OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UnicodeTestSuite.cpp
Go to the documentation of this file.
1 // /////////////////////////////////////////////////////////////////////////
2 //
3 // Unicode-based transformations
4 //
5 // Author: Denis Arnaud
6 // Date: September 2012
7 //
8 // /////////////////////////////////////////////////////////////////////////
9 // STL
10 #include <sstream>
11 #include <fstream>
12 #include <string>
13 #include <list>
14 // Boost Unit Test Framework (UTF)
15 #define BOOST_TEST_DYN_LINK
16 #define BOOST_TEST_MAIN
17 #define BOOST_TEST_MODULE UnicodeTestSuite
18 #include <boost/test/unit_test.hpp>
19 // OpenTrep
21 
22 namespace boost_utf = boost::unit_test;
23 
24 // (Boost) Unit Test XML Report
25 std::ofstream utfReportStream ("UnicodeTestSuite_utfresults.xml");
26 
30 struct UnitTestConfig {
33  boost_utf::unit_test_log.set_stream (utfReportStream);
34  boost_utf::unit_test_log.set_format (boost_utf::XML);
35  boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
36  //boost_utf::unit_test_log.set_threshold_level (boost_utf::log_successful_tests);
37  }
38 
41  }
42 };
43 
44 
45 // /////////////// Main: Unit Test Suite //////////////
46 
47 // Set the UTF configuration (re-direct the output to a specific file)
49 
50 // Start the test suite
51 BOOST_AUTO_TEST_SUITE (master_test_suite)
52 
53 
56 BOOST_AUTO_TEST_CASE (unicode_strings) {
57 
58  // Output log File
59  std::string lLogFilename ("UnicodeTestSuite.log");
60 
61  // Set the log parameters
62  std::ofstream logOutputFile;
63  // Open and clean the log outputfile
64  logOutputFile.open (lLogFilename.c_str());
65  logOutputFile.clear();
66 
67  // Unicode transliterator
68  OPENTREP::OTransliterator lTransliterator;
69 
70  // European
71  const std::string lFRStr = "À côté de Nice Côte d'Azur";
72  const std::string lFRTranslitStr = lTransliterator.normalise (lFRStr);
73  const std::string lFRTargetStr = "a cote de nice cote d azur";
74  const std::string lHUStr = "San Franciscó-i nemzetközi repülőtér";
75  const std::string lHUTranslitStr = lTransliterator.normalise (lHUStr);
76  const std::string lHUTargetStr = "san francisco i nemzetkozi repuloter";
77  const std::string lGRStr = "Αλφαβητικός Κατάλογος";
78  const std::string lGRTranslitStr = lTransliterator.normalise (lGRStr);
79  const std::string lGRTargetStr = "alphabetikos katalogos";
80  const std::string lRUStr = "Аэропорт «Аннаба», Биологическом";
81  const std::string lRUTranslitStr = lTransliterator.normalise (lRUStr);
82  const std::string lRUTargetStr = "aeroport annaba biologiceskom";
83  const std::string lUKStr = "Биологїческом";
84  const std::string lUKTranslitStr = lTransliterator.normalise (lUKStr);
85  const std::string lUKTargetStr = "biologiceskom";
86  const std::string lTRStr = "San Francisco Uluslararası Havalimanı";
87  const std::string lTRTranslitStr = lTransliterator.normalise (lTRStr);
88  const std::string lTRTargetStr = "san francisco uluslararası havalimanı";
89 
90  // Africa - Middle-East
91  const std::string lARStr = "مطار سان فرانسيسكو الدولي";
92  const std::string lARTranslitStr = lTransliterator.normalise (lARStr);
93  const std::string lARTargetStr = "mtar san fransyskw aldwly";
94  const std::string lFAStr = "فرودگاه بین المللی سانفرانسیسکو";
95  const std::string lFATranslitStr = lTransliterator.normalise (lFAStr);
96  const std::string lFATargetStr = "frwdgah byn almlly sanfransyskw";
97 
98  // Asia
99  const std::string lZHStr = "舊金山國際機場";
100  const std::string lZHTranslitStr = lTransliterator.normalise (lZHStr);
101  const std::string lZHTargetStr = "jiu jin shan guo ji ji chang";
102  const std::string lJPStr = "サンフランシスコ国際空港";
103  const std::string lJPTranslitStr = lTransliterator.normalise (lJPStr);
104  const std::string lJPTargetStr = "sanfuranshisuko guo ji kong gang";
105  const std::string lKOStr = "샌프란시스코 국제공항";
106  const std::string lKOTranslitStr = lTransliterator.normalise (lKOStr);
107  const std::string lKOTargetStr = "saenpeulansiseuko gugjegonghang";
108  const std::string lTHStr = "ท่าอากาศยานนานาชาติซานฟรานซิสโก";
109  const std::string lTHTranslitStr = lTransliterator.normalise (lTHStr);
110  const std::string lTHTargetStr = "tha xakasyan nana chat san f ran ss ko";
111  const std::string lVIStr = "Sân bay quốc tế San Francisco";
112  const std::string lVITranslitStr = lTransliterator.normalise (lVIStr);
113  const std::string lVITargetStr = "san bay quoc te san francisco";
114 
115  // French (accentuated Latin)
116  logOutputFile << "[FR] " << lFRStr << " -> " << lFRTranslitStr << std::endl;
117  BOOST_CHECK_MESSAGE (lFRTranslitStr == lFRTargetStr,
118  "The French transliterated string for '" << lFRStr
119  << "' should be '" << lFRTargetStr << "'. "
120  << "However, it is '" << lFRTranslitStr << "'.");
121 
122  // Hungarian (accentuated Latin)
123  logOutputFile << "[HU] " << lHUStr << " -> " << lHUTranslitStr << std::endl;
124  BOOST_CHECK_MESSAGE (lHUTranslitStr == lHUTargetStr,
125  "The Hungarian transliterated string for '" << lHUStr
126  << "' should be '" << lHUTargetStr << "'. "
127  << "However, it is '" << lHUTranslitStr << "'.");
128 
129  // Greek
130  logOutputFile << "[GR] " << lGRStr << " -> " << lGRTranslitStr << std::endl;
131  BOOST_CHECK_MESSAGE (lGRTranslitStr == lGRTargetStr,
132  "The Greek transliterated string for '" << lGRStr
133  << "' should be '" << lGRTargetStr << "'. "
134  << "However, it is '" << lGRTranslitStr << "'.");
135 
136  // Russian (Cyrillic)
137  logOutputFile << "[RU] " << lRUStr << " -> " << lRUTranslitStr << std::endl;
138  BOOST_CHECK_MESSAGE (lRUTranslitStr == lRUTargetStr,
139  "The Russian transliterated string for '" << lRUStr
140  << "' should be '" << lRUTargetStr << "'. "
141  << "However, it is '" << lRUTranslitStr << "'.");
142 
143  // Ukrainian (Cyrillic)
144  logOutputFile << "[UK] " << lUKStr << " -> " << lUKTranslitStr << std::endl;
145  BOOST_CHECK_MESSAGE (lUKTranslitStr == lUKTargetStr,
146  "The Ukrainian transliterated string for '" << lUKStr
147  << "' should be '" << lUKTargetStr << "'. "
148  << "However, it is '" << lUKTranslitStr << "'.");
149 
150  // Turkish
151  logOutputFile << "[TR] " << lTRStr << " -> " << lTRTranslitStr << std::endl;
152  BOOST_CHECK_MESSAGE (lTRTranslitStr == lTRTargetStr,
153  "The Turkish transliterated string for '" << lTRStr
154  << "' should be '" << lTRTargetStr << "'. "
155  << "However, it is '" << lTRTranslitStr << "'.");
156 
157  // Arabic
158  logOutputFile << "[AR] " << lARStr << " -> " << lARTranslitStr << std::endl;
159  BOOST_CHECK_MESSAGE (lARTranslitStr == lARTargetStr,
160  "The Arabic transliterated string for '" << lARStr
161  << "' should be '" << lARTargetStr << "'. "
162  << "However, it is '" << lARTranslitStr << "'.");
163 
164  // Iranian (Farsi)
165  logOutputFile << "[FA] " << lFAStr << " -> " << lFATranslitStr << std::endl;
166  BOOST_CHECK_MESSAGE (lFATranslitStr == lFATargetStr,
167  "The Arabic transliterated string for '" << lFAStr
168  << "' should be '" << lFATargetStr << "'. "
169  << "However, it is '" << lFATranslitStr << "'.");
170 
171  // Chinese (Han)
172  logOutputFile << "[ZH] " << lZHStr << " -> " << lZHTranslitStr << std::endl;
173  BOOST_CHECK_MESSAGE (lZHTranslitStr == lZHTargetStr,
174  "The Chinese transliterated string for '" << lZHStr
175  << "' should be '" << lZHTargetStr << "'. "
176  << "However, it is '" << lZHTranslitStr << "'.");
177 
178  // Japanese (Katakana)
179  logOutputFile << "[JP] " << lJPStr << " -> " << lJPTranslitStr << std::endl;
180  BOOST_CHECK_MESSAGE (lJPTranslitStr == lJPTargetStr,
181  "The Japanese transliterated string for '" << lJPStr
182  << "' should be '" << lJPTargetStr << "'. "
183  << "However, it is '" << lJPTranslitStr << "'.");
184 
185  // Korean (Hangul)
186  logOutputFile << "[KO] " << lKOStr << " -> " << lKOTranslitStr << std::endl;
187  BOOST_CHECK_MESSAGE (lKOTranslitStr == lKOTargetStr,
188  "The Korean transliterated string for '" << lKOStr
189  << "' should be '" << lKOTargetStr << "'. "
190  << "However, it is '" << lKOTranslitStr << "'.");
191 
192  // Thai
193  logOutputFile << "[TH] " << lTHStr << " -> " << lTHTranslitStr << std::endl;
194  BOOST_CHECK_MESSAGE (lTHTranslitStr == lTHTargetStr,
195  "The Korean transliterated string for '" << lTHStr
196  << "' should be '" << lTHTargetStr << "'. "
197  << "However, it is '" << lTHTranslitStr << "'.");
198 
199  // Vietnamese
200  logOutputFile << "[VI] " << lVIStr << " -> " << lVITranslitStr << std::endl;
201  BOOST_CHECK_MESSAGE (lVITranslitStr == lVITargetStr,
202  "The Korean transliterated string for '" << lVIStr
203  << "' should be '" << lVITargetStr << "'. "
204  << "However, it is '" << lVITranslitStr << "'.");
205 
206 
207  // Close the Log outputFile
208  logOutputFile.close();
209 }
210 
211 // End the test suite
212 BOOST_AUTO_TEST_SUITE_END()
213 
std::ofstream utfReportStream("UnicodeTestSuite_utfresults.xml")
BOOST_AUTO_TEST_CASE(unicode_strings)
BOOST_GLOBAL_FIXTURE(UnitTestConfig)
std::string normalise(const std::string &iString) const