eina: add test case for eina_memdup in eina str
authorvivek <vivek.ellur@samsung.com>
Wed, 25 Feb 2015 16:26:03 +0000 (17:26 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 25 Feb 2015 16:46:16 +0000 (17:46 +0100)
Summary:
Added test case for eina_memdup function in eina_str test module

Signed-off-by: vivek <vivek.ellur@samsung.com>
Reviewers: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2026

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/tests/eina/eina_test_str.c

index 4045ce8..d99e5c0 100644 (file)
@@ -309,6 +309,36 @@ START_TEST(str_join_len)
 }
 END_TEST
 
+START_TEST(str_memdup)
+{
+   struct temp {
+      int i;
+      char *s;
+      double d;
+   } t1,*t2;
+   unsigned char buf[7], *temp_buf;
+
+   eina_init();
+
+   t1.i = 1234;
+   t1.s = "hello";
+   t1.d = 123.456;
+
+   t2 = (struct temp *)eina_memdup((unsigned char *)&t1, sizeof(struct temp), EINA_TRUE);
+   fail_if(t2->i != t1.i);
+   fail_if(strcmp(t2->s,t1.s) != 0);
+   fail_if(t2->d != t1.d);
+   free(t2);
+
+   memcpy(buf, "aaabbb", 6);
+   temp_buf = eina_memdup(buf, 6, EINA_TRUE);
+   fail_if(strcmp(temp_buf, "aaabbb") != 0);
+   free(temp_buf);
+
+   eina_shutdown();
+}
+END_TEST
+
 #ifdef HAVE_ICONV
 START_TEST(str_convert)
 {
@@ -346,6 +376,7 @@ eina_test_str(TCase *tc)
    tcase_add_test(tc, str_split);
    tcase_add_test(tc, str_lcat_lcpy);
    tcase_add_test(tc, str_join_len);
+   tcase_add_test(tc, str_memdup);
 #ifdef HAVE_ICONV
    tcase_add_test(tc, str_convert);
 #endif