comparison UnitTestsSources/UnitTestsMain.cpp @ 948:e57e08ed510f dicom-rt

integration mainline -> dicom-rt
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Jun 2014 13:57:05 +0200
parents 8cfc6119a5bd 27d256e0b458
children 98d6ba37c7dc
comparison
equal deleted inserted replaced
767:c19552f604d5 948:e57e08ed510f
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
4 * Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * In addition, as a special exception, the copyright holders of this
12 * program give permission to link the code of its release with the
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
14 * that use the same license as the "OpenSSL" library), and distribute
15 * the linked executables. You must obey the GNU General Public License
16 * in all respects for all of the code used other than "OpenSSL". If you
17 * modify file(s) with this exception, you may extend this exception to
18 * your version of the file(s), but you are not obligated to do so. If
19 * you do not wish to do so, delete this exception statement from your
20 * version. If you delete this exception statement from all source files
21 * in the program, then also delete it here.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/
31
32
33 #include "PrecompiledHeadersUnitTests.h"
1 #include "../Core/EnumerationDictionary.h" 34 #include "../Core/EnumerationDictionary.h"
2 35
3 #include "gtest/gtest.h" 36 #include "gtest/gtest.h"
4 37
5 #include <ctype.h> 38 #include <ctype.h>
8 #include "../Core/DicomFormat/DicomTag.h" 41 #include "../Core/DicomFormat/DicomTag.h"
9 #include "../Core/HttpServer/HttpHandler.h" 42 #include "../Core/HttpServer/HttpHandler.h"
10 #include "../Core/OrthancException.h" 43 #include "../Core/OrthancException.h"
11 #include "../Core/Toolbox.h" 44 #include "../Core/Toolbox.h"
12 #include "../Core/Uuid.h" 45 #include "../Core/Uuid.h"
13 #include "../OrthancServer/FromDcmtkBridge.h"
14 #include "../OrthancServer/OrthancInitialization.h" 46 #include "../OrthancServer/OrthancInitialization.h"
15 47
16 using namespace Orthanc; 48 using namespace Orthanc;
17 49
18 50
175 HttpHandler::Arguments a; 207 HttpHandler::Arguments a;
176 HttpHandler::ParseGetQuery(a, "aaa"); 208 HttpHandler::ParseGetQuery(a, "aaa");
177 ASSERT_EQ(1u, a.size()); 209 ASSERT_EQ(1u, a.size());
178 ASSERT_EQ(a["aaa"], ""); 210 ASSERT_EQ(a["aaa"], "");
179 } 211 }
180
181 TEST(DicomFormat, Tag)
182 {
183 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010)));
184
185 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription");
186 ASSERT_EQ(0x0008, t.GetGroup());
187 ASSERT_EQ(0x103E, t.GetElement());
188
189 t = FromDcmtkBridge::ParseTag("0020-e040");
190 ASSERT_EQ(0x0020, t.GetGroup());
191 ASSERT_EQ(0xe040, t.GetElement());
192
193 // Test ==() and !=() operators
194 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020));
195 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020));
196 }
197
198 212
199 TEST(Uri, SplitUriComponents) 213 TEST(Uri, SplitUriComponents)
200 { 214 {
201 UriComponents c; 215 UriComponents c;
202 Toolbox::SplitUriComponents(c, "/cou/hello/world"); 216 Toolbox::SplitUriComponents(c, "/cou/hello/world");
323 Toolbox::ComputeSHA1(s, ""); 337 Toolbox::ComputeSHA1(s, "");
324 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); 338 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s);
325 } 339 }
326 340
327 341
342 static std::string EncodeBase64Bis(const std::string& s)
343 {
344 std::string result;
345 Toolbox::EncodeBase64(result, s);
346 return result;
347 }
348
349
328 TEST(Toolbox, Base64) 350 TEST(Toolbox, Base64)
329 { 351 {
330 ASSERT_EQ("", Toolbox::EncodeBase64("")); 352 ASSERT_EQ("", EncodeBase64Bis(""));
331 ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a")); 353 ASSERT_EQ("YQ==", EncodeBase64Bis("a"));
332 354
333 const std::string hello = "SGVsbG8gd29ybGQ="; 355 const std::string hello = "SGVsbG8gd29ybGQ=";
334 ASSERT_EQ(hello, Toolbox::EncodeBase64("Hello world")); 356 ASSERT_EQ(hello, EncodeBase64Bis("Hello world"));
335 ASSERT_EQ("Hello world", Toolbox::DecodeBase64(hello)); 357
358 std::string decoded;
359 Toolbox::DecodeBase64(decoded, hello);
360 ASSERT_EQ("Hello world", decoded);
336 } 361 }
337 362
338 TEST(Toolbox, PathToExecutable) 363 TEST(Toolbox, PathToExecutable)
339 { 364 {
340 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); 365 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str());
430 455
431 456
432 #if defined(__linux) 457 #if defined(__linux)
433 TEST(OrthancInitialization, AbsoluteDirectory) 458 TEST(OrthancInitialization, AbsoluteDirectory)
434 { 459 {
435 ASSERT_EQ("/tmp/hello", InterpretRelativePath("/tmp", "hello")); 460 ASSERT_EQ("/tmp/hello", Configuration::InterpretRelativePath("/tmp", "hello"));
436 ASSERT_EQ("/tmp", InterpretRelativePath("/tmp", "/tmp")); 461 ASSERT_EQ("/tmp", Configuration::InterpretRelativePath("/tmp", "/tmp"));
437 } 462 }
438 #endif 463 #endif
439 464
440 465
441 466
602 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 627 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5
603 628
604 #if defined(_WIN32) 629 #if defined(_WIN32)
605 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); 630 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
606 631
607 #elif defined(__linux) 632 #elif defined(__APPLE__)
633 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
634
635 #elif defined(__linux) || defined(__FreeBSD_kernel__)
608 636
609 #if !defined(__BYTE_ORDER) 637 #if !defined(__BYTE_ORDER)
610 # error Support your platform here 638 # error Support your platform here
611 #endif 639 #endif
612 640
620 #error Support your platform here 648 #error Support your platform here
621 #endif 649 #endif
622 } 650 }
623 651
624 652
625
626 int main(int argc, char **argv) 653 int main(int argc, char **argv)
627 { 654 {
628 // Initialize Google's logging library. 655 // Initialize Google's logging library.
629 FLAGS_logtostderr = true; 656 FLAGS_logtostderr = true;
630 FLAGS_minloglevel = 0; 657 FLAGS_minloglevel = 0;
633 //FLAGS_v = 1; 660 //FLAGS_v = 1;
634 661
635 Toolbox::DetectEndianness(); 662 Toolbox::DetectEndianness();
636 663
637 google::InitGoogleLogging("Orthanc"); 664 google::InitGoogleLogging("Orthanc");
665
666 Toolbox::CreateDirectory("UnitTestsResults");
638 667
639 OrthancInitialize(); 668 OrthancInitialize();
640 ::testing::InitGoogleTest(&argc, argv); 669 ::testing::InitGoogleTest(&argc, argv);
641 int result = RUN_ALL_TESTS(); 670 int result = RUN_ALL_TESTS();
642 OrthancFinalize(); 671 OrthancFinalize();