Revision: 860 Author: bertfrees@xxxxxxxxx Date: Thu Dec 13 08:38:59 2012 Log: Add helper function to convert typeform strings http://code.google.com/p/liblouis/source/detail?r=860 Modified: /trunk/tests/brl_checks.c /trunk/tests/en_gb_g1_italics.c ======================================= --- /trunk/tests/brl_checks.c Thu Dec 13 05:00:37 2012 +++ /trunk/tests/brl_checks.c Thu Dec 13 08:38:59 2012 @@ -23,6 +23,20 @@ for (i = 0; i < len; i++) printf("%c", buf[i]); } + +/* Helper function to convert a typeform string of '0's, '1's, '2's etc. + to the required format, which is an array of 0s, 1s, 2s, etc. + For example, "0000011111000" is converted to {0,0,0,0,0,1,1,1,1,1,0,0,0} + The caller is responsible for freeing the returned array. */ +char * +convert_typeform(char* typeform_string) +{ + int len = strlen(typeform_string); + char *typeform = malloc(len * sizeof(char)); + for (int i=0; i<len; i++) + typeform[i] = typeform_string[i] - '0'; + return typeform; +} /* Check if a string is translated as expected. Return 0 if the translation is as expected and 1 otherwise. */ ======================================= --- /trunk/tests/en_gb_g1_italics.c Thu Dec 13 05:32:50 2012 +++ /trunk/tests/en_gb_g1_italics.c Thu Dec 13 08:38:59 2012 @@ -16,19 +16,19 @@ const char *typeform = "00000000000000"; const char *expected = ",this is a ,test"; - result |= check_translation(TRANSLATION_TABLE, str, typeform, expected);+ result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);
str = "This is a Test in Italic."; typeform = "1111111111111111111111111"; expected = "..,this is a ,test in ,italic4.'"; - result |= check_translation(TRANSLATION_TABLE, str, typeform, expected);+ result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);
str = "This is a Test"; typeform = "00000111100000"; expected = ",this .is .a ,test"; - result |= check_translation(TRANSLATION_TABLE, str, typeform, expected);+ result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);
return result; } For a description of the software, to download it and links to project pages go to http://www.abilitiessoft.com