annotate UnitTestsSources/main.cpp @ 671:7131193b0e4b

fix mainline version
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 Nov 2013 16:28:58 +0100
parents 900274ed996f
children d76b747aec1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
1 #include "../Core/EnumerationDictionary.h"
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
2
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #include "gtest/gtest.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 #include <ctype.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #include "../Core/Compression/ZlibCompressor.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #include "../Core/DicomFormat/DicomTag.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 #include "../Core/HttpServer/HttpHandler.h"
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
10 #include "../Core/OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #include "../Core/Toolbox.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #include "../Core/Uuid.h"
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
13 #include "../OrthancServer/FromDcmtkBridge.h"
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
14 #include "../OrthancServer/OrthancInitialization.h"
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
15 #include "../Core/MultiThreading/SharedMessageQueue.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
17 using namespace Orthanc;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 TEST(Uuid, Generation)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 for (int i = 0; i < 10; i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 std::string s = Toolbox::GenerateUuid();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 ASSERT_TRUE(Toolbox::IsUuid(s));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 TEST(Uuid, Test)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 ASSERT_FALSE(Toolbox::IsUuid(""));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000"));
402
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
34 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
35 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
36 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
37 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
38 }
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
39
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
40 TEST(Toolbox, IsSHA1)
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
41 {
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
42 ASSERT_FALSE(Toolbox::IsSHA1(""));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
43 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
44 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
45 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9"));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
46
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
47 std::string s;
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
48 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
49 ASSERT_TRUE(Toolbox::IsSHA1(s));
d2c69150a979 bulk storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 337
diff changeset
50 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 TEST(Zlib, Basic)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 std::string s = Toolbox::GenerateUuid();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 s = s + s + s + s;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 std::string compressed;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ZlibCompressor c;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 c.Compress(compressed, s);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 std::string uncompressed;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 c.Uncompress(uncompressed, compressed);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ASSERT_EQ(s.size(), uncompressed.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size()));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 TEST(Zlib, Empty)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 std::string s = "";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 std::string compressed;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ZlibCompressor c;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 c.Compress(compressed, s);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 std::string uncompressed;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 c.Uncompress(uncompressed, compressed);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ASSERT_EQ(0u, uncompressed.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 TEST(ParseGetQuery, Basic)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 HttpHandler::Arguments a;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 HttpHandler::ParseGetQuery(a, "aaa=baaa&bb=a&aa=c");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_EQ(3u, a.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ASSERT_EQ(a["aaa"], "baaa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ASSERT_EQ(a["bb"], "a");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 ASSERT_EQ(a["aa"], "c");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 TEST(ParseGetQuery, BasicEmpty)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 HttpHandler::Arguments a;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 HttpHandler::ParseGetQuery(a, "aaa&bb=aa&aa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ASSERT_EQ(3u, a.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ASSERT_EQ(a["aaa"], "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ASSERT_EQ(a["bb"], "aa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_EQ(a["aa"], "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 TEST(ParseGetQuery, Single)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 HttpHandler::Arguments a;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 HttpHandler::ParseGetQuery(a, "aaa=baaa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_EQ(1u, a.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 ASSERT_EQ(a["aaa"], "baaa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 TEST(ParseGetQuery, SingleEmpty)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 HttpHandler::Arguments a;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 HttpHandler::ParseGetQuery(a, "aaa");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_EQ(1u, a.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_EQ(a["aaa"], "");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 TEST(DicomFormat, Tag)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010)));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
123 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_EQ(0x0008, t.GetGroup());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_EQ(0x103E, t.GetElement());
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
126
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
127 t = FromDcmtkBridge::ParseTag("0020-e040");
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
128 ASSERT_EQ(0x0020, t.GetGroup());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
129 ASSERT_EQ(0xe040, t.GetElement());
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 559
diff changeset
130
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 559
diff changeset
131 // Test ==() and !=() operators
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 559
diff changeset
132 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 559
diff changeset
133 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 TEST(Uri, SplitUriComponents)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 UriComponents c;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 Toolbox::SplitUriComponents(c, "/cou/hello/world");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 ASSERT_EQ(3u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 ASSERT_EQ("cou", c[0]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ASSERT_EQ("hello", c[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_EQ("world", c[2]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 Toolbox::SplitUriComponents(c, "/cou/hello/world/");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ASSERT_EQ(3u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ASSERT_EQ("cou", c[0]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ("hello", c[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ("world", c[2]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 Toolbox::SplitUriComponents(c, "/cou/hello/world/a");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 ASSERT_EQ(4u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 ASSERT_EQ("cou", c[0]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_EQ("hello", c[1]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_EQ("world", c[2]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ASSERT_EQ("a", c[3]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 Toolbox::SplitUriComponents(c, "/");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(0u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 Toolbox::SplitUriComponents(c, "/hello");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 ASSERT_EQ(1u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 ASSERT_EQ("hello", c[0]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 Toolbox::SplitUriComponents(c, "/hello/");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ASSERT_EQ(1u, c.size());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ASSERT_EQ("hello", c[0]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
170 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException);
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
171 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException);
207
7f74209ea0f8 RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 177
diff changeset
172 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 TEST(Uri, Child)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 UriComponents c5; Toolbox::SplitUriComponents(c5, "/");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 TEST(Uri, AutodetectMimeType)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ASSERT_EQ("", Toolbox::AutodetectMimeType("../NOTES"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ASSERT_EQ("", Toolbox::AutodetectMimeType(""));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 ASSERT_EQ("", Toolbox::AutodetectMimeType("/"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 ASSERT_EQ("", Toolbox::AutodetectMimeType("a/a"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../NOTES.txt"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../coucou.xml/NOTES.txt"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("../.xml"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 ASSERT_EQ("application/javascript", Toolbox::AutodetectMimeType("NOTES.js"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 ASSERT_EQ("application/json", Toolbox::AutodetectMimeType("NOTES.json"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 ASSERT_EQ("application/pdf", Toolbox::AutodetectMimeType("NOTES.pdf"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 ASSERT_EQ("text/css", Toolbox::AutodetectMimeType("NOTES.css"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 ASSERT_EQ("text/html", Toolbox::AutodetectMimeType("NOTES.html"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("NOTES.txt"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("NOTES.xml"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 ASSERT_EQ("image/gif", Toolbox::AutodetectMimeType("NOTES.gif"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpg"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpeg"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 ASSERT_EQ("image/png", Toolbox::AutodetectMimeType("NOTES.png"));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
22
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
239 TEST(Toolbox, ComputeMD5)
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
240 {
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
241 std::string s;
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
242
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
243 // # echo -n "Hello" | md5sum
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
244
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
245 Toolbox::ComputeMD5(s, "Hello");
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
246 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s);
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
247 Toolbox::ComputeMD5(s, "");
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
248 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s);
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
249 }
1bc6327d1de3 MD5 sum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
250
177
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
251 TEST(Toolbox, ComputeSHA1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
252 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
253 std::string s;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
254
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
255 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
256 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
257 Toolbox::ComputeSHA1(s, "");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
258 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
259 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
260
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
261
24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
262 TEST(Toolbox, Base64)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
263 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
264 ASSERT_EQ("", Toolbox::EncodeBase64(""));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
265 ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a"));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
266 ASSERT_EQ("SGVsbG8gd29ybGQ=", Toolbox::EncodeBase64("Hello world"));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
267 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
268
87
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
269 TEST(Toolbox, PathToExecutable)
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
270 {
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
271 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str());
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
272 printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str());
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
273 }
8517e2c44283 path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 63
diff changeset
274
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
275 TEST(Toolbox, StripSpaces)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
276 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
277 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n "));
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
278 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n "));
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
279 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n "));
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
280 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n "));
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 235
diff changeset
281 }
100
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
282
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
283
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
284 #include <glog/logging.h>
100
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
285
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
286 TEST(Logger, Basic)
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
287 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
288 LOG(INFO) << "I say hello";
100
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
289 }
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
290
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
291 TEST(Toolbox, ConvertFromLatin1)
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
292 {
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
293 // This is a Latin-1 test string
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
294 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 };
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
295
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
296 /*FILE* f = fopen("/tmp/tutu", "w");
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
297 fwrite(&data[0], 9, 1, f);
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
298 fclose(f);*/
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
299
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
300 std::string s((char*) &data[0], 10);
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
301 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
302
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
303 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C"
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
304 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1");
235
1e0595885a81 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
305 ASSERT_EQ(15u, utf8.size());
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
306 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
307 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
308 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
309 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
310 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
311 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
312 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
313 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
314 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
315 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
316 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
317 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
318 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
319 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13]));
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
320 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
321 }
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
322
336
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
323 TEST(Toolbox, UrlDecode)
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
324 {
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
325 std::string s;
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
326
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
327 s = "Hello%20World";
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
328 Toolbox::UrlDecode(s);
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
329 ASSERT_EQ("Hello World", s);
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
330
337
26218c4de7e0 test added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
331 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff";
336
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
332 Toolbox::UrlDecode(s);
337
26218c4de7e0 test added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
333 std::string ss = "!#$&'()*+,/:;=?@[]";
26218c4de7e0 test added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
334 ss.push_back((char) 144);
26218c4de7e0 test added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
335 ss.push_back((char) 255);
26218c4de7e0 test added
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 336
diff changeset
336 ASSERT_EQ(ss, s);
336
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
337
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
338 s = "(2000%2C00A4)+Other";
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
339 Toolbox::UrlDecode(s);
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
340 ASSERT_EQ("(2000,00A4) Other", s);
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
341 }
3c291753231f url decode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
342
100
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
343
429
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
344 #if defined(__linux)
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
345 TEST(OrthancInitialization, AbsoluteDirectory)
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
346 {
430
f746592d8301 unit testing
jodogne
parents: 429
diff changeset
347 ASSERT_EQ("/tmp/hello", InterpretRelativePath("/tmp", "hello"));
f746592d8301 unit testing
jodogne
parents: 429
diff changeset
348 ASSERT_EQ("/tmp", InterpretRelativePath("/tmp", "/tmp"));
429
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
349 }
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
350 #endif
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
351
09b3c6265a94 unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 402
diff changeset
352
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
353
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
354 #include "../OrthancServer/ServerEnumerations.h"
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
355
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
356 TEST(EnumerationDictionary, Simple)
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
357 {
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
358 Toolbox::EnumerationDictionary<MetadataType> d;
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
359
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
360 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException);
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
361 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5"));
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 435
diff changeset
362 ASSERT_EQ(256, d.Translate("256"));
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
363
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
364 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate");
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
365
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
366 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate"));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
367 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2"));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
368 ASSERT_EQ("ReceptionDate", d.Translate(MetadataType_Instance_ReceptionDate));
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
369
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
370 ASSERT_THROW(d.Add(MetadataType_Instance_ReceptionDate, "Hello"), OrthancException);
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
371 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "ReceptionDate"), OrthancException); // already used
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
372 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "1024"), OrthancException); // cannot register numbers
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
373 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
374 }
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
375
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
376
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
377 TEST(EnumerationDictionary, ServerEnumerations)
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
378 {
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
379 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
380 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
381 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
382 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
383
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
384 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
385
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
386 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
387 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success));
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
388
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
389 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries));
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
390
437
beca6747945e PUT on metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
391 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries));
beca6747945e PUT on metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
392 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate));
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
393
559
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
394 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT"));
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
395 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy"));
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
396 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs"));
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
397 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance"));
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
398 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE"));
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
399 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException);
e0cfb413c86b find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 533
diff changeset
400
435
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
401 ASSERT_EQ(2047, StringToMetadata("2047"));
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
402 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException);
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
403 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024)
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
404 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535)
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
405 RegisterUserMetadata(2047, "Ceci est un test");
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
406 ASSERT_EQ(2047, StringToMetadata("2047"));
28ba73274919 registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
407 ASSERT_EQ(2047, StringToMetadata("Ceci est un test"));
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
408 }
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
409
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 430
diff changeset
410
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
411
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
412 class DynamicInteger : public IDynamicObject
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
413 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
414 private:
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
415 int value_;
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
416
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
417 public:
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
418 DynamicInteger(int value) : value_(value)
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
419 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
420 }
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
421
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
422 int GetValue() const
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
423 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
424 return value_;
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
425 }
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
426 };
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
427
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
428
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
429 TEST(SharedMessageQueue, Basic)
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
430 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
431 SharedMessageQueue q;
452
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
432 ASSERT_TRUE(q.WaitEmpty(0));
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
433 q.Enqueue(new DynamicInteger(10));
452
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
434 ASSERT_FALSE(q.WaitEmpty(1));
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
435 q.Enqueue(new DynamicInteger(20));
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
436 q.Enqueue(new DynamicInteger(30));
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
437 q.Enqueue(new DynamicInteger(40));
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
438
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
439 std::auto_ptr<DynamicInteger> i;
452
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
440 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue());
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
441 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue());
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
442 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue());
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
443 ASSERT_FALSE(q.WaitEmpty(1));
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
444 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue());
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
445 ASSERT_TRUE(q.WaitEmpty(0));
80f7539147a2 WaitEmpty
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 450
diff changeset
446 ASSERT_EQ(NULL, q.Dequeue(1));
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
447 }
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
448
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
449
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
450 TEST(SharedMessageQueue, Clean)
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
451 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
452 try
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
453 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
454 SharedMessageQueue q;
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
455 q.Enqueue(new DynamicInteger(10));
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
456 q.Enqueue(new DynamicInteger(20));
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
457 throw OrthancException("Nope");
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
458 }
533
09b836088f63 eclipse warning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 483
diff changeset
459 catch (OrthancException&)
450
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
460 {
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
461 }
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
462 }
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
463
58b433bb9762 SharedMessageQueue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 437
diff changeset
464
483
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
465 TEST(Toolbox, WriteFile)
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
466 {
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
467 std::string path;
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
468
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
469 {
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
470 Toolbox::TemporaryFile tmp;
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
471 path = tmp.GetPath();
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
472
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
473 std::string s;
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
474 s.append("Hello");
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
475 s.push_back('\0');
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
476 s.append("World");
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
477 ASSERT_EQ(11u, s.size());
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
478
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
479 Toolbox::WriteFile(s, path.c_str());
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
480
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
481 std::string t;
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
482 Toolbox::ReadFile(t, path.c_str());
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
483
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
484 ASSERT_EQ(11u, t.size());
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
485 ASSERT_EQ(0, t[5]);
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
486 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
487 }
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
488
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
489 std::string u;
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
490 ASSERT_THROW(Toolbox::ReadFile(u, path.c_str()), OrthancException);
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
491 }
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
492
8c3573d28868 export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
493
608
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
494 TEST(Toolbox, Wildcard)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
495 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
496 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd"));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
497 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd"));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
498 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd"));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
499 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d"));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
500 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]"));
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
501 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
502
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
503
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
504 TEST(Toolbox, Tokenize)
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
505 {
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
506 std::vector<std::string> t;
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
507
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
508 Toolbox::TokenizeString(t, "", ',');
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
509 ASSERT_EQ(1, t.size());
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
510 ASSERT_EQ("", t[0]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
511
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
512 Toolbox::TokenizeString(t, "abc", ',');
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
513 ASSERT_EQ(1, t.size());
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
514 ASSERT_EQ("abc", t[0]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
515
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
516 Toolbox::TokenizeString(t, "ab,cd,ef,", ',');
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
517 ASSERT_EQ(4, t.size());
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
518 ASSERT_EQ("ab", t[0]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
519 ASSERT_EQ("cd", t[1]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
520 ASSERT_EQ("ef", t[2]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
521 ASSERT_EQ("", t[3]);
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
522 }
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
523
0bedf8ff9288 basic find scp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 567
diff changeset
524
637
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
525 TEST(Toolbox, Endianness)
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
526 {
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
527 #if defined(__powerpc__) || defined(__powerpc64__)
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
528 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
529 #endif
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
530
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
531 #if defined(_WIN32)
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
532 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
533 #endif
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
534
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
535 #if defined(__amd64__) || defined(__i386__)
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
536 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
537 #endif
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
538 }
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
539
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
540
900274ed996f test endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
541
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 int main(int argc, char **argv)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
544 // Initialize Google's logging library.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
545 FLAGS_logtostderr = true;
137
0e97abc7b950 fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 107
diff changeset
546 FLAGS_minloglevel = 0;
159
c08fbad40ddd less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
547
c08fbad40ddd less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
548 // Go to trace-level verbosity
c08fbad40ddd less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
549 //FLAGS_v = 1;
c08fbad40ddd less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
550
453
30086c1aca30 endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 452
diff changeset
551 Toolbox::DetectEndianness();
30086c1aca30 endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 452
diff changeset
552
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
553 google::InitGoogleLogging("Orthanc");
100
27dc762e3dc8 getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
554
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
555 OrthancInitialize();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 ::testing::InitGoogleTest(&argc, argv);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 int result = RUN_ALL_TESTS();
63
f1d0470ff334 renaming unittests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
558 OrthancFinalize();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 return result;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }