Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3691:4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Feb 2020 21:44:09 +0100 |
parents | 94f4a18a79cc |
children | 2a170a8f1faf |
comparison
equal
deleted
inserted
replaced
3690:a9ce35d67c3c | 3691:4922bdd046dd |
---|---|
106 | 106 |
107 TEST(DicomModification, Anonymization) | 107 TEST(DicomModification, Anonymization) |
108 { | 108 { |
109 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName")); | 109 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName")); |
110 | 110 |
111 const DicomTag privateTag(0x0045, 0x0010); | 111 const DicomTag privateTag(0x0045, 0x1010); |
112 const DicomTag privateTag2(FromDcmtkBridge::ParseTag("0031-1020")); | 112 const DicomTag privateTag2(FromDcmtkBridge::ParseTag("0031-1020")); |
113 ASSERT_TRUE(privateTag.IsPrivate()); | 113 ASSERT_TRUE(privateTag.IsPrivate()); |
114 ASSERT_TRUE(privateTag2.IsPrivate()); | 114 ASSERT_TRUE(privateTag2.IsPrivate()); |
115 ASSERT_EQ(0x0031, privateTag2.GetGroup()); | 115 ASSERT_EQ(0x0031, privateTag2.GetGroup()); |
116 ASSERT_EQ(0x1020, privateTag2.GetElement()); | 116 ASSERT_EQ(0x1020, privateTag2.GetElement()); |
117 | 117 |
118 std::string s; | 118 std::string s; |
119 ParsedDicomFile o(true); | 119 ParsedDicomFile o(true); |
120 o.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "coucou"); | 120 o.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "coucou"); |
121 ASSERT_FALSE(o.GetTagValue(s, privateTag)); | 121 ASSERT_FALSE(o.GetTagValue(s, privateTag)); |
122 o.Insert(privateTag, "private tag", false); | 122 o.Insert(privateTag, "private tag", false, "OrthancCreator"); |
123 ASSERT_TRUE(o.GetTagValue(s, privateTag)); | 123 ASSERT_TRUE(o.GetTagValue(s, privateTag)); |
124 ASSERT_STREQ("private tag", s.c_str()); | 124 ASSERT_STREQ("private tag", s.c_str()); |
125 | 125 |
126 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); | 126 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); |
127 ASSERT_THROW(o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_ThrowIfAbsent), OrthancException); | 127 ASSERT_THROW(o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_ThrowIfAbsent, "OrthancCreator"), OrthancException); |
128 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); | 128 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); |
129 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_IgnoreIfAbsent); | 129 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_IgnoreIfAbsent, "OrthancCreator"); |
130 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); | 130 ASSERT_FALSE(o.GetTagValue(s, privateTag2)); |
131 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_InsertIfAbsent); | 131 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_InsertIfAbsent, "OrthancCreator"); |
132 ASSERT_TRUE(o.GetTagValue(s, privateTag2)); | 132 ASSERT_TRUE(o.GetTagValue(s, privateTag2)); |
133 ASSERT_STREQ("hello", s.c_str()); | 133 ASSERT_STREQ("hello", s.c_str()); |
134 o.ReplacePlainString(privateTag2, "hello world"); | 134 o.Replace(privateTag2, std::string("hello world"), false, DicomReplaceMode_InsertIfAbsent, "OrthancCreator"); |
135 ASSERT_TRUE(o.GetTagValue(s, privateTag2)); | 135 ASSERT_TRUE(o.GetTagValue(s, privateTag2)); |
136 ASSERT_STREQ("hello world", s.c_str()); | 136 ASSERT_STREQ("hello world", s.c_str()); |
137 | 137 |
138 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); | 138 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); |
139 ASSERT_FALSE(Toolbox::IsUuid(s)); | 139 ASSERT_FALSE(Toolbox::IsUuid(s)); |
288 { | 288 { |
289 ParsedDicomFile f(true); | 289 ParsedDicomFile f(true); |
290 f.SetEncoding(testEncodings[i]); | 290 f.SetEncoding(testEncodings[i]); |
291 | 291 |
292 std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); | 292 std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); |
293 f.Insert(DICOM_TAG_PATIENT_NAME, s, false); | 293 f.Insert(DICOM_TAG_PATIENT_NAME, s, false, ""); |
294 f.SaveToMemoryBuffer(dicom); | 294 f.SaveToMemoryBuffer(dicom); |
295 } | 295 } |
296 | 296 |
297 if (testEncodings[i] != Encoding_Windows1251) | 297 if (testEncodings[i] != Encoding_Windows1251) |
298 { | 298 { |
405 std::auto_ptr<DcmElement> element; | 405 std::auto_ptr<DcmElement> element; |
406 | 406 |
407 { | 407 { |
408 Json::Value a; | 408 Json::Value a; |
409 a = "Hello"; | 409 a = "Hello"; |
410 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)); | 410 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, "")); |
411 | 411 |
412 Json::Value b; | 412 Json::Value b; |
413 std::set<DicomTag> ignoreTagLength; | 413 std::set<DicomTag> ignoreTagLength; |
414 ignoreTagLength.insert(DICOM_TAG_PATIENT_ID); | 414 ignoreTagLength.insert(DICOM_TAG_PATIENT_ID); |
415 | 415 |
437 | 437 |
438 { | 438 { |
439 Json::Value a; | 439 Json::Value a; |
440 a = "Hello"; | 440 a = "Hello"; |
441 // Cannot assign a string to a sequence | 441 // Cannot assign a string to a sequence |
442 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, false, Encoding_Utf8)), OrthancException); | 442 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, false, Encoding_Utf8, "")), OrthancException); |
443 } | 443 } |
444 | 444 |
445 { | 445 { |
446 Json::Value a = Json::arrayValue; | 446 Json::Value a = Json::arrayValue; |
447 a.append("Hello"); | 447 a.append("Hello"); |
448 // Cannot assign an array to a string | 448 // Cannot assign an array to a string |
449 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)), OrthancException); | 449 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, "")), OrthancException); |
450 } | 450 } |
451 | 451 |
452 { | 452 { |
453 Json::Value a; | 453 Json::Value a; |
454 a = "data:application/octet-stream;base64,SGVsbG8="; // echo -n "Hello" | base64 | 454 a = "data:application/octet-stream;base64,SGVsbG8="; // echo -n "Hello" | base64 |
455 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8)); | 455 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8, "")); |
456 | 456 |
457 Json::Value b; | 457 Json::Value b; |
458 std::set<DicomTag> ignoreTagLength; | 458 std::set<DicomTag> ignoreTagLength; |
459 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 459 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
460 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); | 460 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength); |
462 } | 462 } |
463 | 463 |
464 { | 464 { |
465 Json::Value a = Json::arrayValue; | 465 Json::Value a = Json::arrayValue; |
466 CreateSampleJson(a); | 466 CreateSampleJson(a); |
467 element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, true, Encoding_Utf8)); | 467 element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, true, Encoding_Utf8, "")); |
468 | 468 |
469 { | 469 { |
470 Json::Value b; | 470 Json::Value b; |
471 std::set<DicomTag> ignoreTagLength; | 471 std::set<DicomTag> ignoreTagLength; |
472 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, | 472 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, |
504 | 504 |
505 TEST(ParsedDicomFile, InsertReplaceStrings) | 505 TEST(ParsedDicomFile, InsertReplaceStrings) |
506 { | 506 { |
507 ParsedDicomFile f(true); | 507 ParsedDicomFile f(true); |
508 | 508 |
509 f.Insert(DICOM_TAG_PATIENT_NAME, "World", false); | 509 f.Insert(DICOM_TAG_PATIENT_NAME, "World", false, ""); |
510 ASSERT_THROW(f.Insert(DICOM_TAG_PATIENT_ID, "Hello", false), OrthancException); // Already existing tag | 510 ASSERT_THROW(f.Insert(DICOM_TAG_PATIENT_ID, "Hello", false, ""), OrthancException); // Already existing tag |
511 f.ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, "Toto"); // (*) | 511 f.ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, "Toto"); // (*) |
512 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "Tata"); // (**) | 512 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "Tata"); // (**) |
513 | 513 |
514 std::string s; | 514 std::string s; |
515 ASSERT_FALSE(f.LookupTransferSyntax(s)); | 515 ASSERT_FALSE(f.LookupTransferSyntax(s)); |
516 | 516 |
517 ASSERT_THROW(f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), | 517 ASSERT_THROW(f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), |
518 false, DicomReplaceMode_ThrowIfAbsent), OrthancException); | 518 false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException); |
519 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_IgnoreIfAbsent); | 519 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_IgnoreIfAbsent, ""); |
520 ASSERT_FALSE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); | 520 ASSERT_FALSE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); |
521 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_InsertIfAbsent); | 521 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_InsertIfAbsent, ""); |
522 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); | 522 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); |
523 ASSERT_EQ(s, "Accession"); | 523 ASSERT_EQ(s, "Accession"); |
524 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession2"), false, DicomReplaceMode_IgnoreIfAbsent); | 524 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession2"), false, DicomReplaceMode_IgnoreIfAbsent, ""); |
525 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); | 525 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); |
526 ASSERT_EQ(s, "Accession2"); | 526 ASSERT_EQ(s, "Accession2"); |
527 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession3"), false, DicomReplaceMode_ThrowIfAbsent); | 527 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession3"), false, DicomReplaceMode_ThrowIfAbsent, ""); |
528 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); | 528 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER)); |
529 ASSERT_EQ(s, "Accession3"); | 529 ASSERT_EQ(s, "Accession3"); |
530 | 530 |
531 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); | 531 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); |
532 ASSERT_EQ(s, "World"); | 532 ASSERT_EQ(s, "World"); |
550 Json::Value a; | 550 Json::Value a; |
551 CreateSampleJson(a); | 551 CreateSampleJson(a); |
552 | 552 |
553 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); | 553 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); |
554 f.Remove(REFERENCED_STUDY_SEQUENCE); // No effect | 554 f.Remove(REFERENCED_STUDY_SEQUENCE); // No effect |
555 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true); | 555 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, ""); |
556 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); | 556 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); |
557 ASSERT_THROW(f.Insert(REFERENCED_STUDY_SEQUENCE, a, true), OrthancException); | 557 ASSERT_THROW(f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, ""), OrthancException); |
558 f.Remove(REFERENCED_STUDY_SEQUENCE); | 558 f.Remove(REFERENCED_STUDY_SEQUENCE); |
559 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); | 559 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); |
560 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true); | 560 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, ""); |
561 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); | 561 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE)); |
562 | 562 |
563 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); | 563 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); |
564 ASSERT_THROW(f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_ThrowIfAbsent), OrthancException); | 564 ASSERT_THROW(f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException); |
565 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); | 565 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); |
566 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_IgnoreIfAbsent); | 566 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_IgnoreIfAbsent, ""); |
567 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); | 567 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); |
568 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_InsertIfAbsent); | 568 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_InsertIfAbsent, ""); |
569 ASSERT_TRUE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); | 569 ASSERT_TRUE(f.HasTag(REFERENCED_PATIENT_SEQUENCE)); |
570 | 570 |
571 { | 571 { |
572 Json::Value b; | 572 Json::Value b; |
573 f.DatasetToJson(b, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0); | 573 f.DatasetToJson(b, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0); |
578 ASSERT_EQ(0, c["ReferencedPatientSequence"].compare(a)); | 578 ASSERT_EQ(0, c["ReferencedPatientSequence"].compare(a)); |
579 ASSERT_NE(0, c["ReferencedStudySequence"].compare(a)); // Because Data URI Scheme decoding was enabled | 579 ASSERT_NE(0, c["ReferencedStudySequence"].compare(a)); // Because Data URI Scheme decoding was enabled |
580 } | 580 } |
581 | 581 |
582 a = "data:application/octet-stream;base64,VGF0YQ=="; // echo -n "Tata" | base64 | 582 a = "data:application/octet-stream;base64,VGF0YQ=="; // echo -n "Tata" | base64 |
583 f.Replace(DICOM_TAG_SOP_INSTANCE_UID, a, false, DicomReplaceMode_InsertIfAbsent); // (*) | 583 f.Replace(DICOM_TAG_SOP_INSTANCE_UID, a, false, DicomReplaceMode_InsertIfAbsent, ""); // (*) |
584 f.Replace(DICOM_TAG_SOP_CLASS_UID, a, true, DicomReplaceMode_InsertIfAbsent); // (**) | 584 f.Replace(DICOM_TAG_SOP_CLASS_UID, a, true, DicomReplaceMode_InsertIfAbsent, ""); // (**) |
585 | 585 |
586 std::string s; | 586 std::string s; |
587 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_INSTANCE_UID)); | 587 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_INSTANCE_UID)); |
588 ASSERT_EQ(s, a.asString()); | 588 ASSERT_EQ(s, a.asString()); |
589 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); // Implicitly modified by (*) | 589 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); // Implicitly modified by (*) |
612 ASSERT_EQ(testEncodings[i], f.DetectEncoding(hasCodeExtensions)); | 612 ASSERT_EQ(testEncodings[i], f.DetectEncoding(hasCodeExtensions)); |
613 ASSERT_FALSE(hasCodeExtensions); | 613 ASSERT_FALSE(hasCodeExtensions); |
614 } | 614 } |
615 | 615 |
616 Json::Value s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); | 616 Json::Value s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false); |
617 f.Replace(DICOM_TAG_PATIENT_NAME, s, false, DicomReplaceMode_InsertIfAbsent); | 617 f.Replace(DICOM_TAG_PATIENT_NAME, s, false, DicomReplaceMode_InsertIfAbsent, ""); |
618 | 618 |
619 Json::Value v; | 619 Json::Value v; |
620 f.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0); | 620 f.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0); |
621 ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i])); | 621 ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i])); |
622 } | 622 } |
624 } | 624 } |
625 | 625 |
626 | 626 |
627 TEST(ParsedDicomFile, ToJsonFlags1) | 627 TEST(ParsedDicomFile, ToJsonFlags1) |
628 { | 628 { |
629 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), ValueRepresentation_PersonName, "MyPrivateTag", 1, 1, ""); | 629 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), ValueRepresentation_OtherByte, "MyPrivateTag", 1, 1, "OrthancCreator"); |
630 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), ValueRepresentation_PersonName, "Declared public tag", 1, 1, ""); | 630 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), ValueRepresentation_PersonName, "Declared public tag", 1, 1, ""); |
631 | 631 |
632 ParsedDicomFile f(true); | 632 ParsedDicomFile f(true); |
633 f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false); // Even group => public tag | 633 f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false, ""); // Even group => public tag |
634 f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false); // Even group => public, unknown tag | 634 f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false, ""); // Even group => public, unknown tag |
635 f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false); // Odd group => private tag | 635 f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false, "OrthancCreator"); // Odd group => private tag |
636 | 636 |
637 Json::Value v; | 637 Json::Value v; |
638 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); | 638 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); |
639 ASSERT_EQ(Json::objectValue, v.type()); | 639 ASSERT_EQ(Json::objectValue, v.type()); |
640 ASSERT_EQ(6u, v.getMemberNames().size()); | 640 ASSERT_EQ(6u, v.getMemberNames().size()); |
642 ASSERT_FALSE(v.isMember("7053,1000")); | 642 ASSERT_FALSE(v.isMember("7053,1000")); |
643 ASSERT_TRUE(v.isMember("7050,1000")); | 643 ASSERT_TRUE(v.isMember("7050,1000")); |
644 ASSERT_EQ(Json::stringValue, v["7050,1000"].type()); | 644 ASSERT_EQ(Json::stringValue, v["7050,1000"].type()); |
645 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); | 645 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); |
646 | 646 |
647 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_ConvertBinaryToNull), 0); | 647 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0); |
648 ASSERT_EQ(Json::objectValue, v.type()); | 648 ASSERT_EQ(Json::objectValue, v.type()); |
649 ASSERT_EQ(7u, v.getMemberNames().size()); | 649 ASSERT_EQ(7u, v.getMemberNames().size()); |
650 ASSERT_FALSE(v.isMember("7052,1000")); | 650 ASSERT_FALSE(v.isMember("7052,1000")); |
651 ASSERT_TRUE(v.isMember("7050,1000")); | 651 ASSERT_TRUE(v.isMember("7050,1000")); |
652 ASSERT_TRUE(v.isMember("7053,1000")); | 652 ASSERT_TRUE(v.isMember("7053,1000")); |
653 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); | 653 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); |
654 ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); | 654 ASSERT_EQ(Json::nullValue, v["7053,1000"].type()); |
655 | 655 |
656 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0); | 656 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags), 0); |
657 ASSERT_EQ(Json::objectValue, v.type()); | |
658 ASSERT_EQ(6u, v.getMemberNames().size()); | |
659 ASSERT_FALSE(v.isMember("7052,1000")); | |
660 ASSERT_TRUE(v.isMember("7050,1000")); | |
661 ASSERT_FALSE(v.isMember("7053,1000")); | |
662 | |
663 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary), 0); | |
657 ASSERT_EQ(Json::objectValue, v.type()); | 664 ASSERT_EQ(Json::objectValue, v.type()); |
658 ASSERT_EQ(7u, v.getMemberNames().size()); | 665 ASSERT_EQ(7u, v.getMemberNames().size()); |
659 ASSERT_FALSE(v.isMember("7052,1000")); | 666 ASSERT_FALSE(v.isMember("7052,1000")); |
660 ASSERT_TRUE(v.isMember("7050,1000")); | 667 ASSERT_TRUE(v.isMember("7050,1000")); |
661 ASSERT_TRUE(v.isMember("7053,1000")); | 668 ASSERT_TRUE(v.isMember("7053,1000")); |
664 ASSERT_EQ(Json::stringValue, v["7053,1000"].type()); | 671 ASSERT_EQ(Json::stringValue, v["7053,1000"].type()); |
665 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7053,1000"].asString())); | 672 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7053,1000"].asString())); |
666 ASSERT_EQ("application/octet-stream", mime); | 673 ASSERT_EQ("application/octet-stream", mime); |
667 ASSERT_EQ("Some private tag", content); | 674 ASSERT_EQ("Some private tag", content); |
668 | 675 |
669 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_ConvertBinaryToNull), 0); | 676 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0); |
670 ASSERT_EQ(Json::objectValue, v.type()); | 677 ASSERT_EQ(Json::objectValue, v.type()); |
671 ASSERT_EQ(7u, v.getMemberNames().size()); | 678 ASSERT_EQ(7u, v.getMemberNames().size()); |
672 ASSERT_TRUE(v.isMember("7050,1000")); | 679 ASSERT_TRUE(v.isMember("7050,1000")); |
673 ASSERT_TRUE(v.isMember("7052,1000")); | 680 ASSERT_TRUE(v.isMember("7052,1000")); |
674 ASSERT_FALSE(v.isMember("7053,1000")); | 681 ASSERT_FALSE(v.isMember("7053,1000")); |
675 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); | 682 ASSERT_EQ("Some public tag", v["7050,1000"].asString()); |
676 ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); | 683 ASSERT_EQ(Json::nullValue, v["7052,1000"].type()); |
677 | 684 |
678 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags), 0); | 685 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludeBinary), 0); |
679 ASSERT_EQ(Json::objectValue, v.type()); | 686 ASSERT_EQ(Json::objectValue, v.type()); |
680 ASSERT_EQ(7u, v.getMemberNames().size()); | 687 ASSERT_EQ(7u, v.getMemberNames().size()); |
681 ASSERT_TRUE(v.isMember("7050,1000")); | 688 ASSERT_TRUE(v.isMember("7050,1000")); |
682 ASSERT_TRUE(v.isMember("7052,1000")); | 689 ASSERT_TRUE(v.isMember("7052,1000")); |
683 ASSERT_FALSE(v.isMember("7053,1000")); | 690 ASSERT_FALSE(v.isMember("7053,1000")); |
685 ASSERT_EQ(Json::stringValue, v["7052,1000"].type()); | 692 ASSERT_EQ(Json::stringValue, v["7052,1000"].type()); |
686 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7052,1000"].asString())); | 693 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7052,1000"].asString())); |
687 ASSERT_EQ("application/octet-stream", mime); | 694 ASSERT_EQ("application/octet-stream", mime); |
688 ASSERT_EQ("Some unknown tag", content); | 695 ASSERT_EQ("Some unknown tag", content); |
689 | 696 |
690 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_ConvertBinaryToNull), 0); | 697 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0); |
691 ASSERT_EQ(Json::objectValue, v.type()); | 698 ASSERT_EQ(Json::objectValue, v.type()); |
692 ASSERT_EQ(8u, v.getMemberNames().size()); | 699 ASSERT_EQ(8u, v.getMemberNames().size()); |
693 ASSERT_TRUE(v.isMember("7050,1000")); | 700 ASSERT_TRUE(v.isMember("7050,1000")); |
694 ASSERT_TRUE(v.isMember("7052,1000")); | 701 ASSERT_TRUE(v.isMember("7052,1000")); |
695 ASSERT_TRUE(v.isMember("7053,1000")); | 702 ASSERT_TRUE(v.isMember("7053,1000")); |
700 | 707 |
701 | 708 |
702 TEST(ParsedDicomFile, ToJsonFlags2) | 709 TEST(ParsedDicomFile, ToJsonFlags2) |
703 { | 710 { |
704 ParsedDicomFile f(true); | 711 ParsedDicomFile f(true); |
705 f.Insert(DICOM_TAG_PIXEL_DATA, "Pixels", false); | 712 f.Insert(DICOM_TAG_PIXEL_DATA, "Pixels", false, ""); |
706 | 713 |
707 Json::Value v; | 714 Json::Value v; |
708 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); | 715 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0); |
709 ASSERT_EQ(Json::objectValue, v.type()); | 716 ASSERT_EQ(Json::objectValue, v.type()); |
710 ASSERT_EQ(5u, v.getMemberNames().size()); | 717 ASSERT_EQ(5u, v.getMemberNames().size()); |
809 DicomToJsonFlags_ConvertBinaryToAscii); | 816 DicomToJsonFlags_ConvertBinaryToAscii); |
810 | 817 |
811 | 818 |
812 { | 819 { |
813 std::auto_ptr<ParsedDicomFile> dicom | 820 std::auto_ptr<ParsedDicomFile> dicom |
814 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers))); | 821 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); |
815 | 822 |
816 Json::Value vv; | 823 Json::Value vv; |
817 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, toJsonFlags, 0); | 824 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, toJsonFlags, 0); |
818 | 825 |
819 ASSERT_EQ(vv["SOPClassUID"].asString(), sopClassUid); | 826 ASSERT_EQ(vv["SOPClassUID"].asString(), sopClassUid); |
825 } | 832 } |
826 | 833 |
827 | 834 |
828 { | 835 { |
829 std::auto_ptr<ParsedDicomFile> dicom | 836 std::auto_ptr<ParsedDicomFile> dicom |
830 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers))); | 837 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); |
831 | 838 |
832 Json::Value vv; | 839 Json::Value vv; |
833 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData), 0); | 840 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData), 0); |
834 | 841 |
835 std::string mime, content; | 842 std::string mime, content; |
839 } | 846 } |
840 | 847 |
841 | 848 |
842 { | 849 { |
843 std::auto_ptr<ParsedDicomFile> dicom | 850 std::auto_ptr<ParsedDicomFile> dicom |
844 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_DecodeDataUriScheme))); | 851 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_DecodeDataUriScheme), "")); |
845 | 852 |
846 Json::Value vv; | 853 Json::Value vv; |
847 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, toJsonFlags, 0); | 854 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, toJsonFlags, 0); |
848 | 855 |
849 ASSERT_FALSE(vv.isMember("SOPInstanceUID")); | 856 ASSERT_FALSE(vv.isMember("SOPInstanceUID")); |