comparison UnitTestsSources/PluginsTests.cpp @ 886:29087d728e0a plugins

plugin sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 14 Jun 2014 18:50:14 +0200
parents 0570a8c859cb
children 4066e6f2d134
comparison
equal deleted inserted replaced
885:0570a8c859cb 886:29087d728e0a
31 31
32 32
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>
37
36 #include "../Plugins/Engine/SharedLibrary.h" 38 #include "../Plugins/Engine/SharedLibrary.h"
39 #include "../Plugins/OrthancCPlugin/OrthancCPlugin.h"
37 40
38 using namespace Orthanc; 41 using namespace Orthanc;
39 42
40 TEST(SharedLibrary, Basic) 43 TEST(SharedLibrary, Basic)
41 { 44 {
52 #else 55 #else
53 #error Support your platform here 56 #error Support your platform here
54 #endif 57 #endif
55 58
56 } 59 }
60
61
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)
87 {
88 #if defined(_WIN32)
89 #error Support your platform here
90
91 #elif defined(__linux)
92 SharedLibrary l("./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
126 #else
127 #error Support your platform here
128 #endif
129
130 }