summaryrefslogtreecommitdiffstats
path: root/Tests/Plugin/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-04-17 17:43:03 (GMT)
committerBrad King <brad.king@kitware.com>2007-04-17 17:43:03 (GMT)
commitaabcf981e22a7c39bcd828bff1a4fb4345e658c9 (patch)
tree1f166f92adf72e9008bff112099dbf1e5b61d7bf /Tests/Plugin/src
parentc50dabff029b4ea5cd639189d822e3fc76a9e719 (diff)
downloadCMake-aabcf981e22a7c39bcd828bff1a4fb4345e658c9.zip
CMake-aabcf981e22a7c39bcd828bff1a4fb4345e658c9.tar.gz
CMake-aabcf981e22a7c39bcd828bff1a4fb4345e658c9.tar.bz2
ENH: Added test for executables with plugins that use an API exported by the executable itself.
Diffstat (limited to 'Tests/Plugin/src')
-rw-r--r--Tests/Plugin/src/example_exe.cxx53
-rw-r--r--Tests/Plugin/src/example_mod_1.c16
2 files changed, 69 insertions, 0 deletions
diff --git a/Tests/Plugin/src/example_exe.cxx b/Tests/Plugin/src/example_exe.cxx
new file mode 100644
index 0000000..59f1e0b
--- /dev/null
+++ b/Tests/Plugin/src/example_exe.cxx
@@ -0,0 +1,53 @@
+#include <example.h>
+
+#include <kwsys/DynamicLoader.hxx>
+#include <kwsys/ios/iostream>
+#include <kwsys/stl/string>
+
+#include <stdio.h>
+
+// Implement the ABI used by plugins.
+extern "C" int example_exe_function()
+{
+ kwsys_ios::cout << "hello" << kwsys_ios::endl;
+ return 123;
+}
+
+#ifdef CMAKE_INTDIR
+# define CONFIG_DIR "/" CMAKE_INTDIR
+#else
+# define CONFIG_DIR ""
+#endif
+
+int main()
+{
+ kwsys_stl::string libName = "lib/plugin" CONFIG_DIR "/";
+ libName += kwsys::DynamicLoader::LibPrefix();
+ libName += "example_mod_1";
+ libName += kwsys::DynamicLoader::LibExtension();
+ kwsys::DynamicLoader::LibraryHandle handle =
+ kwsys::DynamicLoader::OpenLibrary(libName.c_str());
+ if(!handle)
+ {
+ kwsys_ios::cerr << "Could not open plugin \""
+ << libName << "\"!" << kwsys_ios::endl;
+ return 1;
+ }
+ kwsys::DynamicLoader::SymbolPointer sym =
+ kwsys::DynamicLoader::GetSymbolAddress(handle, "example_mod_1_function");
+ if(!sym)
+ {
+ kwsys_ios::cerr
+ << "Could not get plugin symbol \"example_mod_1_function\"!"
+ << kwsys_ios::endl;
+ return 1;
+ }
+ int(*f)() = reinterpret_cast<int(*)()>(sym);
+ if(f() != (123+456))
+ {
+ kwsys_ios::cerr << "Incorrect return value from plugin!"
+ << kwsys_ios::endl;
+ return 1;
+ }
+ return 0;
+}
diff --git a/Tests/Plugin/src/example_mod_1.c b/Tests/Plugin/src/example_mod_1.c
new file mode 100644
index 0000000..f96ba29
--- /dev/null
+++ b/Tests/Plugin/src/example_mod_1.c
@@ -0,0 +1,16 @@
+#include <example.h>
+
+#include <stdio.h>
+
+#if defined(_WIN32)
+# define MODULE_EXPORT __declspec(dllexport)
+#else
+# define MODULE_EXPORT
+#endif
+
+MODULE_EXPORT int example_mod_1_function()
+{
+ int result = example_exe_function() + 456;
+ printf("world\n");
+ return result;
+}