Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3217:cf8cbeb35f33
preliminary support of Korean character set
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 13 Feb 2019 17:46:12 +0100 |
parents | 683d572424b6 |
children | 4351f52f15d5 |
comparison
equal
deleted
inserted
replaced
3216:c9a71eb4edcf | 3217:cf8cbeb35f33 |
---|---|
215 { | 215 { |
216 for (unsigned int i = 0; i < testEncodingsCount; i++) | 216 for (unsigned int i = 0; i < testEncodingsCount; i++) |
217 { | 217 { |
218 std::string source(testEncodingsEncoded[i]); | 218 std::string source(testEncodingsEncoded[i]); |
219 std::string expected(testEncodingsExpected[i]); | 219 std::string expected(testEncodingsExpected[i]); |
220 std::string s = Toolbox::ConvertToUtf8(source, testEncodings[i]); | 220 std::string s = Toolbox::ConvertToUtf8(source, testEncodings[i], false); |
221 //std::cout << EnumerationToString(testEncodings[i]) << std::endl; | 221 //std::cout << EnumerationToString(testEncodings[i]) << std::endl; |
222 EXPECT_EQ(expected, s); | 222 EXPECT_EQ(expected, s); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
260 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 166")); ASSERT_EQ(Encoding_Thai, e); | 260 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 166")); ASSERT_EQ(Encoding_Thai, e); |
261 | 261 |
262 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-4 | 262 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-4 |
263 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 87")); //ASSERT_EQ(Encoding_JapaneseKanji, e); | 263 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 87")); //ASSERT_EQ(Encoding_JapaneseKanji, e); |
264 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 159")); //ASSERT_EQ(Encoding_JapaneseKanjiSupplementary, e); | 264 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 159")); //ASSERT_EQ(Encoding_JapaneseKanjiSupplementary, e); |
265 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 149")); //ASSERT_EQ(Encoding_Korean, e); | 265 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 149")); ASSERT_EQ(Encoding_Korean, e); |
266 | 266 |
267 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-5 | 267 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-5 |
268 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e); | 268 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e); |
269 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e); | 269 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e); |
270 ASSERT_TRUE(GetDicomEncoding(e, "GBK")); ASSERT_EQ(Encoding_Chinese, e); | 270 ASSERT_TRUE(GetDicomEncoding(e, "GBK")); ASSERT_EQ(Encoding_Chinese, e); |
280 | 280 |
281 { | 281 { |
282 ParsedDicomFile f(true); | 282 ParsedDicomFile f(true); |
283 f.SetEncoding(testEncodings[i]); | 283 f.SetEncoding(testEncodings[i]); |
284 | 284 |
285 std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i]); | 285 std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); |
286 f.Insert(DICOM_TAG_PATIENT_NAME, s, false); | 286 f.Insert(DICOM_TAG_PATIENT_NAME, s, false); |
287 f.SaveToMemoryBuffer(dicom); | 287 f.SaveToMemoryBuffer(dicom); |
288 } | 288 } |
289 | 289 |
290 if (testEncodings[i] != Encoding_Windows1251) | 290 if (testEncodings[i] != Encoding_Windows1251) |
291 { | 291 { |
292 ParsedDicomFile g(dicom); | 292 ParsedDicomFile g(dicom); |
293 | 293 |
294 if (testEncodings[i] != Encoding_Ascii) | 294 if (testEncodings[i] != Encoding_Ascii) |
295 { | 295 { |
296 ASSERT_EQ(testEncodings[i], g.GetEncoding()); | 296 bool hasCodeExtensions; |
297 ASSERT_EQ(testEncodings[i], g.DetectEncoding(hasCodeExtensions)); | |
298 ASSERT_FALSE(hasCodeExtensions); | |
297 } | 299 } |
298 | 300 |
299 std::string tag; | 301 std::string tag; |
300 ASSERT_TRUE(g.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); | 302 ASSERT_TRUE(g.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); |
301 ASSERT_EQ(std::string(testEncodingsExpected[i]), tag); | 303 ASSERT_EQ(std::string(testEncodingsExpected[i]), tag); |
403 Json::Value b; | 405 Json::Value b; |
404 std::set<DicomTag> ignoreTagLength; | 406 std::set<DicomTag> ignoreTagLength; |
405 ignoreTagLength.insert(DICOM_TAG_PATIENT_ID); | 407 ignoreTagLength.insert(DICOM_TAG_PATIENT_ID); |
406 | 408 |
407 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 409 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
408 DicomToJsonFlags_Default, 0, Encoding_Ascii, ignoreTagLength); | 410 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); |
409 ASSERT_TRUE(b.isMember("0010,0010")); | 411 ASSERT_TRUE(b.isMember("0010,0010")); |
410 ASSERT_EQ("Hello", b["0010,0010"].asString()); | 412 ASSERT_EQ("Hello", b["0010,0010"].asString()); |
411 | 413 |
412 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 414 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
413 DicomToJsonFlags_Default, 3, Encoding_Ascii, ignoreTagLength); | 415 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength); |
414 ASSERT_TRUE(b["0010,0010"].isNull()); // "Hello" has more than 3 characters | 416 ASSERT_TRUE(b["0010,0010"].isNull()); // "Hello" has more than 3 characters |
415 | 417 |
416 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full, | 418 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full, |
417 DicomToJsonFlags_Default, 3, Encoding_Ascii, ignoreTagLength); | 419 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength); |
418 ASSERT_TRUE(b["0010,0010"].isObject()); | 420 ASSERT_TRUE(b["0010,0010"].isObject()); |
419 ASSERT_EQ("PatientName", b["0010,0010"]["Name"].asString()); | 421 ASSERT_EQ("PatientName", b["0010,0010"]["Name"].asString()); |
420 ASSERT_EQ("TooLong", b["0010,0010"]["Type"].asString()); | 422 ASSERT_EQ("TooLong", b["0010,0010"]["Type"].asString()); |
421 ASSERT_TRUE(b["0010,0010"]["Value"].isNull()); | 423 ASSERT_TRUE(b["0010,0010"]["Value"].isNull()); |
422 | 424 |
423 ignoreTagLength.insert(DICOM_TAG_PATIENT_NAME); | 425 ignoreTagLength.insert(DICOM_TAG_PATIENT_NAME); |
424 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 426 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
425 DicomToJsonFlags_Default, 3, Encoding_Ascii, ignoreTagLength); | 427 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength); |
426 ASSERT_EQ("Hello", b["0010,0010"].asString()); | 428 ASSERT_EQ("Hello", b["0010,0010"].asString()); |
427 } | 429 } |
428 | 430 |
429 { | 431 { |
430 Json::Value a; | 432 Json::Value a; |
446 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8)); | 448 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8)); |
447 | 449 |
448 Json::Value b; | 450 Json::Value b; |
449 std::set<DicomTag> ignoreTagLength; | 451 std::set<DicomTag> ignoreTagLength; |
450 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 452 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
451 DicomToJsonFlags_Default, 0, Encoding_Ascii, ignoreTagLength); | 453 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); |
452 ASSERT_EQ("Hello", b["0010,0010"].asString()); | 454 ASSERT_EQ("Hello", b["0010,0010"].asString()); |
453 } | 455 } |
454 | 456 |
455 { | 457 { |
456 Json::Value a = Json::arrayValue; | 458 Json::Value a = Json::arrayValue; |
459 | 461 |
460 { | 462 { |
461 Json::Value b; | 463 Json::Value b; |
462 std::set<DicomTag> ignoreTagLength; | 464 std::set<DicomTag> ignoreTagLength; |
463 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 465 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
464 DicomToJsonFlags_Default, 0, Encoding_Ascii, ignoreTagLength); | 466 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); |
465 ASSERT_EQ(Json::arrayValue, b["0008,1110"].type()); | 467 ASSERT_EQ(Json::arrayValue, b["0008,1110"].type()); |
466 ASSERT_EQ(2u, b["0008,1110"].size()); | 468 ASSERT_EQ(2u, b["0008,1110"].size()); |
467 | 469 |
468 Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1; | 470 Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1; |
469 | 471 |
478 | 480 |
479 { | 481 { |
480 Json::Value b; | 482 Json::Value b; |
481 std::set<DicomTag> ignoreTagLength; | 483 std::set<DicomTag> ignoreTagLength; |
482 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full, | 484 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full, |
483 DicomToJsonFlags_Default, 0, Encoding_Ascii, ignoreTagLength); | 485 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); |
484 | 486 |
485 Json::Value c; | 487 Json::Value c; |
486 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human); | 488 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human); |
487 | 489 |
488 a[1]["PatientName"] = "Hello2"; // To remove the Data URI Scheme encoding | 490 a[1]["PatientName"] = "Hello2"; // To remove the Data URI Scheme encoding |
597 //std::cout << EnumerationToString(testEncodings[i]) << std::endl; | 599 //std::cout << EnumerationToString(testEncodings[i]) << std::endl; |
598 f.SetEncoding(testEncodings[i]); | 600 f.SetEncoding(testEncodings[i]); |
599 | 601 |
600 if (testEncodings[i] != Encoding_Ascii) | 602 if (testEncodings[i] != Encoding_Ascii) |
601 { | 603 { |
602 ASSERT_EQ(testEncodings[i], f.GetEncoding()); | 604 bool hasCodeExtensions; |
605 ASSERT_EQ(testEncodings[i], f.DetectEncoding(hasCodeExtensions)); | |
606 ASSERT_FALSE(hasCodeExtensions); | |
603 } | 607 } |
604 | 608 |
605 Json::Value s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i]); | 609 Json::Value s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); |
606 f.Replace(DICOM_TAG_PATIENT_NAME, s, false, DicomReplaceMode_InsertIfAbsent); | 610 f.Replace(DICOM_TAG_PATIENT_NAME, s, false, DicomReplaceMode_InsertIfAbsent); |
607 | 611 |
608 Json::Value v; | 612 Json::Value v; |
609 f.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0); | 613 f.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0); |
610 ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i])); | 614 ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i])); |
1159 { | 1163 { |
1160 { | 1164 { |
1161 // Sanity check to test the proper behavior of "EncodingTests.py" | 1165 // Sanity check to test the proper behavior of "EncodingTests.py" |
1162 std::string encoded = Toolbox::ConvertFromUtf8(testEncodingsExpected[i], testEncodings[i]); | 1166 std::string encoded = Toolbox::ConvertFromUtf8(testEncodingsExpected[i], testEncodings[i]); |
1163 ASSERT_STREQ(testEncodingsEncoded[i], encoded.c_str()); | 1167 ASSERT_STREQ(testEncodingsEncoded[i], encoded.c_str()); |
1164 std::string decoded = Toolbox::ConvertToUtf8(encoded, testEncodings[i]); | 1168 std::string decoded = Toolbox::ConvertToUtf8(encoded, testEncodings[i], false); |
1165 ASSERT_STREQ(testEncodingsExpected[i], decoded.c_str()); | 1169 ASSERT_STREQ(testEncodingsExpected[i], decoded.c_str()); |
1166 | 1170 |
1167 if (testEncodings[i] != Encoding_Chinese) | 1171 if (testEncodings[i] != Encoding_Chinese) |
1168 { | 1172 { |
1169 // A specific source string is used in "EncodingTests.py" to | 1173 // A specific source string is used in "EncodingTests.py" to |
1170 // test against Chinese, it is normal that it does not correspond to UTF8 | 1174 // test against Chinese, it is normal that it does not correspond to UTF8 |
1171 | 1175 |
1172 std::string encoded = Toolbox::ConvertToUtf8(Toolbox::ConvertFromUtf8(utf8, testEncodings[i]), testEncodings[i]); | 1176 std::string encoded = Toolbox::ConvertToUtf8(Toolbox::ConvertFromUtf8(utf8, testEncodings[i]), testEncodings[i], false); |
1173 ASSERT_STREQ(testEncodingsExpected[i], encoded.c_str()); | 1177 ASSERT_STREQ(testEncodingsExpected[i], encoded.c_str()); |
1174 } | 1178 } |
1175 } | 1179 } |
1176 | 1180 |
1177 | 1181 |
1225 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false); | 1229 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false); |
1226 | 1230 |
1227 std::string tag; | 1231 std::string tag; |
1228 | 1232 |
1229 ParsedDicomFile dicom(m, Encoding_Utf8); | 1233 ParsedDicomFile dicom(m, Encoding_Utf8); |
1230 ASSERT_EQ(Encoding_Utf8, dicom.GetEncoding()); | 1234 bool hasCodeExtensions; |
1235 ASSERT_EQ(Encoding_Utf8, dicom.DetectEncoding(hasCodeExtensions)); | |
1236 ASSERT_FALSE(hasCodeExtensions); | |
1231 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); | 1237 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); |
1232 ASSERT_EQ(tag, testEncodingsExpected[i]); | 1238 ASSERT_EQ(tag, testEncodingsExpected[i]); |
1233 | 1239 |
1234 { | 1240 { |
1235 Json::Value v; | 1241 Json::Value v; |
1238 ASSERT_STREQ(v["PatientName"].asCString(), testEncodingsExpected[i]); | 1244 ASSERT_STREQ(v["PatientName"].asCString(), testEncodingsExpected[i]); |
1239 } | 1245 } |
1240 | 1246 |
1241 dicom.ChangeEncoding(testEncodings[i]); | 1247 dicom.ChangeEncoding(testEncodings[i]); |
1242 | 1248 |
1243 ASSERT_EQ(testEncodings[i], dicom.GetEncoding()); | 1249 ASSERT_EQ(testEncodings[i], dicom.DetectEncoding(hasCodeExtensions)); |
1250 ASSERT_FALSE(hasCodeExtensions); | |
1244 | 1251 |
1245 const char* c = NULL; | 1252 const char* c = NULL; |
1246 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, c).good()); | 1253 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, c).good()); |
1247 EXPECT_STREQ(c, testEncodingsEncoded[i]); | 1254 EXPECT_STREQ(c, testEncodingsEncoded[i]); |
1248 | 1255 |
1273 // No encoding provided, fallback to default encoding | 1280 // No encoding provided, fallback to default encoding |
1274 DicomMap m; | 1281 DicomMap m; |
1275 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); | 1282 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); |
1276 | 1283 |
1277 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); | 1284 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); |
1278 ASSERT_EQ(Encoding_Latin3, d.GetEncoding()); | 1285 |
1286 bool hasCodeExtensions; | |
1287 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions)); | |
1288 ASSERT_FALSE(hasCodeExtensions); | |
1279 } | 1289 } |
1280 | 1290 |
1281 { | 1291 { |
1282 // Valid encoding, "ISO_IR 13" is Japanese | 1292 // Valid encoding, "ISO_IR 13" is Japanese |
1283 DicomMap m; | 1293 DicomMap m; |
1284 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false); | 1294 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false); |
1285 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); | 1295 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); |
1286 | 1296 |
1287 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); | 1297 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); |
1288 ASSERT_EQ(Encoding_Japanese, d.GetEncoding()); | 1298 |
1299 bool hasCodeExtensions; | |
1300 ASSERT_EQ(Encoding_Japanese, d.DetectEncoding(hasCodeExtensions)); | |
1301 ASSERT_FALSE(hasCodeExtensions); | |
1289 } | 1302 } |
1290 | 1303 |
1291 { | 1304 { |
1292 // Invalid value for an encoding ("nope" is not in the DICOM standard) | 1305 // Invalid value for an encoding ("nope" is not in the DICOM standard) |
1293 DicomMap m; | 1306 DicomMap m; |
1312 DicomMap m; | 1325 DicomMap m; |
1313 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false); | 1326 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false); |
1314 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); | 1327 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); |
1315 | 1328 |
1316 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); | 1329 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); |
1317 ASSERT_EQ(Encoding_Latin3, d.GetEncoding()); | 1330 |
1318 } | 1331 bool hasCodeExtensions; |
1319 } | 1332 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions)); |
1333 ASSERT_FALSE(hasCodeExtensions); | |
1334 } | |
1335 } | |
1336 | |
1337 | |
1338 | |
1339 TEST(Toolbox, RemoveIso2022EscapeSequences) | |
1340 { | |
1341 // +----------------------------------+ | |
1342 // | one-byte control messages | | |
1343 // +----------------------------------+ | |
1344 | |
1345 static const uint8_t iso2022_cstr_oneByteControl[] = { | |
1346 0x0f, 0x41, | |
1347 0x0e, 0x42, | |
1348 0x8e, 0x1b, 0x4e, 0x43, | |
1349 0x8f, 0x1b, 0x4f, 0x44, | |
1350 0x8e, 0x1b, 0x4a, 0x45, | |
1351 0x8f, 0x1b, 0x4a, 0x46, | |
1352 0x50, 0x51, 0x52, 0x00 | |
1353 }; | |
1354 | |
1355 static const uint8_t iso2022_cstr_oneByteControl_ref[] = { | |
1356 0x41, | |
1357 0x42, | |
1358 0x43, | |
1359 0x44, | |
1360 0x8e, 0x1b, 0x4a, 0x45, | |
1361 0x8f, 0x1b, 0x4a, 0x46, | |
1362 0x50, 0x51, 0x52, 0x00 | |
1363 }; | |
1364 | |
1365 // +----------------------------------+ | |
1366 // | two-byte control messages | | |
1367 // +----------------------------------+ | |
1368 | |
1369 static const uint8_t iso2022_cstr_twoByteControl[] = { | |
1370 0x1b, 0x6e, 0x41, | |
1371 0x1b, 0x6f, 0x42, | |
1372 0x1b, 0x4e, 0x43, | |
1373 0x1b, 0x4f, 0x44, | |
1374 0x1b, 0x7e, 0x45, | |
1375 0x1b, 0x7d, 0x46, | |
1376 0x1b, 0x7c, 0x47, 0x00 | |
1377 }; | |
1378 | |
1379 static const uint8_t iso2022_cstr_twoByteControl_ref[] = { | |
1380 0x41, | |
1381 0x42, | |
1382 0x43, | |
1383 0x44, | |
1384 0x45, | |
1385 0x46, | |
1386 0x47, 0x00 | |
1387 }; | |
1388 | |
1389 // +----------------------------------+ | |
1390 // | various-length escape sequences | | |
1391 // +----------------------------------+ | |
1392 | |
1393 static const uint8_t iso2022_cstr_escapeSequence[] = { | |
1394 0x1b, 0x40, 0x41, // 1b and 40 should not be removed (invalid esc seq) | |
1395 0x1b, 0x50, 0x42, // ditto | |
1396 0x1b, 0x7f, 0x43, // ditto | |
1397 0x1b, 0x21, 0x4a, 0x44, // this will match | |
1398 0x1b, 0x20, 0x21, 0x2f, 0x40, 0x45, // this will match | |
1399 0x1b, 0x20, 0x21, 0x2f, 0x2f, 0x40, 0x46, // this will match too | |
1400 0x1b, 0x20, 0x21, 0x2f, 0x1f, 0x47, 0x48, 0x00 // this will NOT match! | |
1401 }; | |
1402 | |
1403 static const uint8_t iso2022_cstr_escapeSequence_ref[] = { | |
1404 0x1b, 0x40, 0x41, // 1b and 40 should not be removed (invalid esc seq) | |
1405 0x1b, 0x50, 0x42, // ditto | |
1406 0x1b, 0x7f, 0x43, // ditto | |
1407 0x44, // this will match | |
1408 0x45, // this will match | |
1409 0x46, // this will match too | |
1410 0x1b, 0x20, 0x21, 0x2f, 0x1f, 0x47, 0x48, 0x00 // this will NOT match! | |
1411 }; | |
1412 | |
1413 | |
1414 // +----------------------------------+ | |
1415 // | a real-world japanese sample | | |
1416 // +----------------------------------+ | |
1417 | |
1418 static const uint8_t iso2022_cstr_real_ir13[] = { | |
1419 0xd4, 0xcf, 0xc0, 0xde, 0x5e, 0xc0, 0xdb, 0xb3, | |
1420 0x3d, 0x1b, 0x24, 0x42, 0x3b, 0x33, 0x45, 0x44, | |
1421 0x1b, 0x28, 0x4a, 0x5e, 0x1b, 0x24, 0x42, 0x42, | |
1422 0x40, 0x4f, 0x3a, 0x1b, 0x28, 0x4a, 0x3d, 0x1b, | |
1423 0x24, 0x42, 0x24, 0x64, 0x24, 0x5e, 0x24, 0x40, | |
1424 0x1b, 0x28, 0x4a, 0x5e, 0x1b, 0x24, 0x42, 0x24, | |
1425 0x3f, 0x24, 0x6d, 0x24, 0x26, 0x1b, 0x28, 0x4a, 0x00 | |
1426 }; | |
1427 | |
1428 static const uint8_t iso2022_cstr_real_ir13_ref[] = { | |
1429 0xd4, 0xcf, 0xc0, 0xde, 0x5e, 0xc0, 0xdb, 0xb3, | |
1430 0x3d, | |
1431 0x3b, 0x33, 0x45, 0x44, | |
1432 0x5e, | |
1433 0x42, | |
1434 0x40, 0x4f, 0x3a, | |
1435 0x3d, | |
1436 0x24, 0x64, 0x24, 0x5e, 0x24, 0x40, | |
1437 0x5e, | |
1438 0x24, | |
1439 0x3f, 0x24, 0x6d, 0x24, 0x26, 0x00 | |
1440 }; | |
1441 | |
1442 | |
1443 | |
1444 // +----------------------------------+ | |
1445 // | the actual test | | |
1446 // +----------------------------------+ | |
1447 | |
1448 std::string iso2022_str_oneByteControl( | |
1449 reinterpret_cast<const char*>(iso2022_cstr_oneByteControl)); | |
1450 std::string iso2022_str_oneByteControl_ref( | |
1451 reinterpret_cast<const char*>(iso2022_cstr_oneByteControl_ref)); | |
1452 std::string iso2022_str_twoByteControl( | |
1453 reinterpret_cast<const char*>(iso2022_cstr_twoByteControl)); | |
1454 std::string iso2022_str_twoByteControl_ref( | |
1455 reinterpret_cast<const char*>(iso2022_cstr_twoByteControl_ref)); | |
1456 std::string iso2022_str_escapeSequence( | |
1457 reinterpret_cast<const char*>(iso2022_cstr_escapeSequence)); | |
1458 std::string iso2022_str_escapeSequence_ref( | |
1459 reinterpret_cast<const char*>(iso2022_cstr_escapeSequence_ref)); | |
1460 std::string iso2022_str_real_ir13( | |
1461 reinterpret_cast<const char*>(iso2022_cstr_real_ir13)); | |
1462 std::string iso2022_str_real_ir13_ref( | |
1463 reinterpret_cast<const char*>(iso2022_cstr_real_ir13_ref)); | |
1464 | |
1465 std::string dest; | |
1466 | |
1467 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_oneByteControl); | |
1468 ASSERT_EQ(dest, iso2022_str_oneByteControl_ref); | |
1469 | |
1470 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_twoByteControl); | |
1471 ASSERT_EQ(dest, iso2022_str_twoByteControl_ref); | |
1472 | |
1473 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_escapeSequence); | |
1474 ASSERT_EQ(dest, iso2022_str_escapeSequence_ref); | |
1475 | |
1476 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_real_ir13); | |
1477 ASSERT_EQ(dest, iso2022_str_real_ir13_ref); | |
1478 } |