comparison UnitTestsSources/PluginsTests.cpp @ 887:4066e6f2d134 plugins

PluginsManager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 14 Jun 2014 19:20:38 +0200
parents 29087d728e0a
children d44b845c1c89
comparison
equal deleted inserted replaced
886:29087d728e0a 887:4066e6f2d134
33 #include "PrecompiledHeadersUnitTests.h" 33 #include "PrecompiledHeadersUnitTests.h"
34 #include "gtest/gtest.h" 34 #include "gtest/gtest.h"
35 35
36 #include <glog/logging.h> 36 #include <glog/logging.h>
37 37
38 #include "../Plugins/Engine/SharedLibrary.h" 38 #include "../Plugins/Engine/PluginsManager.h"
39 #include "../Plugins/OrthancCPlugin/OrthancCPlugin.h"
40 39
41 using namespace Orthanc; 40 using namespace Orthanc;
42 41
43 TEST(SharedLibrary, Basic) 42 TEST(SharedLibrary, Basic)
44 { 43 {
57 #endif 56 #endif
58 57
59 } 58 }
60 59
61 60
62
63 static void LogError(const char* str)
64 {
65 LOG(ERROR) << str;
66 }
67
68 static void LogWarning(const char* str)
69 {
70 LOG(WARNING) << str;
71 }
72
73 static void LogInfo(const char* str)
74 {
75 LOG(INFO) << str;
76 }
77
78 static int32_t InvokeService(const char* serviceName,
79 const void* serviceParameters)
80 {
81 return 0;
82 }
83
84
85
86 TEST(SharedLibrary, Development) 61 TEST(SharedLibrary, Development)
87 { 62 {
63 PluginsManager manager;
64
88 #if defined(_WIN32) 65 #if defined(_WIN32)
89 #error Support your platform here 66 #error Support your platform here
90 67
91 #elif defined(__linux) 68 #elif defined(__linux)
92 SharedLibrary l("./libPluginTest.so"); 69 manager.RegisterPlugin("./libPluginTest.so");
93 ASSERT_TRUE(l.HasFunction("OrthancPluginFinalize"));
94 ASSERT_TRUE(l.HasFunction("OrthancPluginInitialize"));
95
96 OrthancPluginContext context;
97 context.orthancVersion = ORTHANC_VERSION;
98 context.InvokeService = InvokeService;
99 context.LogError = LogError;
100 context.LogWarning = LogWarning;
101 context.LogInfo = LogInfo;
102
103 typedef void (*Finalize) ();
104 typedef int32_t (*Initialize) (const OrthancPluginContext*);
105
106 /**
107 * gcc would complain about "ISO C++ forbids casting between
108 * pointer-to-function and pointer-to-object" without the trick
109 * below, that is known as "the POSIX.1-2003 (Technical Corrigendum
110 * 1) workaround". See the man page of "dlsym()".
111 * http://www.trilithium.com/johan/2004/12/problem-with-dlsym/
112 * http://stackoverflow.com/a/14543811/881731
113 **/
114
115 Finalize finalize;
116 *(void **) (&finalize) = l.GetFunction("OrthancPluginFinalize");
117 assert(finalize != NULL);
118
119 Initialize initialize;
120 *(void **) (&initialize) = l.GetFunction("OrthancPluginInitialize");
121 assert(initialize != NULL);
122
123 initialize(&context);
124 finalize();
125 70
126 #else 71 #else
127 #error Support your platform here 72 #error Support your platform here
128 #endif 73 #endif
129
130 } 74 }