summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-11-03 20:52:02 +0100
committerSébastien Helleu <flashcode@flashtux.org>2014-11-03 20:52:02 +0100
commit0d1abd38999e1b2ef7355667fb72c58e830d1fc7 (patch)
treefc605761cde0f480cb73e637500f3504a0c5fb65 /tests/unit
parente85ae88b255ec032ceb91d8e026e4f736c468726 (diff)
downloadweechat-0d1abd38999e1b2ef7355667fb72c58e830d1fc7.zip
tests: add tests of functions string_shared_get and string_shared_free
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/core/test-string.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/unit/core/test-string.cpp b/tests/unit/core/test-string.cpp
index e80698f56..a22599b29 100644
--- a/tests/unit/core/test-string.cpp
+++ b/tests/unit/core/test-string.cpp
@@ -28,6 +28,7 @@ extern "C"
#include <regex.h>
#include "tests/tests.h"
#include "src/core/wee-string.h"
+#include "src/core/wee-hashtable.h"
}
#define ONE_KB 1000ULL
@@ -94,6 +95,8 @@ extern "C"
STRCMP_EQUAL(__result, str); \
free (str);
+extern struct t_hashtable *string_hashtable_shared;
+
TEST_GROUP(String)
{
};
@@ -1081,5 +1084,35 @@ TEST(String, Input)
TEST(String, Shared)
{
- /* TODO: write tests */
+ const char *str1, *str2, *str3;
+ int count;
+
+ count = string_hashtable_shared->items_count;
+
+ str1 = string_shared_get ("this is a test");
+ CHECK(str1);
+
+ LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);
+
+ str2 = string_shared_get ("this is a test");
+ CHECK(str2);
+ POINTERS_EQUAL(str1, str2);
+
+ LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);
+
+ str3 = string_shared_get ("this is another test");
+ CHECK(str3);
+ CHECK(str1 != str3);
+ CHECK(str2 != str3);
+
+ LONGS_EQUAL(count + 2, string_hashtable_shared->items_count);
+
+ string_shared_free (str1);
+ LONGS_EQUAL(count + 2, string_hashtable_shared->items_count);
+
+ string_shared_free (str2);
+ LONGS_EQUAL(count + 1, string_hashtable_shared->items_count);
+
+ string_shared_free (str3);
+ LONGS_EQUAL(count + 0, string_hashtable_shared->items_count);
}