comparison OrthancServer/UnitTestsSources/UnitTestsMain.cpp @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents UnitTestsSources/UnitTestsMain.cpp@5d2348b39392
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #include "PrecompiledHeadersUnitTests.h"
35 #include "../Core/EnumerationDictionary.h"
36
37 #include "gtest/gtest.h"
38
39 #include "../Core/Logging.h"
40 #include "../Core/Toolbox.h"
41 #include "../Core/OrthancException.h"
42
43 #include "../OrthancServer/OrthancInitialization.h"
44 #include "../OrthancServer/ServerEnumerations.h"
45
46
47 using namespace Orthanc;
48
49
50 TEST(EnumerationDictionary, Simple)
51 {
52 EnumerationDictionary<MetadataType> d;
53
54 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException);
55 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5"));
56 ASSERT_EQ(256, d.Translate("256"));
57
58 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate");
59
60 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate"));
61 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2"));
62 ASSERT_EQ("ReceptionDate", d.Translate(MetadataType_Instance_ReceptionDate));
63
64 ASSERT_THROW(d.Add(MetadataType_Instance_ReceptionDate, "Hello"), OrthancException);
65 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "ReceptionDate"), OrthancException); // already used
66 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "1024"), OrthancException); // cannot register numbers
67 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok
68 }
69
70
71 TEST(EnumerationDictionary, ServerEnumerations)
72 {
73 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient));
74 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study));
75 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series));
76 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance));
77
78 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries));
79
80 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure));
81 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success));
82
83 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries));
84
85 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries));
86 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate));
87
88 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT"));
89 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy"));
90 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs"));
91 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance"));
92 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE"));
93 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException);
94
95 ASSERT_EQ(2047, StringToMetadata("2047"));
96 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException);
97 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024)
98 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535)
99 RegisterUserMetadata(2047, "Ceci est un test");
100 ASSERT_EQ(2047, StringToMetadata("2047"));
101 ASSERT_EQ(2047, StringToMetadata("Ceci est un test"));
102
103 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Generic")));
104 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("GenericNoWildcardInDates")));
105 ASSERT_STREQ("GenericNoUniversalWildcard", EnumerationToString(StringToModalityManufacturer("GenericNoUniversalWildcard")));
106 ASSERT_STREQ("StoreScp", EnumerationToString(StringToModalityManufacturer("StoreScp")));
107 ASSERT_STREQ("Vitrea", EnumerationToString(StringToModalityManufacturer("Vitrea")));
108 ASSERT_STREQ("GE", EnumerationToString(StringToModalityManufacturer("GE")));
109 // backward compatibility tests (to remove once we make these manufacturer really obsolete)
110 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("MedInria")));
111 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("EFilm2")));
112 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("ClearCanvas")));
113 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Dcm4Chee")));
114 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("SyngoVia")));
115 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("AgfaImpax")));
116 }
117
118
119
120 int main(int argc, char **argv)
121 {
122 Logging::Initialize();
123 Toolbox::InitializeGlobalLocale(NULL);
124 Logging::EnableInfoLevel(true);
125 Toolbox::DetectEndianness();
126 SystemToolbox::MakeDirectory("UnitTestsResults");
127 OrthancInitialize();
128
129 ::testing::InitGoogleTest(&argc, argv);
130 int result = RUN_ALL_TESTS();
131
132 OrthancFinalize();
133 Logging::Finalize();
134
135 return result;
136 }