comparison UnitTestsSources/FromDcmtkTests.cpp @ 2126:03b065778fc3

cleaning up
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Nov 2016 13:47:21 +0100
parents 4b02ec79728a
children 9329ba17a069
comparison
equal deleted inserted replaced
2125:b9bd52c72ba2 2126:03b065778fc3
378 a.append(b); 378 a.append(b);
379 } 379 }
380 } 380 }
381 381
382 382
383 TEST(FromDcmtkBridge, FromJson) 383 namespace Orthanc
384 { 384 {
385 std::auto_ptr<DcmElement> element; 385 // Namespace for the "FRIEND_TEST()" directive in "FromDcmtkBridge" to apply:
386 386 // https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#private-class-members
387 { 387 TEST(FromDcmtkBridge, FromJson)
388 Json::Value a; 388 {
389 a = "Hello"; 389 std::auto_ptr<DcmElement> element;
390 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)); 390
391 391 {
392 Json::Value b; 392 Json::Value a;
393 FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii); 393 a = "Hello";
394 ASSERT_EQ("Hello", b["0010,0010"].asString()); 394 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8));
395 } 395
396
397 {
398 Json::Value a;
399 a = "Hello";
400 // Cannot assign a string to a sequence
401 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, false, Encoding_Utf8)), OrthancException);
402 }
403
404 {
405 Json::Value a = Json::arrayValue;
406 a.append("Hello");
407 // Cannot assign an array to a string
408 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)), OrthancException);
409 }
410
411 {
412 Json::Value a;
413 a = "data:application/octet-stream;base64,SGVsbG8="; // echo -n "Hello" | base64
414 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8));
415
416 Json::Value b;
417 FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii);
418 ASSERT_EQ("Hello", b["0010,0010"].asString());
419 }
420
421 {
422 Json::Value a = Json::arrayValue;
423 CreateSampleJson(a);
424 element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, true, Encoding_Utf8));
425
426 {
427 Json::Value b; 396 Json::Value b;
428 FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii); 397 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii);
429 ASSERT_EQ(Json::arrayValue, b["0008,1110"].type()); 398 ASSERT_EQ("Hello", b["0010,0010"].asString());
430 ASSERT_EQ(2u, b["0008,1110"].size()); 399 }
400
401 {
402 Json::Value a;
403 a = "Hello";
404 // Cannot assign a string to a sequence
405 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, false, Encoding_Utf8)), OrthancException);
406 }
407
408 {
409 Json::Value a = Json::arrayValue;
410 a.append("Hello");
411 // Cannot assign an array to a string
412 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8)), OrthancException);
413 }
414
415 {
416 Json::Value a;
417 a = "data:application/octet-stream;base64,SGVsbG8="; // echo -n "Hello" | base64
418 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8));
419
420 Json::Value b;
421 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii);
422 ASSERT_EQ("Hello", b["0010,0010"].asString());
423 }
424
425 {
426 Json::Value a = Json::arrayValue;
427 CreateSampleJson(a);
428 element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, true, Encoding_Utf8));
429
430 {
431 Json::Value b;
432 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0, Encoding_Ascii);
433 ASSERT_EQ(Json::arrayValue, b["0008,1110"].type());
434 ASSERT_EQ(2u, b["0008,1110"].size());
431 435
432 Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1; 436 Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1;
433 437
434 ASSERT_EQ(3u, b["0008,1110"][i].size()); 438 ASSERT_EQ(3u, b["0008,1110"][i].size());
435 ASSERT_EQ(2u, b["0008,1110"][1 - i].size()); 439 ASSERT_EQ(2u, b["0008,1110"][1 - i].size());
436 ASSERT_EQ(b["0008,1110"][i]["0010,0010"].asString(), "Hello"); 440 ASSERT_EQ(b["0008,1110"][i]["0010,0010"].asString(), "Hello");
437 ASSERT_EQ(b["0008,1110"][i]["0010,0020"].asString(), "World"); 441 ASSERT_EQ(b["0008,1110"][i]["0010,0020"].asString(), "World");
438 ASSERT_EQ(b["0008,1110"][i]["0008,1030"].asString(), "Toto"); 442 ASSERT_EQ(b["0008,1110"][i]["0008,1030"].asString(), "Toto");
439 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0010"].asString(), "Hello2"); 443 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0010"].asString(), "Hello2");
440 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0020"].asString(), "World2"); 444 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0020"].asString(), "World2");
441 } 445 }
442 446
443 { 447 {
444 Json::Value b; 448 Json::Value b;
445 FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0, Encoding_Ascii); 449 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0, Encoding_Ascii);
446 450
447 Json::Value c; 451 Json::Value c;
448 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human); 452 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human);
449 453
450 a[1]["PatientName"] = "Hello2"; // To remove the Data URI Scheme encoding 454 a[1]["PatientName"] = "Hello2"; // To remove the Data URI Scheme encoding
451 ASSERT_EQ(0, c["ReferencedStudySequence"].compare(a)); 455 ASSERT_EQ(0, c["ReferencedStudySequence"].compare(a));
452 } 456 }
453 } 457 }
454 } 458 }
455 459 }
456 460
457 461
458 TEST(ParsedDicomFile, InsertReplaceStrings) 462 TEST(ParsedDicomFile, InsertReplaceStrings)
459 { 463 {
460 ParsedDicomFile f(true); 464 ParsedDicomFile f(true);