// ********************************************************************** // // Copyright (c) 2001 // ZeroC, Inc. // Huntsville, AL, USA // // All Rights Reserved // // ********************************************************************** #include #include #include using namespace IceUtil; using namespace std; int main(int, char**) { cout << "testing string/wstring conversion... "; string arabic = "لماذا لا يتكلمون اللّغة العربية فحسب؟"; wstring warabic = stringToWstring(arabic); test(warabic.length() == 37); string arabic2 = wstringToString(warabic); test(arabic2.length() == arabic.length()); test(arabic2 == arabic); string japanese = "なぜ、みんな日本語を話してくれないのか?"; wstring wjapanese = stringToWstring(japanese); test(wjapanese.length() == 20); string japanese2 = wstringToString(wjapanese); test(japanese2.length() == japanese.length()); test(japanese2 == japanese); cout << "ok" << endl; cout << "ditto, but with random unicode text... "; ifstream numeric("numeric.txt"); test(numeric.good()); wstring wrandom; while(numeric) { int c; numeric >> c; if(numeric) { wrandom += static_cast(c); } } numeric.close(); ifstream utf8("utf8.txt"); test(utf8.good()); string random; while(utf8) { char c; utf8.get(c); if(utf8) { random += c; } } utf8.close(); string random2 = wstringToString(wrandom); wstring wrandom2 = stringToWstring(random); /* unsigned int i; ofstream numeric2("numeric2.txt"); for(i = 0; i < wrandom2.length(); ++i) { numeric2 << static_cast(wrandom2[i]) << '\n'; } numeric2.close(); ofstream utf82("utf82.txt"); for(i = 0; i < random2.length(); ++i) { utf82.put(random2[i]); } utf82.close(); */ test (random2.length() == random.length()); test (wrandom2.length() == wrandom.length()); test (random2 == random); test (wrandom2 == wrandom); cout << "ok" << endl; return EXIT_SUCCESS; }