Enlightenment CVS committal

Author  : pfritz
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/bin/tests/text


Modified Files:
        ewl_text.c 


Log Message:
add UTF-8 unit tests

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/bin/tests/text/ewl_text.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- ewl_text.c  5 Dec 2006 14:49:46 -0000       1.5
+++ ewl_text.c  17 Dec 2006 17:06:20 -0000      1.6
@@ -83,9 +83,13 @@
 static void trigger_cb(Ewl_Widget *w, void *ev, void *data);
 
 static int text_test_set_get(char *buf, int len);
+static int text_valid_utf8_set_get(char *buf, int len);
+static int text_invalid_utf8_set_get(char *buf, int len);
 
 static Ewl_Unit_Test text_unit_tests[] = {
                {"text set/get", text_test_set_get},    
+               {"valid UTF-8 text set/get", text_valid_utf8_set_get},  
+               {"invalid UTF-8 text set/get", text_invalid_utf8_set_get},      
                {NULL, NULL}
        };
 
@@ -293,4 +297,99 @@
 
        return ret;
 }
- 
+
+static int
+text_valid_utf8_set_get(char *buf, int len)
+{
+       Ewl_Widget *t;
+       char text[] = "This a valid UTF-8 string, although it contains "
+                       "at the moment only 7-bit ascii code.\n"
+                       " This will be changed later!";
+       const char * returned_text;
+       unsigned char *utext;
+
+       utext = (unsigned char *)text;
+
+       t = ewl_text_new();
+       ewl_widget_show(t);
+
+       /*
+        * append the US-ASCII string
+        */
+       ewl_text_text_set(EWL_TEXT(t), text);
+       returned_text = ewl_text_text_get(EWL_TEXT(t));
+
+       if (strcmp(text, returned_text)) {
+               snprintf(buf, len, "Incorrect UTF-8 validation during"
+                               "setting a US-ASCII string");
+               return FALSE;
+       }
+
+       ewl_text_clear(EWL_TEXT(t));
+
+       /* insert the umlaut a with two dots */
+       utext[2] = 0xC3;
+       utext[3] = 0xA4;
+       /* insert the euro sign */
+       utext[10] = 0xE2;
+       utext[11] = 0x82;
+       utext[12] = 0xAC;
+       /*
+        * set a valid UTF-8 string
+        */
+       ewl_text_text_set(EWL_TEXT(t), text);
+       returned_text = ewl_text_text_get(EWL_TEXT(t));
+
+       if (strcmp(text, returned_text)) {
+               snprintf(buf, len, "Incorrect UTF-8 validation during"
+                               "setting a valid UTF-8 string");
+               return FALSE;
+       }
+       return TRUE;
+}
+
+
+static int
+text_invalid_utf8_set_get(char *buf, int len)
+{
+       Ewl_Widget *t;
+       char text[] = "This a valid UTF-8 string, although it contains "
+                       "at the moment only 7-bit ascii code.\n"
+                       " This will be changed later!";
+       const char * returned_text;
+       unsigned char *utext;
+
+       utext = (unsigned char *)text;
+
+       t = ewl_text_new();
+       ewl_widget_show(t);
+
+       /* insert some invalid bytes */
+       utext[2] = 254;
+       utext[4] = 0xA4;
+       /* insert the euro sign without the 3rd byte */
+       utext[10] = 0xE2;
+       utext[11] = 0x82;
+       /*
+        * set a valid UTF-8 string
+        */
+       ewl_text_text_set(EWL_TEXT(t), text);
+       returned_text = ewl_text_text_get(EWL_TEXT(t));
+
+       if (!returned_text) {
+               snprintf(buf, len, "ewl_text_text_get() returned a "
+                               "NULL-pointer");
+       }
+       else if (!strcmp(text, returned_text) 
+               || returned_text[2] < 0
+               || returned_text[4] < 0
+               || returned_text[10] < 0
+               || returned_text[11] < 0) 
+       {
+               snprintf(buf, len, "Incorrect UTF-8 validation during"
+                               "setting a invalid UTF-8 string");
+               return FALSE;
+       }
+       return TRUE;
+} 
+



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to