changeset 9:1fb480a156fd

build unit tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jun 2015 11:07:20 +0200
parents 6d59828e2662
children f45ded9a9934
files CMakeLists.txt Orthanc/Resources/CMake/Compiler.cmake Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Orthanc/Resources/CMake/JsonCppConfiguration.cmake Resources/SyncOrthancFolder.py UnitTestsSources/MultiThreadingTests.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 7 files changed, 116 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Jun 02 10:55:32 2015 +0200
+++ b/CMakeLists.txt	Tue Jun 02 11:07:20 2015 +0200
@@ -7,6 +7,7 @@
 
 # Parameters of the build
 SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
+SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
 
 # Advanced parameters to fine-tune linking against system libraries
 SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost")
@@ -29,9 +30,10 @@
 include(Orthanc/Resources/CMake/Compiler.cmake)
 
 include(Orthanc/Resources/CMake/BoostConfiguration.cmake)
+include(Orthanc/Resources/CMake/GoogleTestConfiguration.cmake)
 include(Orthanc/Resources/CMake/JsonCppConfiguration.cmake)
+include(Orthanc/Resources/CMake/LibCurlConfiguration.cmake)
 include(Orthanc/Resources/CMake/LibPngConfiguration.cmake)
-include(Orthanc/Resources/CMake/LibCurlConfiguration.cmake)
 include(Orthanc/Resources/CMake/OpenSslConfiguration.cmake)
 include(Orthanc/Resources/CMake/ZlibConfiguration.cmake)
 
@@ -50,9 +52,9 @@
     set(CMAKE_SHARED_LIBRARY_PREFIX "")
 
     if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
-      set(ORTHANC_CPP_CLIENT_AUX CppClient/SharedLibrary/AUTOGENERATED/Windows32.def)
+      set(ORTHANC_CPP_CLIENT_AUX SharedLibrary/AUTOGENERATED/Windows32.def)
     elseif (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
-      set(ORTHANC_CPP_CLIENT_AUX CppClient/SharedLibrary/AUTOGENERATED/Windows64.def)
+      set(ORTHANC_CPP_CLIENT_AUX SharedLibrary/AUTOGENERATED/Windows64.def)
     else()
       message(FATAL_ERROR "Support your platform here")
     endif()
@@ -62,10 +64,10 @@
 
   if (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
     set(CMAKE_SHARED_LIBRARY_SUFFIX "_Windows32.dll")
-    list(APPEND ORTHANC_CPP_CLIENT_AUX CppClient/SharedLibrary/AUTOGENERATED/Windows32.rc)
+    list(APPEND ORTHANC_CPP_CLIENT_AUX SharedLibrary/AUTOGENERATED/Windows32.rc)
   elseif (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
     set(CMAKE_SHARED_LIBRARY_SUFFIX "_Windows64.dll")
-    list(APPEND ORTHANC_CPP_CLIENT_AUX CppClient/SharedLibrary/AUTOGENERATED/Windows64.rc)
+    list(APPEND ORTHANC_CPP_CLIENT_AUX SharedLibrary/AUTOGENERATED/Windows64.rc)
   else()
     message(FATAL_ERROR "Support your platform here")
   endif()    
@@ -104,6 +106,18 @@
   )
 
 
+add_executable(UnitTests
+  CppClient/ArrayFilledByThreads.cpp
+  CppClient/ThreadedCommandProcessor.cpp
+  Orthanc/Core/MultiThreading/SharedMessageQueue.cpp
+  UnitTestsSources/MultiThreadingTests.cpp
+  UnitTestsSources/UnitTestsMain.cpp
+
+  ${THIRD_PARTY_SOURCES}
+  ${GTEST_SOURCES}
+  )
+
+
 list(LENGTH OPENSSL_SOURCES OPENSSL_SOURCES_LENGTH)
 if (${OPENSSL_SOURCES_LENGTH} GREATER 0)
   add_library(OpenSSL STATIC ${OPENSSL_SOURCES})
@@ -161,7 +175,7 @@
 
 install(
   FILES
-  CppClient/SharedLibrary/AUTOGENERATED/CppClient.h 
+  SharedLibrary/AUTOGENERATED/CppClient.h 
   DESTINATION include/orthanc
   )
 
--- a/Orthanc/Resources/CMake/Compiler.cmake	Tue Jun 02 10:55:32 2015 +0200
+++ b/Orthanc/Resources/CMake/Compiler.cmake	Tue Jun 02 11:07:20 2015 +0200
@@ -101,7 +101,7 @@
 if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
   # In FreeBSD, the "/usr/local/" folder contains the ports and need to be imported
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
-  SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -I/usr/local/include/jsoncpp")
+  SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
   SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib")
 endif()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Orthanc/Resources/CMake/GoogleTestConfiguration.cmake	Tue Jun 02 11:07:20 2015 +0200
@@ -0,0 +1,39 @@
+if (USE_GTEST_DEBIAN_SOURCE_PACKAGE)
+  set(GTEST_SOURCES /usr/src/gtest/src/gtest-all.cc)
+  include_directories(/usr/src/gtest)
+
+  if (NOT EXISTS /usr/include/gtest/gtest.h OR
+      NOT EXISTS ${GTEST_SOURCES})
+    message(FATAL_ERROR "Please install the libgtest-dev package")
+  endif()
+
+elseif (STATIC_BUILD OR NOT USE_SYSTEM_GOOGLE_TEST)
+  set(GTEST_SOURCES_DIR ${CMAKE_BINARY_DIR}/gtest-1.7.0)
+  DownloadPackage(
+    "2d6ec8ccdf5c46b05ba54a9fd1d130d7"
+    "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/gtest-1.7.0.zip"
+    "${GTEST_SOURCES_DIR}")
+
+  include_directories(
+    ${GTEST_SOURCES_DIR}/include
+    ${GTEST_SOURCES_DIR}
+    )
+
+  set(GTEST_SOURCES
+    ${GTEST_SOURCES_DIR}/src/gtest-all.cc
+    )
+
+  # https://code.google.com/p/googletest/issues/detail?id=412
+  if (MSVC) # VS2012 does not support tuples correctly yet
+    add_definitions(/D _VARIADIC_MAX=10)
+  endif()
+
+else()
+  include(FindGTest)
+  if (NOT GTEST_FOUND)
+    message(FATAL_ERROR "Unable to find GoogleTest")
+  endif()
+
+  include_directories(${GTEST_INCLUDE_DIRS})
+  link_libraries(${GTEST_LIBRARIES})
+endif()
--- a/Orthanc/Resources/CMake/JsonCppConfiguration.cmake	Tue Jun 02 10:55:32 2015 +0200
+++ b/Orthanc/Resources/CMake/JsonCppConfiguration.cmake	Tue Jun 02 11:07:20 2015 +0200
@@ -18,11 +18,6 @@
   source_group(ThirdParty\\JsonCpp REGULAR_EXPRESSION ${JSONCPP_SOURCES_DIR}/.*)
 
 else()
-  CHECK_INCLUDE_FILE_CXX(jsoncpp/json/reader.h HAVE_JSONCPP_H)
-  if (NOT HAVE_JSONCPP_H)
-    message(FATAL_ERROR "Please install the libjsoncpp-dev package")
-  endif()
-
   find_path(JSONCPP_INCLUDE_DIR json/reader.h
     /usr/include/jsoncpp
     /usr/local/include/jsoncpp
@@ -32,4 +27,9 @@
   include_directories(${JSONCPP_INCLUDE_DIR})
   link_libraries(jsoncpp)
 
+  CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H)
+  if (NOT HAVE_JSONCPP_H)
+    message(FATAL_ERROR "Please install the libjsoncpp-dev package")
+  endif()
+
 endif()
--- a/Resources/SyncOrthancFolder.py	Tue Jun 02 10:55:32 2015 +0200
+++ b/Resources/SyncOrthancFolder.py	Tue Jun 02 11:07:20 2015 +0200
@@ -33,6 +33,7 @@
     'Resources/CMake/BoostConfiguration.cmake',
     'Resources/CMake/Compiler.cmake',
     'Resources/CMake/DownloadPackage.cmake',
+    'Resources/CMake/GoogleTestConfiguration.cmake',
     'Resources/CMake/JsonCppConfiguration.cmake',
     'Resources/CMake/LibCurlConfiguration.cmake',
     'Resources/CMake/LibPngConfiguration.cmake',
--- a/UnitTestsSources/MultiThreadingTests.cpp	Tue Jun 02 10:55:32 2015 +0200
+++ b/UnitTestsSources/MultiThreadingTests.cpp	Tue Jun 02 11:07:20 2015 +0200
@@ -30,15 +30,14 @@
  **/
 
 
-#include "../Core/MultiThreading/ThreadedCommandProcessor.h"
-#include "../Core/MultiThreading/ArrayFilledByThreads.h"
+#include "../CppClient/ThreadedCommandProcessor.h"
+#include "../CppClient/ArrayFilledByThreads.h"
 
-
-using namespace Orthanc;
+#include <gtest/gtest.h>
 
 namespace
 {
-  class DynamicInteger : public ICommand
+  class DynamicInteger : public Orthanc::ICommand
   {
   private:
     int value_;
@@ -64,7 +63,7 @@
     }
   };
 
-  class MyFiller : public ArrayFilledByThreads::IFiller
+  class MyFiller : public OrthancClient::ArrayFilledByThreads::IFiller
   {
   private:
     int size_;
@@ -81,7 +80,7 @@
       return size_;
     }
 
-    virtual IDynamicObject* GetFillerItem(size_t index)
+    virtual Orthanc::IDynamicObject* GetFillerItem(size_t index)
     {
       static boost::mutex mutex;
       boost::mutex::scoped_lock lock(mutex);
@@ -106,7 +105,7 @@
 TEST(MultiThreading, ArrayFilledByThreadEmpty)
 {
   MyFiller f(0);
-  ArrayFilledByThreads a(f);
+  OrthancClient::ArrayFilledByThreads a(f);
   a.SetThreadCount(1);
   ASSERT_EQ(0, a.GetSize());
 }
@@ -115,7 +114,7 @@
 TEST(MultiThreading, ArrayFilledByThread1)
 {
   MyFiller f(100);
-  ArrayFilledByThreads a(f);
+  OrthancClient::ArrayFilledByThreads a(f);
   a.SetThreadCount(1);
   ASSERT_EQ(100, a.GetSize());
   for (size_t i = 0; i < a.GetSize(); i++)
@@ -128,7 +127,7 @@
 TEST(MultiThreading, ArrayFilledByThread4)
 {
   MyFiller f(100);
-  ArrayFilledByThreads a(f);
+  OrthancClient::ArrayFilledByThreads a(f);
   a.SetThreadCount(4);
   ASSERT_EQ(100, a.GetSize());
   for (size_t i = 0; i < a.GetSize(); i++)
@@ -156,7 +155,7 @@
 
 TEST(MultiThreading, CommandProcessor)
 {
-  ThreadedCommandProcessor p(4);
+  OrthancClient::ThreadedCommandProcessor p(4);
 
   std::set<int> s;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UnitTestsSources/UnitTestsMain.cpp	Tue Jun 02 11:07:20 2015 +0200
@@ -0,0 +1,40 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv)
+{
+  ::testing::InitGoogleTest(&argc, argv);
+  int result = RUN_ALL_TESTS();
+  return result;
+}