comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4325:b96aedfa8cc1

unit tests now running in WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 16:21:29 +0100
parents 50b0c69b653a
children d9473bd5ed43
comparison
equal deleted inserted replaced
4324:433e94d08e36 4325:b96aedfa8cc1
47 #include "../Sources/Images/ImageProcessing.h" 47 #include "../Sources/Images/ImageProcessing.h"
48 #include "../Sources/Images/PngReader.h" 48 #include "../Sources/Images/PngReader.h"
49 #include "../Sources/Images/PngWriter.h" 49 #include "../Sources/Images/PngWriter.h"
50 #include "../Sources/Logging.h" 50 #include "../Sources/Logging.h"
51 #include "../Sources/OrthancException.h" 51 #include "../Sources/OrthancException.h"
52 #include "../Sources/SystemToolbox.h"
53 #include "../Resources/CodeGeneration/EncodingTests.h" 52 #include "../Resources/CodeGeneration/EncodingTests.h"
53
54 #if ORTHANC_SANDBOXED != 1
55 # include "../Sources/SystemToolbox.h"
56 #endif
54 57
55 #include <dcmtk/dcmdata/dcdeftag.h> 58 #include <dcmtk/dcmdata/dcdeftag.h>
56 #include <dcmtk/dcmdata/dcelem.h> 59 #include <dcmtk/dcmdata/dcelem.h>
57 #include <dcmtk/dcmdata/dcvrat.h> 60 #include <dcmtk/dcmdata/dcvrat.h>
58 61
84 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020)); 87 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020));
85 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020)); 88 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020));
86 } 89 }
87 90
88 91
92 #if ORTHANC_SANDBOXED != 1
89 TEST(DicomModification, Basic) 93 TEST(DicomModification, Basic)
90 { 94 {
91 DicomModification m; 95 DicomModification m;
92 m.SetupAnonymization(DicomVersion_2008); 96 m.SetupAnonymization(DicomVersion_2008);
93 //m.SetLevel(DicomRootLevel_Study); 97 //m.SetLevel(DicomRootLevel_Study);
106 o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); 110 o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou");
107 m.Apply(*f); 111 m.Apply(*f);
108 f->SaveToFile(b); 112 f->SaveToFile(b);
109 } 113 }
110 } 114 }
115 #endif
111 116
112 117
113 TEST(DicomModification, Anonymization) 118 TEST(DicomModification, Anonymization)
114 { 119 {
115 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName")); 120 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName"));
180 ASSERT_EQ(5u, reader.GetWidth()); 185 ASSERT_EQ(5u, reader.GetWidth());
181 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat()); 186 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat());
182 187
183 ParsedDicomFile o(true); 188 ParsedDicomFile o(true);
184 o.EmbedContent(s); 189 o.EmbedContent(s);
190
191 #if ORTHANC_SANDBOXED != 1
185 o.SaveToFile("UnitTestsResults/png1.dcm"); 192 o.SaveToFile("UnitTestsResults/png1.dcm");
193 #endif
186 194
187 // Red dot, without alpha channel 195 // Red dot, without alpha channel
188 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; 196 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII=";
189 o.EmbedContent(s); 197 o.EmbedContent(s);
198
199 #if ORTHANC_SANDBOXED != 1
190 o.SaveToFile("UnitTestsResults/png2.dcm"); 200 o.SaveToFile("UnitTestsResults/png2.dcm");
201 #endif
191 202
192 // Check box in Graylevel8 203 // Check box in Graylevel8
193 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; 204 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII=";
194 o.EmbedContent(s); 205 o.EmbedContent(s);
195 //o.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); 206 //o.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing);
207
208 #if ORTHANC_SANDBOXED != 1
196 o.SaveToFile("UnitTestsResults/png3.dcm"); 209 o.SaveToFile("UnitTestsResults/png3.dcm");
210 #endif
197 211
198 212
199 { 213 {
200 // Gradient in Graylevel16 214 // Gradient in Graylevel16
201 215
216 *p = v; 230 *p = v;
217 } 231 }
218 } 232 }
219 233
220 o.EmbedImage(accessor); 234 o.EmbedImage(accessor);
235
236 #if ORTHANC_SANDBOXED != 1
221 o.SaveToFile("UnitTestsResults/png4.dcm"); 237 o.SaveToFile("UnitTestsResults/png4.dcm");
238 #endif
222 } 239 }
223 } 240 }
224 241
225 242
226 TEST(FromDcmtkBridge, Encodings1) 243 TEST(FromDcmtkBridge, Encodings1)
741 758
742 759
743 760
744 TEST(TestImages, PatternGrayscale8) 761 TEST(TestImages, PatternGrayscale8)
745 { 762 {
746 static const char* PATH = "UnitTestsResults/PatternGrayscale8.dcm";
747
748 Orthanc::Image image(Orthanc::PixelFormat_Grayscale8, 256, 256, false); 763 Orthanc::Image image(Orthanc::PixelFormat_Grayscale8, 256, 256, false);
749 764
750 for (int y = 0; y < 256; y++) 765 for (int y = 0; y < 256; y++)
751 { 766 {
752 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y)); 767 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y));
762 Orthanc::ImageProcessing::Set(r, 0); 777 Orthanc::ImageProcessing::Set(r, 0);
763 778
764 image.GetRegion(r, 160, 32, 64, 192); 779 image.GetRegion(r, 160, 32, 64, 192);
765 Orthanc::ImageProcessing::Set(r, 255); 780 Orthanc::ImageProcessing::Set(r, 255);
766 781
782 std::string saved;
783
767 { 784 {
768 ParsedDicomFile f(true); 785 ParsedDicomFile f(true);
769 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); 786 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
770 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); 787 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
771 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC"); 788 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
772 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc"); 789 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
773 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); 790 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
774 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale8"); 791 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale8");
775 f.EmbedImage(image); 792 f.EmbedImage(image);
776 793
777 f.SaveToFile(PATH); 794 f.SaveToMemoryBuffer(saved);
778 } 795 }
779 796
780 { 797 {
781 std::string s; 798 Orthanc::ParsedDicomFile f(saved);
782 Orthanc::SystemToolbox::ReadFile(s, PATH);
783 Orthanc::ParsedDicomFile f(s);
784 799
785 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0)); 800 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0));
786 ASSERT_EQ(256u, decoded->GetWidth()); 801 ASSERT_EQ(256u, decoded->GetWidth());
787 ASSERT_EQ(256u, decoded->GetHeight()); 802 ASSERT_EQ(256u, decoded->GetHeight());
788 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat()); 803 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat());
797 } 812 }
798 813
799 814
800 TEST(TestImages, PatternRGB) 815 TEST(TestImages, PatternRGB)
801 { 816 {
802 static const char* PATH = "UnitTestsResults/PatternRGB24.dcm";
803
804 Orthanc::Image image(Orthanc::PixelFormat_RGB24, 384, 256, false); 817 Orthanc::Image image(Orthanc::PixelFormat_RGB24, 384, 256, false);
805 818
806 for (int y = 0; y < 256; y++) 819 for (int y = 0; y < 256; y++)
807 { 820 {
808 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y)); 821 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y));
823 p[0] = 0; 836 p[0] = 0;
824 p[1] = 0; 837 p[1] = 0;
825 p[2] = y; 838 p[2] = y;
826 } 839 }
827 } 840 }
841
842 std::string saved;
828 843
829 { 844 {
830 ParsedDicomFile f(true); 845 ParsedDicomFile f(true);
831 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); 846 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
832 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); 847 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
834 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc"); 849 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
835 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); 850 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
836 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "RGB24"); 851 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "RGB24");
837 f.EmbedImage(image); 852 f.EmbedImage(image);
838 853
839 f.SaveToFile(PATH); 854 f.SaveToMemoryBuffer(saved);
840 } 855 }
841 856
842 { 857 {
843 std::string s; 858 Orthanc::ParsedDicomFile f(saved);
844 Orthanc::SystemToolbox::ReadFile(s, PATH);
845 Orthanc::ParsedDicomFile f(s);
846 859
847 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0)); 860 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0));
848 ASSERT_EQ(384u, decoded->GetWidth()); 861 ASSERT_EQ(384u, decoded->GetWidth());
849 ASSERT_EQ(256u, decoded->GetHeight()); 862 ASSERT_EQ(256u, decoded->GetHeight());
850 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat()); 863 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat());
859 } 872 }
860 873
861 874
862 TEST(TestImages, PatternUint16) 875 TEST(TestImages, PatternUint16)
863 { 876 {
864 static const char* PATH = "UnitTestsResults/PatternGrayscale16.dcm";
865
866 Orthanc::Image image(Orthanc::PixelFormat_Grayscale16, 256, 256, false); 877 Orthanc::Image image(Orthanc::PixelFormat_Grayscale16, 256, 256, false);
867 878
868 uint16_t v = 0; 879 uint16_t v = 0;
869 for (int y = 0; y < 256; y++) 880 for (int y = 0; y < 256; y++)
870 { 881 {
881 Orthanc::ImageProcessing::Set(r, 0); 892 Orthanc::ImageProcessing::Set(r, 0);
882 893
883 image.GetRegion(r, 160, 32, 64, 192); 894 image.GetRegion(r, 160, 32, 64, 192);
884 Orthanc::ImageProcessing::Set(r, 65535); 895 Orthanc::ImageProcessing::Set(r, 65535);
885 896
897 std::string saved;
898
886 { 899 {
887 ParsedDicomFile f(true); 900 ParsedDicomFile f(true);
888 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); 901 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
889 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); 902 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
890 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC"); 903 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
891 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc"); 904 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
892 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); 905 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
893 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale16"); 906 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale16");
894 f.EmbedImage(image); 907 f.EmbedImage(image);
895 908
896 f.SaveToFile(PATH); 909 f.SaveToMemoryBuffer(saved);
897 } 910 }
898 911
899 { 912 {
900 std::string s; 913 Orthanc::ParsedDicomFile f(saved);
901 Orthanc::SystemToolbox::ReadFile(s, PATH);
902 Orthanc::ParsedDicomFile f(s);
903 914
904 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0)); 915 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0));
905 ASSERT_EQ(256u, decoded->GetWidth()); 916 ASSERT_EQ(256u, decoded->GetWidth());
906 ASSERT_EQ(256u, decoded->GetHeight()); 917 ASSERT_EQ(256u, decoded->GetHeight());
907 ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat()); 918 ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat());
916 } 927 }
917 928
918 929
919 TEST(TestImages, PatternInt16) 930 TEST(TestImages, PatternInt16)
920 { 931 {
921 static const char* PATH = "UnitTestsResults/PatternSignedGrayscale16.dcm";
922
923 Orthanc::Image image(Orthanc::PixelFormat_SignedGrayscale16, 256, 256, false); 932 Orthanc::Image image(Orthanc::PixelFormat_SignedGrayscale16, 256, 256, false);
924 933
925 int16_t v = -32768; 934 int16_t v = -32768;
926 for (int y = 0; y < 256; y++) 935 for (int y = 0; y < 256; y++)
927 { 936 {
937 Orthanc::ImageProcessing::Set(r, -32768); 946 Orthanc::ImageProcessing::Set(r, -32768);
938 947
939 image.GetRegion(r, 160, 32, 64, 192); 948 image.GetRegion(r, 160, 32, 64, 192);
940 Orthanc::ImageProcessing::Set(r, 32767); 949 Orthanc::ImageProcessing::Set(r, 32767);
941 950
951 std::string saved;
952
942 { 953 {
943 ParsedDicomFile f(true); 954 ParsedDicomFile f(true);
944 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); 955 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
945 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); 956 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
946 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC"); 957 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
947 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc"); 958 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
948 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); 959 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
949 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "SignedGrayscale16"); 960 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "SignedGrayscale16");
950 f.EmbedImage(image); 961 f.EmbedImage(image);
951 962
952 f.SaveToFile(PATH); 963 f.SaveToMemoryBuffer(saved);
953 } 964 }
954 965
955 { 966 {
956 std::string s; 967 Orthanc::ParsedDicomFile f(saved);
957 Orthanc::SystemToolbox::ReadFile(s, PATH);
958 Orthanc::ParsedDicomFile f(s);
959 968
960 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0)); 969 std::unique_ptr<Orthanc::ImageAccessor> decoded(f.DecodeFrame(0));
961 ASSERT_EQ(256u, decoded->GetWidth()); 970 ASSERT_EQ(256u, decoded->GetWidth());
962 ASSERT_EQ(256u, decoded->GetHeight()); 971 ASSERT_EQ(256u, decoded->GetHeight());
963 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat()); 972 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat());