iSulad/0030-add-more-test-for-string-and-map.patch
zhangxiaoyu 97df963d71 add ut and bugfix for device mapper and websocket
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
2022-11-01 20:06:15 +08:00

123 lines
3.6 KiB
Diff

From 5e4fc62e36631d8d2e444ac3d60ce99ec7396ca0 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Fri, 21 Oct 2022 09:58:40 +0800
Subject: [PATCH 30/39] add more test for string and map
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
test/cutils/map/map_ut.cc | 50 ++++++++++++++++++++-
test/cutils/utils_string/utils_string_ut.cc | 17 ++++---
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/test/cutils/map/map_ut.cc b/test/cutils/map/map_ut.cc
index fd75da28..7e4c97e4 100644
--- a/test/cutils/map/map_ut.cc
+++ b/test/cutils/map/map_ut.cc
@@ -18,7 +18,12 @@
#include <gtest/gtest.h>
#include "map.h"
-TEST(map_map_ut, test_map)
+static void ptr_ptr_map_kefree(void *key, void *value)
+{
+ return;
+}
+
+TEST(map_map_ut, test_map_string)
{
// map[string][bool]
map_t *map_test = nullptr;
@@ -37,3 +42,46 @@ TEST(map_map_ut, test_map)
map_itor_free(itor);
map_clear(map_test);
}
+
+TEST(map_map_ut, test_map_int)
+{
+ int key = 3;
+ int value = 5;
+ int *value_ptr = nullptr;
+ // map[int][int]
+ map_t *map_test = nullptr;
+
+ map_test = map_new(MAP_INT_INT, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
+ ASSERT_NE(map_test, nullptr);
+ ASSERT_EQ(map_insert(map_test, &key, &value), true);
+
+ key = 22;
+ value = 33;
+ ASSERT_EQ(map_insert(map_test, &key, &value), true);
+
+ value_ptr = (int *)map_search(map_test, &key);
+ ASSERT_EQ(*value_ptr, 33);
+
+ key = 44;
+ ASSERT_EQ(map_search(map_test, &key), nullptr);
+
+ map_clear(map_test);
+}
+
+TEST(map_map_ut, test_map_ptr)
+{
+ int *key_ptr = new int(3);
+ int *value_ptr = new int(5);
+ // map[ptr][ptr]
+ map_t *map_test = nullptr;
+
+ map_test = map_new(MAP_PTR_PTR, MAP_DEFAULT_CMP_FUNC, ptr_ptr_map_kefree);
+ ASSERT_NE(map_test, nullptr);
+ ASSERT_EQ(map_insert(map_test, key_ptr, value_ptr), true);
+ ASSERT_EQ(map_search(map_test, key_ptr), value_ptr);
+ ASSERT_EQ(map_search(map_test, nullptr), nullptr);
+
+ map_clear(map_test);
+ delete key_ptr;
+ delete value_ptr;
+}
diff --git a/test/cutils/utils_string/utils_string_ut.cc b/test/cutils/utils_string/utils_string_ut.cc
index 8b6c61a6..0f8f0011 100644
--- a/test/cutils/utils_string/utils_string_ut.cc
+++ b/test/cutils/utils_string/utils_string_ut.cc
@@ -833,26 +833,33 @@ TEST(utils_string_ut, test_str_token)
free(token);
}
-TEST(utils_string_ut, test_string_split_multi)
+TEST(utils_string_ut, test_string_split_n)
{
char **result = nullptr;
- ASSERT_EQ(util_string_split_multi(nullptr, ':'), nullptr);
+ ASSERT_EQ(util_string_split_n(nullptr, ':', 3), nullptr);
+ ASSERT_EQ(util_string_split_n("aa:bb", ':', 0), nullptr);
- result = util_string_split_multi("", ':');
+ result = util_string_split_n("", ':', 3);
ASSERT_STREQ(result[0], "");
ASSERT_EQ(result[1], nullptr);
util_free_array(result);
- result = util_string_split_multi("abcd;", ':');
+ result = util_string_split_n("abcd;", ':', 3);
ASSERT_STREQ(result[0], "abcd;");
ASSERT_EQ(result[1], nullptr);
util_free_array(result);
- result = util_string_split_multi("abc:dd:e", ':');
+ result = util_string_split_n("abc:dd:e", ':', 3);
ASSERT_STREQ(result[0], "abc");
ASSERT_STREQ(result[1], "dd");
ASSERT_STREQ(result[2], "e");
ASSERT_EQ(result[3], nullptr);
util_free_array(result);
+
+ result = util_string_split_n("abc:dd:e", ':', 2);
+ ASSERT_STREQ(result[0], "abc");
+ ASSERT_STREQ(result[1], "dd:e");
+ ASSERT_EQ(result[2], nullptr);
+ util_free_array(result);
}
--
2.25.1