]> git.mxchange.org Git - simgear.git/blob - simgear/misc/utf8tolatin1_test.cxx
utf8ToLatin1: add test
[simgear.git] / simgear / misc / utf8tolatin1_test.cxx
1 #include "strutils.hxx"
2 #include <iostream>
3 #include <string>
4
5 int main()
6 {
7     std::string utf8_string1 = "Zweibr\u00FCcken";
8     //valid UTF-8, convertible to Latin-1
9     std::string latin1_string1 = "Zweibr\374cken";
10     //Latin-1, not valid UTF-8
11     std::string utf8_string2 = "\u600f\U00010143";
12     //valid UTF-8, out of range for Latin-1
13     
14     std::string output_string1u = simgear::strutils::utf8ToLatin1(utf8_string1);
15     if (output_string1u.compare(latin1_string1)){
16         std::cerr << "Conversion fail: "
17         << output_string1u << "!=" << latin1_string1;
18         return 1;
19     }
20     std::string output_string1l = simgear::strutils::utf8ToLatin1(latin1_string1);
21     if (output_string1l.compare(latin1_string1)){
22         std::cerr << "Non-conversion fail: "
23         << output_string1l << "!=" << latin1_string1;
24         return 1;
25     }
26     std::string output_string3 = simgear::strutils::utf8ToLatin1(utf8_string2);
27     //we don't check the result of this one as there is no right answer,
28     //just make sure it doesn't crash/hang
29     return 0;
30 }