Add ustr tests.
authornash <nash@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 2 Aug 2010 09:43:51 +0000 (09:43 +0000)
committernash <nash@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 2 Aug 2010 09:43:51 +0000 (09:43 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@50737 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/tests/Makefile.am
src/tests/eina_suite.c
src/tests/eina_suite.h
src/tests/eina_test_ustr.c [new file with mode: 0644]

index 7df949b..a414348 100644 (file)
@@ -35,7 +35,8 @@ eina_suite.c          \
 eina_test_fp.c         \
 eina_test_stringshare.c \
 eina_test_ustringshare.c\
-eina_test_binshare.c\
+eina_test_ustr.c       \
+eina_test_binshare.c    \
 eina_test_array.c      \
 eina_test_error.c      \
 eina_test_log.c        \
index bb2b437..78a014f 100644 (file)
@@ -60,6 +60,7 @@ static const Eina_Test_Case etc[] = {
    { "Eina Tiler", eina_test_tiler },
    { "Eina Strbuf", eina_test_strbuf },
    { "String", eina_test_str },
+   { "Unicode String", eina_test_ustr },
    { "QuadTree", eina_test_quadtree },
    { NULL, NULL }
 };
index 292471e..b63cb60 100644 (file)
@@ -47,6 +47,7 @@ void eina_test_matrixsparse(TCase *tc);
 void eina_test_tiler(TCase *tc);
 void eina_test_strbuf(TCase *tc);
 void eina_test_str(TCase *tc);
+void eina_test_ustr(TCase *tc);
 void eina_test_quadtree(TCase *tc);
 void eina_test_fp(TCase *tc);
 
diff --git a/src/tests/eina_test_ustr.c b/src/tests/eina_test_ustr.c
new file mode 100644 (file)
index 0000000..d069a96
--- /dev/null
@@ -0,0 +1,230 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2010 Brett Nash
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "eina_suite.h"
+#include "Eina.h"
+
+static const Eina_Unicode STR1[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0};
+static const Eina_Unicode STR2[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'f', 'f', 0};
+static const Eina_Unicode STR3[] = {'P', 'a', 'n', 't', 's',' ', 'O', 'n', 0};
+static const Eina_Unicode STR4[] = {'A', 0};
+static const Eina_Unicode EMPTYSTR[] = {0};
+
+START_TEST(eina_unicode_strcmp_test)
+{
+   eina_init();
+
+   /* 1 & 2 */
+   fail_if(eina_unicode_strcmp(STR1,STR2) == 0);
+   fail_if(eina_unicode_strcmp(STR1,STR2) < 1);
+
+   /* 1 & 3 */
+   fail_if(eina_unicode_strcmp(STR1, STR3) != 0);
+
+   /* 1 & 4 */
+   fail_if(eina_unicode_strcmp(STR1, STR4) == 0);
+   fail_if(eina_unicode_strcmp(STR1, STR4) > 1);
+
+   /* 1 & empty */
+   fail_if(eina_unicode_strcmp(STR1, EMPTYSTR) < 1);
+
+   /* Self tests */
+   fail_if(eina_unicode_strcmp(STR1, STR1) != 0);
+   fail_if(eina_unicode_strcmp(STR2, STR2) != 0);
+   fail_if(eina_unicode_strcmp(STR3, STR3) != 0);
+   fail_if(eina_unicode_strcmp(STR4, STR4) != 0);
+   fail_if(eina_unicode_strcmp(EMPTYSTR, EMPTYSTR) != 0);
+
+   eina_shutdown();
+}
+END_TEST
+
+START_TEST(eina_unicode_strcpy_test)
+{
+   Eina_Unicode buf[10] = { 0 };
+   Eina_Unicode *rv;
+
+   eina_init();
+
+   rv = eina_unicode_strcpy(buf,STR1);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR1) != 0);
+
+   rv = eina_unicode_strcpy(buf,STR2);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR2) != 0);
+
+   /* Now a shorter string */
+   rv = eina_unicode_strcpy(buf,STR2);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR2) != 0);
+
+   /* Really short string */
+   rv = eina_unicode_strcpy(buf,STR4);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR4) != 0);
+   fail_if(buf[2] != 'n'); /* check old buf is there */
+
+   buf[1] = '7';
+   rv = eina_unicode_strcpy(buf,EMPTYSTR);
+   fail_if(rv != buf);
+   fail_if(buf[0] != 0);
+   fail_if(buf[1] != '7');
+
+   eina_shutdown();
+}
+END_TEST
+
+START_TEST(eina_unicode_strncpy_test)
+{
+   Eina_Unicode buf[10] = { 0 };
+   Eina_Unicode *rv;
+
+   eina_init();
+
+   rv = eina_unicode_strncpy(buf,STR1,9);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR1) != 0);
+
+   buf[1] = '7';
+   rv = eina_unicode_strncpy(buf,STR1,1);
+   fail_if(rv != buf);
+   fail_if(buf[1] != '7');
+   fail_if(buf[0] != STR1[1]);
+
+   buf[9] = '7';
+   rv = eina_unicode_strncpy(buf, STR1, 10);
+   fail_if(rv != buf);
+   fail_if(eina_unicode_strcmp(buf,STR1) != 0);
+   fail_if(buf[9] != 0);
+
+   eina_shutdown();
+}
+END_TEST
+
+
+
+START_TEST(eina_ustr_strlen_test)
+{
+
+   eina_init();
+
+   fail_if(eina_unicode_strlen(STR1) != 8);
+   fail_if(eina_unicode_strlen(STR2) != 9);
+   fail_if(eina_unicode_strlen(STR3) != 8);
+   fail_if(eina_unicode_strlen(STR4) != 1);
+   fail_if(eina_unicode_strlen(EMPTYSTR) != 0);
+   /* Eina unicode doesn't take NULL */
+   // fail_if(eina_unicode_strlen(NULL));
+
+   eina_shutdown();
+}
+END_TEST
+
+START_TEST(eina_unicode_strnlen_test)
+{
+   eina_init();
+
+   /* Strlen style tests*/
+   fail_if(eina_unicode_strnlen(STR1,10) != 8);
+   fail_if(eina_unicode_strnlen(STR2,10) != 9);
+   fail_if(eina_unicode_strnlen(STR3,10) != 8);
+   fail_if(eina_unicode_strnlen(STR4,10) != 1);
+   fail_if(eina_unicode_strnlen(EMPTYSTR,10) != 0);
+
+   /* Too short tests */
+   fail_if(eina_unicode_strnlen(STR1,3) != 3);
+   fail_if(eina_unicode_strnlen(STR2,3) != 3);
+   fail_if(eina_unicode_strnlen(STR3,3) != 3);
+   fail_if(eina_unicode_strnlen(EMPTYSTR,1) != 0);
+   fail_if(eina_unicode_strnlen(NULL,0) != 0);
+
+   eina_shutdown();
+}
+END_TEST
+
+START_TEST(eina_unicode_strdup_test)
+{
+   Eina_Unicode *buf;
+
+   eina_init();
+
+   buf = eina_unicode_strdup(STR1);
+   fail_if(!buf);
+   fail_if(eina_unicode_strlen(buf) != eina_unicode_strlen(STR1));
+   fail_if(eina_unicode_strcmp(buf, STR1));
+   free(buf);
+
+   buf = eina_unicode_strdup(EMPTYSTR);
+   fail_if(!buf);
+   fail_if(buf[0] != 0);
+
+   eina_shutdown();
+}
+END_TEST
+
+START_TEST(eina_unicode_strstr_test)
+{
+   Eina_Unicode *buf;
+   Eina_Unicode on[] = { 'O', 'n', 0 };
+
+   eina_init();
+
+   buf = eina_unicode_strstr(STR1,on);
+   fail_if(!buf);
+   fail_if(buf != STR1 + 6);
+   fail_if(eina_unicode_strcmp(buf,on) != 0);
+
+   buf = eina_unicode_strstr(STR2,on);
+   fail_if(buf);
+
+   buf = eina_unicode_strstr(EMPTYSTR, on);
+   fail_if(buf);
+
+   buf = eina_unicode_strstr(STR1, EMPTYSTR);
+   fail_if(!buf);
+   fail_if(buf != STR1);
+
+   eina_shutdown();
+}
+END_TEST
+
+void
+eina_test_ustr(TCase *tc)
+{
+   printf("ustr test\n");
+   tcase_add_test(tc,eina_unicode_strcmp_test);
+   tcase_add_test(tc,eina_unicode_strcpy_test);
+   tcase_add_test(tc,eina_unicode_strncpy_test);
+   tcase_add_test(tc,eina_ustr_strlen_test);
+   tcase_add_test(tc,eina_unicode_strnlen_test);
+   tcase_add_test(tc,eina_unicode_strdup_test);
+   tcase_add_test(tc,eina_unicode_strstr_test);
+
+}
+
+/* vim: set sts=3 sw=3: */