1 #include "ValuesFile.h" 2 #include <stdio.h> 3 4 int 5 ValuesFile_test() 6 { 7 int err = 0; 8 Configuration config; 9 config.locale = "zz_ZZ"; 10 ValuesFile* vf = ValuesFile::ParseFile("testdata/values/strings.xml", config, 11 OLD_VERSION, "1"); 12 13 const set<StringResource>& strings = vf->GetStrings(); 14 string canonical = vf->ToString(); 15 16 if (false) { 17 printf("Strings (%zd)\n", strings.size()); 18 for (set<StringResource>::const_iterator it=strings.begin(); 19 it!=strings.end(); it++) { 20 const StringResource& str = *it; 21 printf("%s: '%s'[%d]='%s' (%s) <!-- %s -->\n", str.pos.ToString().c_str(), 22 str.id.c_str(), str.index, 23 str.value->ContentsToString(ANDROID_NAMESPACES).c_str(), 24 str.config.ToString().c_str(), str.comment.c_str()); 25 } 26 27 printf("XML:[[%s]]\n", canonical.c_str()); 28 } 29 30 const char * const EXPECTED = 31 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 32 "<resources xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" 33 " xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n" 34 " <array name=\"emailAddressTypes\">\n" 35 " <item>Email</item>\n" 36 " <item>Home</item>\n" 37 " <item>Work</item>\n" 38 " <item>Other\\u2026</item>\n" 39 " </array>\n" 40 " <string name=\"test1\">Discard</string>\n" 41 " <string name=\"test2\">a<b>b<i>c</i></b>d</string>\n" 42 " <string name=\"test3\">a<xliff:g a=\"b\" xliff:a=\"asdf\">bBb</xliff:g>C</string>\n" 43 "</resources>\n"; 44 45 if (canonical != EXPECTED) { 46 fprintf(stderr, "ValuesFile_test failed\n"); 47 fprintf(stderr, "canonical=[[%s]]\n", canonical.c_str()); 48 fprintf(stderr, "EXPECTED=[[%s]]\n", EXPECTED); 49 err = 1; 50 } 51 52 delete vf; 53 return err; 54 } 55