changeset 1680:03afa09cfcf1

running the tests of the Orthanc Framework in WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2020 16:39:54 +0100
parents 5b8b88e5bfd6
children f2e8b3ac1dcd
files Applications/Resources/RunCppCheck.sh Applications/Samples/Common/RtViewerView.cpp Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp UnitTestsSources/GenericToolboxTests.cpp UnitTestsSources/UnitTestsMain.cpp UnitTestsSources/WebAssembly/CMakeLists.txt UnitTestsSources/WebAssembly/NOTES.txt UnitTestsSources/WebAssembly/index.html
diffstat 8 files changed, 49 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Resources/RunCppCheck.sh	Tue Nov 24 12:59:10 2020 +0100
+++ b/Applications/Resources/RunCppCheck.sh	Tue Nov 24 16:39:54 2020 +0100
@@ -29,7 +29,7 @@
 
 cat <<EOF > /tmp/cppcheck-suppressions.txt
 stlFindInsert:../../Applications/Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApplication.h
-stlFindInsert:../../Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp:703
+stlFindInsert:../../Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp:827
 unpreciseMathCall:../../OrthancStone/Sources/Scene2D/Internals/CairoFloatTextureRenderer.cpp
 unpreciseMathCall:../../OrthancStone/Sources/Scene2D/LookupTableTextureSceneLayer.cpp
 unreadVariable:../../OrthancStone/Sources/Viewport/SdlViewport.cpp:143
--- a/Applications/Samples/Common/RtViewerView.cpp	Tue Nov 24 12:59:10 2020 +0100
+++ b/Applications/Samples/Common/RtViewerView.cpp	Tue Nov 24 16:39:54 2020 +0100
@@ -319,7 +319,7 @@
   {
     std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
     ViewportController& controller = lock->GetController();
-    Scene2D& scene = controller.GetScene();
+    const Scene2D& scene = controller.GetScene();
     int depth = scene.GetMaxDepth() + 1;
 
     ctVolumeLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume));
@@ -337,7 +337,7 @@
   {
     std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
     ViewportController& controller = lock->GetController();
-    Scene2D& scene = controller.GetScene();
+    const Scene2D& scene = controller.GetScene();
     int depth = scene.GetMaxDepth() + 1;
 
     doseVolumeLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume));
@@ -352,7 +352,7 @@
   {
     std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
     ViewportController& controller = lock->GetController();
-    Scene2D& scene = controller.GetScene();
+    const Scene2D& scene = controller.GetScene();
     int depth = scene.GetMaxDepth() + 1;
 
     structLayerSource_.reset(new VolumeSceneLayerSource(viewport_, depth, volume));
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Nov 24 12:59:10 2020 +0100
+++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp	Tue Nov 24 16:39:54 2020 +0100
@@ -1466,16 +1466,16 @@
   void SetupPrefetchAfterRendering(const Orthanc::ImageAccessor& frame,
                                    DisplayedFrameQuality quality)
   {
-    const size_t frameSize = frame.GetPitch() * frame.GetHeight();
     const size_t cursorIndex = cursor_->GetCurrentIndex();
 
     // Prepare prefetching
     prefetchQueue_.clear();
 
-    size_t prefetchedSize = 0;
-    
     if (1)  // DISABLE PREFETCHING
     {
+      const size_t frameSize = frame.GetPitch() * frame.GetHeight();
+      size_t prefetchedSize = 0;
+    
       for (size_t i = 0; i < cursor_->GetPrefetchSize() && i < 16 &&
              prefetchedSize <= framesCache_->GetMaximumSize() / 2; i++)
       {
@@ -1492,8 +1492,7 @@
     
     if (observer_.get() != NULL)
     {
-      observer_->SignalFrameUpdated(*this, cursor_->GetCurrentIndex(),
-                                    frames_->GetFramesCount(), quality);
+      observer_->SignalFrameUpdated(*this, cursorIndex, frames_->GetFramesCount(), quality);
     }
   }
   
@@ -1974,8 +1973,6 @@
 
   void Redraw()
   {
-    DisplayedFrameQuality quality = DisplayedFrameQuality_None;
-    
     if (cursor_.get() != NULL &&
         frames_.get() != NULL)
     {
--- a/UnitTestsSources/GenericToolboxTests.cpp	Tue Nov 24 12:59:10 2020 +0100
+++ b/UnitTestsSources/GenericToolboxTests.cpp	Tue Nov 24 16:39:54 2020 +0100
@@ -26,9 +26,14 @@
 
 #include <gtest/gtest.h>
 #include <stdint.h>
-#include <inttypes.h>  // For PRId64
 #include <cmath>
 
+#if __cplusplus >= 201103L   // Is C++11?
+#  include <cinttypes>  // For PRId64
+#else
+#  define PRId64 "%lld"
+#endif
+
 TEST(GenericToolbox, TestLegitDoubleString)
 {
   using OrthancStone::GenericToolbox::LegitDoubleString;
--- a/UnitTestsSources/UnitTestsMain.cpp	Tue Nov 24 12:59:10 2020 +0100
+++ b/UnitTestsSources/UnitTestsMain.cpp	Tue Nov 24 16:39:54 2020 +0100
@@ -64,7 +64,7 @@
   int result;
 
   {
-    Orthanc::Logging::Initialize();
+    OrthancStone::StoneInitialize();
     Orthanc::Logging::EnableInfoLevel(true);
 
     ::testing::InitGoogleTest(&argc, argv);
@@ -75,16 +75,17 @@
   
     result = RUN_ALL_TESTS();
 
-    Orthanc::Logging::Finalize();
-
 #if defined(__EMSCRIPTEN__)
     output = testing::internal::GetCapturedStdout();
 #endif
+
+    OrthancStone::StoneFinalize();
   }
 
 #if defined(__EMSCRIPTEN__)
   EM_ASM({
       document.getElementById("output").innerHTML = UTF8ToString($0);
+      window.scrollTo(0, document.body.scrollHeight); // Scroll to the end of the page
     },
     output.c_str());
 #endif
--- a/UnitTestsSources/WebAssembly/CMakeLists.txt	Tue Nov 24 12:59:10 2020 +0100
+++ b/UnitTestsSources/WebAssembly/CMakeLists.txt	Tue Nov 24 16:39:54 2020 +0100
@@ -49,14 +49,13 @@
 
 include(${CMAKE_SOURCE_DIR}/../../Applications/Platforms/WebAssembly/OrthancStoneWebAssemblyParameters.cmake)
 
-SET(ENABLE_DCMTK OFF)  # Not necessary
+SET(ENABLE_DCMTK ON)  # Necessary for the tests of the Orthanc framework
+SET(ENABLE_PUGIXML ON)  # Necessary for the tests of the Orthanc framework
 SET(ENABLE_GOOGLE_TEST OFF)
 SET(ENABLE_LOCALE ON)  # Necessary for text rendering
+SET(ENABLE_LUA ON)  # Necessary for the tests of the Orthanc framework
 SET(ORTHANC_SANDBOXED ON)
 
-# Needed to redirect std::cout to a <div>
-set(ORTHANC_ENABLE_LOGGING_STDIO OFF CACHE INTERNAL "")
-
 # this will set up the build system for Stone of Orthanc and will
 # populate the ORTHANC_STONE_SOURCES CMake variable
 include(${CMAKE_SOURCE_DIR}/../../Applications/Platforms/WebAssembly/OrthancStoneWebAssemblyConfiguration.cmake)
@@ -75,7 +74,32 @@
 
 
 include(${CMAKE_SOURCE_DIR}/../UnitTestsSources.cmake)
-add_executable(UnitTests ${UNIT_TESTS_SOURCES})
+add_executable(UnitTests
+  # Testing Stone
+  ${UNIT_TESTS_SOURCES}
+
+  # Testing the Orthanc Framework
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/DicomMapTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/FrameworkTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/FromDcmtkTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/ImageProcessingTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/ImageTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/JpegLosslessTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/LoggingTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/LuaTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/RestApiTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/StreamTests.cpp
+  ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/ToolboxTests.cpp
+
+  # Tests that are not compatible with WebAssembly
+
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/FileStorageTests.cpp
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/JobsTests.cpp
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/MemoryCacheTests.cpp
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/SQLiteChromiumTests.cpp
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/SQLiteTests.cpp
+  # ${ORTHANC_FRAMEWORK_ROOT}/../UnitTestsSources/ZipTests.cpp
+  )
 
   
 # Declare installation files for the module
--- a/UnitTestsSources/WebAssembly/NOTES.txt	Tue Nov 24 12:59:10 2020 +0100
+++ b/UnitTestsSources/WebAssembly/NOTES.txt	Tue Nov 24 16:39:54 2020 +0100
@@ -8,7 +8,7 @@
 
 # source ~/Downloads/emsdk/emsdk_env.sh
 # mkdir Build && cd Build
-# cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DALLOW_DOWNLOADS=ON -G Ninja
+# cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DALLOW_DOWNLOADS=ON -G Ninja
 # ninja install
 
 => The binaries will be put in "../../../wasm-binaries/UnitTests/"
--- a/UnitTestsSources/WebAssembly/index.html	Tue Nov 24 12:59:10 2020 +0100
+++ b/UnitTestsSources/WebAssembly/index.html	Tue Nov 24 16:39:54 2020 +0100
@@ -7,7 +7,7 @@
   <body>
     <h1>Stone of Orthanc - Unit tests</h1>
     <pre id="output">
-      Executing the tests...
+      Running the tests...
     </pre>
     <script src="UnitTests.js" async></script>
   </body>