Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3712:2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 02 Mar 2020 15:32:45 +0100 |
parents | 4922bdd046dd |
children | 090022f1b5e1 |
comparison
equal
deleted
inserted
replaced
3709:1f4910999fe7 | 3712:2a170a8f1faf |
---|---|
32 | 32 |
33 | 33 |
34 #include "PrecompiledHeadersUnitTests.h" | 34 #include "PrecompiledHeadersUnitTests.h" |
35 #include "gtest/gtest.h" | 35 #include "gtest/gtest.h" |
36 | 36 |
37 #include "../Core/Compatibility.h" | |
37 #include "../Core/DicomNetworking/DicomFindAnswers.h" | 38 #include "../Core/DicomNetworking/DicomFindAnswers.h" |
38 #include "../Core/DicomParsing/DicomModification.h" | 39 #include "../Core/DicomParsing/DicomModification.h" |
39 #include "../Core/DicomParsing/DicomWebJsonVisitor.h" | 40 #include "../Core/DicomParsing/DicomWebJsonVisitor.h" |
40 #include "../Core/DicomParsing/FromDcmtkBridge.h" | 41 #include "../Core/DicomParsing/FromDcmtkBridge.h" |
41 #include "../Core/DicomParsing/Internals/DicomImageDecoder.h" | 42 #include "../Core/DicomParsing/Internals/DicomImageDecoder.h" |
93 | 94 |
94 for (int i = 0; i < 10; i++) | 95 for (int i = 0; i < 10; i++) |
95 { | 96 { |
96 char b[1024]; | 97 char b[1024]; |
97 sprintf(b, "UnitTestsResults/anon%06d.dcm", i); | 98 sprintf(b, "UnitTestsResults/anon%06d.dcm", i); |
98 std::auto_ptr<ParsedDicomFile> f(o.Clone(false)); | 99 std::unique_ptr<ParsedDicomFile> f(o.Clone(false)); |
99 if (i > 4) | 100 if (i > 4) |
100 o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); | 101 o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); |
101 m.Apply(*f); | 102 m.Apply(*f); |
102 f->SaveToFile(b); | 103 f->SaveToFile(b); |
103 } | 104 } |
400 { | 401 { |
401 // Namespace for the "FRIEND_TEST()" directive in "FromDcmtkBridge" to apply: | 402 // Namespace for the "FRIEND_TEST()" directive in "FromDcmtkBridge" to apply: |
402 // https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#private-class-members | 403 // https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#private-class-members |
403 TEST(FromDcmtkBridge, FromJson) | 404 TEST(FromDcmtkBridge, FromJson) |
404 { | 405 { |
405 std::auto_ptr<DcmElement> element; | 406 std::unique_ptr<DcmElement> element; |
406 | 407 |
407 { | 408 { |
408 Json::Value a; | 409 Json::Value a; |
409 a = "Hello"; | 410 a = "Hello"; |
410 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, "")); | 411 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, "")); |
815 DicomToJsonFlags_IncludeUnknownTags | | 816 DicomToJsonFlags_IncludeUnknownTags | |
816 DicomToJsonFlags_ConvertBinaryToAscii); | 817 DicomToJsonFlags_ConvertBinaryToAscii); |
817 | 818 |
818 | 819 |
819 { | 820 { |
820 std::auto_ptr<ParsedDicomFile> dicom | 821 std::unique_ptr<ParsedDicomFile> dicom |
821 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); | 822 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); |
822 | 823 |
823 Json::Value vv; | 824 Json::Value vv; |
824 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, toJsonFlags, 0); | 825 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, toJsonFlags, 0); |
825 | 826 |
831 ASSERT_TRUE(vv.isMember("PatientID")); | 832 ASSERT_TRUE(vv.isMember("PatientID")); |
832 } | 833 } |
833 | 834 |
834 | 835 |
835 { | 836 { |
836 std::auto_ptr<ParsedDicomFile> dicom | 837 std::unique_ptr<ParsedDicomFile> dicom |
837 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); | 838 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), "")); |
838 | 839 |
839 Json::Value vv; | 840 Json::Value vv; |
840 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData), 0); | 841 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData), 0); |
841 | 842 |
845 ASSERT_EQ(5u * 5u * 3u /* the red dot is 5x5 pixels in RGB24 */ + 1 /* for padding */, content.size()); | 846 ASSERT_EQ(5u * 5u * 3u /* the red dot is 5x5 pixels in RGB24 */ + 1 /* for padding */, content.size()); |
846 } | 847 } |
847 | 848 |
848 | 849 |
849 { | 850 { |
850 std::auto_ptr<ParsedDicomFile> dicom | 851 std::unique_ptr<ParsedDicomFile> dicom |
851 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_DecodeDataUriScheme), "")); | 852 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_DecodeDataUriScheme), "")); |
852 | 853 |
853 Json::Value vv; | 854 Json::Value vv; |
854 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, toJsonFlags, 0); | 855 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, toJsonFlags, 0); |
855 | 856 |
914 { | 915 { |
915 std::string s; | 916 std::string s; |
916 Orthanc::SystemToolbox::ReadFile(s, PATH); | 917 Orthanc::SystemToolbox::ReadFile(s, PATH); |
917 Orthanc::ParsedDicomFile f(s); | 918 Orthanc::ParsedDicomFile f(s); |
918 | 919 |
919 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | 920 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); |
920 ASSERT_EQ(256u, decoded->GetWidth()); | 921 ASSERT_EQ(256u, decoded->GetWidth()); |
921 ASSERT_EQ(256u, decoded->GetHeight()); | 922 ASSERT_EQ(256u, decoded->GetHeight()); |
922 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat()); | 923 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat()); |
923 | 924 |
924 for (int y = 0; y < 256; y++) | 925 for (int y = 0; y < 256; y++) |
976 { | 977 { |
977 std::string s; | 978 std::string s; |
978 Orthanc::SystemToolbox::ReadFile(s, PATH); | 979 Orthanc::SystemToolbox::ReadFile(s, PATH); |
979 Orthanc::ParsedDicomFile f(s); | 980 Orthanc::ParsedDicomFile f(s); |
980 | 981 |
981 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | 982 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); |
982 ASSERT_EQ(384u, decoded->GetWidth()); | 983 ASSERT_EQ(384u, decoded->GetWidth()); |
983 ASSERT_EQ(256u, decoded->GetHeight()); | 984 ASSERT_EQ(256u, decoded->GetHeight()); |
984 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat()); | 985 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat()); |
985 | 986 |
986 for (int y = 0; y < 256; y++) | 987 for (int y = 0; y < 256; y++) |
1033 { | 1034 { |
1034 std::string s; | 1035 std::string s; |
1035 Orthanc::SystemToolbox::ReadFile(s, PATH); | 1036 Orthanc::SystemToolbox::ReadFile(s, PATH); |
1036 Orthanc::ParsedDicomFile f(s); | 1037 Orthanc::ParsedDicomFile f(s); |
1037 | 1038 |
1038 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | 1039 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); |
1039 ASSERT_EQ(256u, decoded->GetWidth()); | 1040 ASSERT_EQ(256u, decoded->GetWidth()); |
1040 ASSERT_EQ(256u, decoded->GetHeight()); | 1041 ASSERT_EQ(256u, decoded->GetHeight()); |
1041 ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat()); | 1042 ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat()); |
1042 | 1043 |
1043 for (int y = 0; y < 256; y++) | 1044 for (int y = 0; y < 256; y++) |
1089 { | 1090 { |
1090 std::string s; | 1091 std::string s; |
1091 Orthanc::SystemToolbox::ReadFile(s, PATH); | 1092 Orthanc::SystemToolbox::ReadFile(s, PATH); |
1092 Orthanc::ParsedDicomFile f(s); | 1093 Orthanc::ParsedDicomFile f(s); |
1093 | 1094 |
1094 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | 1095 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); |
1095 ASSERT_EQ(256u, decoded->GetWidth()); | 1096 ASSERT_EQ(256u, decoded->GetWidth()); |
1096 ASSERT_EQ(256u, decoded->GetHeight()); | 1097 ASSERT_EQ(256u, decoded->GetHeight()); |
1097 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat()); | 1098 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat()); |
1098 | 1099 |
1099 for (int y = 0; y < 256; y++) | 1100 for (int y = 0; y < 256; y++) |