Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3223:c94f23198946
unit testing japanese
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 14:16:35 +0100 |
parents | 63681433b0fc |
children | 6399f5f25498 |
comparison
equal
deleted
inserted
replaced
3222:63681433b0fc | 3223:c94f23198946 |
---|---|
1588 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/GivenName"); | 1588 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/GivenName"); |
1589 ASSERT_EQ(utf8.substr(28), node.node().text().as_string()); | 1589 ASSERT_EQ(utf8.substr(28), node.node().text().as_string()); |
1590 #endif | 1590 #endif |
1591 } | 1591 } |
1592 | 1592 |
1593 | |
1594 | |
1595 TEST(Toolbox, EncodingsJapanese) | |
1596 { | |
1597 // http://dicom.nema.org/MEDICAL/dicom/2017c/output/chtml/part05/sect_H.3.html | |
1598 | |
1599 std::string japanese = DecodeFromSpecification( | |
1600 "05/09 06/01 06/13 06/01 06/04 06/01 05/14 05/04 06/01 07/02 06/15 07/05 03/13 " | |
1601 "01/11 02/04 04/02 03/11 03/03 04/05 04/04 01/11 02/08 04/02 05/14 01/11 02/04 " | |
1602 "04/02 04/02 04/00 04/15 03/10 01/11 02/08 04/02 03/13 01/11 02/04 04/02 02/04 " | |
1603 "06/04 02/04 05/14 02/04 04/00 01/11 02/08 04/02 05/14 01/11 02/04 04/02 02/04 " | |
1604 "03/15 02/04 06/13 02/04 02/06 01/11 02/08 04/02"); | |
1605 | |
1606 // This array can be re-generated using command-line: | |
1607 // echo -n "Yamada^Tarou=..." | hexdump -v -e '14/1 "0x%02x, "' -e '"\n"' | |
1608 static const uint8_t utf8raw[] = { | |
1609 0x59, 0x61, 0x6d, 0x61, 0x64, 0x61, 0x5e, 0x54, 0x61, 0x72, 0x6f, 0x75, 0x3d, 0xe5, | |
1610 0xb1, 0xb1, 0xe7, 0x94, 0xb0, 0x5e, 0xe5, 0xa4, 0xaa, 0xe9, 0x83, 0x8e, 0x3d, 0xe3, | |
1611 0x82, 0x84, 0xe3, 0x81, 0xbe, 0xe3, 0x81, 0xa0, 0x5e, 0xe3, 0x81, 0x9f, 0xe3, 0x82, | |
1612 0x8d, 0xe3, 0x81, 0x86 | |
1613 }; | |
1614 | |
1615 std::string utf8(reinterpret_cast<const char*>(utf8raw), sizeof(utf8raw)); | |
1616 | |
1617 ParsedDicomFile dicom(false); | |
1618 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "\\ISO 2022 IR 87"); | |
1619 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString | |
1620 (DCM_PatientName, japanese.c_str(), japanese.size(), true).good()); | |
1621 | |
1622 std::string value; | |
1623 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME)); | |
1624 ASSERT_EQ(utf8, value); | |
1625 | |
1626 DicomWebJsonVisitor visitor; | |
1627 dicom.Apply(visitor); | |
1628 ASSERT_EQ(utf8.substr(0, 12), visitor.GetResult()["00100010"]["Value"][0]["Alphabetic"].asString()); | |
1629 ASSERT_EQ(utf8.substr(13, 13), visitor.GetResult()["00100010"]["Value"][0]["Ideographic"].asString()); | |
1630 ASSERT_EQ(utf8.substr(27), visitor.GetResult()["00100010"]["Value"][0]["Phonetic"].asString()); | |
1631 | |
1632 #if ORTHANC_ENABLE_PUGIXML == 1 | |
1633 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.3.html#table_F.3.1-1 | |
1634 std::string xml; | |
1635 visitor.FormatXml(xml); | |
1636 | |
1637 pugi::xml_document doc; | |
1638 doc.load_buffer(xml.c_str(), xml.size()); | |
1639 | |
1640 pugi::xpath_node node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]/Value"); | |
1641 ASSERT_STREQ("ISO_IR 192", node.node().text().as_string()); | |
1642 | |
1643 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]"); | |
1644 ASSERT_STREQ("CS", node.node().attribute("vr").value()); | |
1645 | |
1646 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]"); | |
1647 ASSERT_STREQ("PN", node.node().attribute("vr").value()); | |
1648 | |
1649 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/FamilyName"); | |
1650 ASSERT_STREQ("Yamada", node.node().text().as_string()); | |
1651 | |
1652 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/GivenName"); | |
1653 ASSERT_STREQ("Tarou", node.node().text().as_string()); | |
1654 | |
1655 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/FamilyName"); | |
1656 ASSERT_EQ(utf8.substr(13, 6), node.node().text().as_string()); | |
1657 | |
1658 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/GivenName"); | |
1659 ASSERT_EQ(utf8.substr(20, 6), node.node().text().as_string()); | |
1660 | |
1661 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/FamilyName"); | |
1662 ASSERT_EQ(utf8.substr(27, 9), node.node().text().as_string()); | |
1663 | |
1664 node = doc.select_single_node("//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/GivenName"); | |
1665 ASSERT_EQ(utf8.substr(37), node.node().text().as_string()); | |
1666 #endif | |
1667 } |