diff options
author | Alan Conway <aconway@apache.org> | 2007-07-04 03:24:48 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-07-04 03:24:48 +0000 |
commit | ae896d73d4914fa96f053a0443f6b05003c12b35 (patch) | |
tree | 0aac1abf592704282ab5860a0f69dcfd9610f2cd /cpp/src/tests | |
parent | 7865fcf6689f96219365995e8ad09b3332205176 (diff) | |
download | qpid-python-ae896d73d4914fa96f053a0443f6b05003c12b35.tar.gz |
2007-07-02 <aconway@redhat.com
* qpid/sys/Shlib.h, .cpp: Portable shared library abstraction.
- Shlib: load, unload, getSymbol
- AutoShlib: unload in destructor.
* qpid/sys/apr/Shlib.cpp sys/posix/Shlib.cpp: APR/Posix impls
* qpid/sys/Module.h: Reimplemented Module in terms of AutoShlib.
* qpid/Plugin.cpp, .h: Removed dlopen - use Shlib instead.
* qpid/broker/Broker.cpp: Added missing #include "qpid/log/Statement.h"
* tests/Shlib.cpp, shlibtest.cpp: Unit test
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@553056 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/Cluster.cpp | 10 | ||||
-rw-r--r-- | cpp/src/tests/Makefile.am | 41 | ||||
-rw-r--r-- | cpp/src/tests/Shlib.cpp | 56 | ||||
-rw-r--r-- | cpp/src/tests/shlibtest.cpp | 28 |
4 files changed, 116 insertions, 19 deletions
diff --git a/cpp/src/tests/Cluster.cpp b/cpp/src/tests/Cluster.cpp index 95cd607979..ccc1b52249 100644 --- a/cpp/src/tests/Cluster.cpp +++ b/cpp/src/tests/Cluster.cpp @@ -16,14 +16,18 @@ * */ -#define BOOST_AUTO_TEST_MAIN // Must come before #include<boost/test/*> -#include <boost/test/auto_unit_test.hpp> -#include "test_tools.h" #include "Cluster.h" +#include "test_tools.h" + #include "qpid/framing/ChannelPingBody.h" #include "qpid/framing/ChannelOkBody.h" #include "qpid/cluster/ClassifierHandler.h" +#define BOOST_AUTO_TEST_MAIN // Must come before #include<boost/test/*> +#include <boost/test/auto_unit_test.hpp> + +#include <sys/wait.h> + static const ProtocolVersion VER; using namespace qpid::log; diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 3adf8818db..76f821798d 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -11,6 +11,7 @@ lib_broker = $(abs_builddir)/../libqpidbroker.la # Initialize variables that are incremented with += # check_PROGRAMS= +check_LTLIBRARIES= TESTS= EXTRA_DIST= @@ -32,6 +33,15 @@ check_PROGRAMS+=Uuid Uuid_SOURCES=Uuid.cpp test_tools.h Uuid_LDADD=-lboost_unit_test_framework $(lib_common) +check_LTLIBRARIES += libshlibtest.la +libshlibtest_la_LDFLAGS = -module -rpath $(abs_builddir) +libshlibtest_la_SOURCES = shlibtest.cpp + +TESTS+=Shlib +check_PROGRAMS+=Shlib +Shlib_SOURCES=Shlib.cpp +Shlib_LDADD=-lboost_unit_test_framework $(lib_common) + include cluster.mk # NB: CppUnit test libraries below will be migrated to boost test programs. @@ -112,24 +122,23 @@ EXTRA_DIST += \ include gen.mk check_LTLIBRARIES += libdlclose_noop.la -libdlclose_noop_la_LDFLAGS = -module -rpath /home/aconway/svn/qpid/cpp/tests +libdlclose_noop_la_LDFLAGS = -module -rpath $(abs_builddir) libdlclose_noop_la_SOURCES = dlclose_noop.c gen.mk: Makefile.am - ( \ - for i in $(testprogs); do \ - echo $${i}_SOURCES = $$i.cpp; \ - echo $${i}_LDADD = '$$(lib_client) $$(lib_common) $$(extra_libs)'; \ - done; \ - libs=; \ - for i in $(unit_tests); do \ - libs="$$libs $${i}.la"; \ - echo $${i}_la_SOURCES = $$i.cpp; \ - echo $${i}_la_LIBADD = '$$(lib_common) $$(lib_client)'; \ - echo $${i}_la_LIBADD += '$$(lib_broker) $$(extra_libs)'; \ - echo $${i}_la_LDFLAGS = "-module -rpath `pwd`"; \ - done; \ - echo "check_LTLIBRARIES =$$libs"; \ + ( \ + for i in $(testprogs); do \ + echo $${i}_SOURCES = $$i.cpp; \ + echo $${i}_LDADD = '$$(lib_client) $$(lib_common) $$(extra_libs)'; \ + done; \ + libs=; \ + for i in $(unit_tests); do \ + echo "check_LTLIBRARIES +=$${i}.la"; \ + echo $${i}_la_SOURCES = $$i.cpp; \ + echo $${i}_la_LIBADD = '$$(lib_common) $$(lib_client)'; \ + echo $${i}_la_LIBADD += '$$(lib_broker) $$(extra_libs)'; \ + echo $${i}_la_LDFLAGS = "-module -rpath `pwd`"; \ + done; \ ) \ > $@-t mv $@-t $@ @@ -138,7 +147,7 @@ check-unit: $(MAKE) check TESTS=$(UNIT_TESTS) run-unit-tests # Make sure valgrind files are generated. -all: .valgrind.supp .valgrindrc +all-am: .valgrind.supp .valgrindrc # Create a copy so that can be modified without risk of committing the changes. .valgrindrc: .valgrindrc-default diff --git a/cpp/src/tests/Shlib.cpp b/cpp/src/tests/Shlib.cpp new file mode 100644 index 0000000000..87136425ab --- /dev/null +++ b/cpp/src/tests/Shlib.cpp @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "test_tools.h" +#include "qpid/sys/Shlib.h" + +#define BOOST_AUTO_TEST_MAIN // Must come before #include<boost/test/*> +#include <boost/test/auto_unit_test.hpp> + +using namespace qpid::sys; +typedef void (*CallMe)(int*); + +BOOST_AUTO_TEST_CASE(testShlib) { + Shlib sh(".libs/libshlibtest.so"); + // Double cast to avoid ISO warning. + CallMe callMe=sh.getSymbol<CallMe>("callMe"); + BOOST_REQUIRE(callMe != 0); + int unloaded=0; + callMe(&unloaded); + sh.unload(); + BOOST_CHECK_EQUAL(42, unloaded); + try { + sh.getSymbol("callMe"); + BOOST_FAIL("Expected exception"); + } + catch (...) {} +} + +BOOST_AUTO_TEST_CASE(testAutoShlib) { + int unloaded = 0; + { + AutoShlib sh(".libs/libshlibtest.so"); + CallMe callMe=sh.getSymbol<CallMe>("callMe"); + BOOST_REQUIRE(callMe != 0); + callMe(&unloaded); + } + BOOST_CHECK_EQUAL(42, unloaded); +} + diff --git a/cpp/src/tests/shlibtest.cpp b/cpp/src/tests/shlibtest.cpp new file mode 100644 index 0000000000..80320ea7be --- /dev/null +++ b/cpp/src/tests/shlibtest.cpp @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +int* loaderData = 0; +extern "C" void callMe(int *i) { loaderData=i; } + +struct OnUnload { ~OnUnload() { *loaderData=42; } }; +OnUnload unloader; // For destructor. + + + |