diff Framework/Plugins/IndexUnitTests.h @ 199:8cae98f73d53

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Mar 2021 14:52:06 +0100
parents 3236894320d6
children 30b210616f4f
line wrap: on
line diff
--- a/Framework/Plugins/IndexUnitTests.h	Thu Mar 18 12:24:28 2021 +0100
+++ b/Framework/Plugins/IndexUnitTests.h	Thu Mar 18 14:52:06 2021 +0100
@@ -98,44 +98,60 @@
                                             _OrthancPluginService service,
                                             const void* params)
 {
-  if (service == _OrthancPluginService_DatabaseAnswer)
+  switch (service)
   {
-    const _OrthancPluginDatabaseAnswer& answer = 
-      *reinterpret_cast<const _OrthancPluginDatabaseAnswer*>(params);
-
-    switch (answer.type)
+    case _OrthancPluginService_DatabaseAnswer:
     {
-      case _OrthancPluginDatabaseAnswerType_Attachment:
+      const _OrthancPluginDatabaseAnswer& answer = 
+        *reinterpret_cast<const _OrthancPluginDatabaseAnswer*>(params);
+
+      switch (answer.type)
       {
-        const OrthancPluginAttachment& attachment = 
-          *reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric);
-        CheckAttachment(attachment);
-        break;
+        case _OrthancPluginDatabaseAnswerType_Attachment:
+        {
+          const OrthancPluginAttachment& attachment = 
+            *reinterpret_cast<const OrthancPluginAttachment*>(answer.valueGeneric);
+          CheckAttachment(attachment);
+          break;
+        }
+
+        case _OrthancPluginDatabaseAnswerType_ExportedResource:
+        {
+          const OrthancPluginExportedResource& attachment = 
+            *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric);
+          CheckExportedResource(attachment);
+          break;
+        }
+
+        case _OrthancPluginDatabaseAnswerType_DicomTag:
+        {
+          const OrthancPluginDicomTag& tag = 
+            *reinterpret_cast<const OrthancPluginDicomTag*>(answer.valueGeneric);
+          CheckDicomTag(tag);
+          break;
+        }
+
+        default:
+          printf("Unhandled message: %d\n", answer.type);
+          break;
       }
 
-      case _OrthancPluginDatabaseAnswerType_ExportedResource:
-      {
-        const OrthancPluginExportedResource& attachment = 
-          *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric);
-        CheckExportedResource(attachment);
-        break;
-      }
+      return OrthancPluginErrorCode_Success;
+    }
 
-      case _OrthancPluginDatabaseAnswerType_DicomTag:
-      {
-        const OrthancPluginDicomTag& tag = 
-          *reinterpret_cast<const OrthancPluginDicomTag*>(answer.valueGeneric);
-        CheckDicomTag(tag);
-        break;
-      }
+    case _OrthancPluginService_GetExpectedDatabaseVersion:
+    {
+      const _OrthancPluginReturnSingleValue& p =
+        *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(params);
+      *(p.resultUint32) = ORTHANC_DATABASE_VERSION;
+      return OrthancPluginErrorCode_Success;
+    }
 
-      default:
-        printf("Unhandled message: %d\n", answer.type);
-        break;
-    }
+    default:
+      assert(0);
+      printf("Service not emulated: %d\n", service);
+      return OrthancPluginErrorCode_NotImplemented;
   }
-
-  return OrthancPluginErrorCode_Success;
 }
 
 
@@ -163,7 +179,7 @@
 #  error Unsupported database backend
 #endif
 
-  db.RegisterOutput(new OrthancPlugins::DatabaseBackendOutput(&context, NULL));
+  db.RegisterOutput(&context, new OrthancPlugins::DatabaseBackendOutput(&context, NULL));
   db.Open();