diff --git a/tests/exceptions.at b/tests/exceptions.at index 293723c..3b5b9e1 100644 --- a/tests/exceptions.at +++ b/tests/exceptions.at @@ -36,10 +36,28 @@ esac], [], [ignore]) CPPFLAGS="$LTDLINCL $CPPFLAGS" -AT_DATA([module.h], -[[#include +AT_DATA([common.h], +[[#ifndef LIBTOOL_TEST_COMMON_HEADER +#define LIBTOOL_TEST_COMMON_HEADER + +#include #include -class modexc : public std::exception { + +#if defined(__CYGWIN__) || defined(_WIN32) +# if defined(DLL_EXPORT) || defined(USING_COMMON_DLL) +# if defined(LIBTOOL_TEST_IN_COMMON) +# define COMMON_IMPEXP __attribute__ ((dllexport)) +# else +# define COMMON_IMPEXP __attribute__ ((dllimport)) +# endif +# else +# define COMMON_IMPEXP +# endif +#else +# define COMMON_IMPEXP +#endif + +class COMMON_IMPEXP modexc : public std::exception { public: modexc (std::string str) : message (str) { } ~modexc () throw () { } @@ -50,11 +68,45 @@ public: private: std::string message; }; -extern "C" int modfoo () throw (modexc); + +extern "C" int COMMON_IMPEXP common_dummy (void); +#endif +]]) + +AT_DATA([common.cpp], +[[#define LIBTOOL_TEST_IN_COMMON +#include "common.h" + +extern "C" +int common_dummy (void) +{ + return 0; +} +]]) + +AT_DATA([module.h], +[[#include "common.h" + +#if defined(__CYGWIN__) || defined(_WIN32) +# if defined(DLL_EXPORT) || defined(USING_MODULE_DLL) +# if defined(LIBTOOL_TEST_IN_MODULE) +# define MODULE_IMPEXP __attribute__ ((dllexport)) +# else +# define MODULE_IMPEXP __attribute__ ((dllimport)) +# endif +# else +# define MODULE_IMPEXP +# endif +#else +# define MODULE_IMPEXP +#endif + +extern "C" int MODULE_IMPEXP modfoo () throw (modexc); ]]) AT_DATA([module.cpp], [[#include +#define LIBTOOL_TEST_IN_MODULE #include "module.h" int modbar (void) throw (modexc) @@ -79,7 +131,23 @@ int modfoo (void) throw (modexc) AT_DATA([lib.h], [[#include #include -class libexc : public std::exception { + + +#if defined(__CYGWIN__) || defined(_WIN32) +# if defined(DLL_EXPORT) || defined(USING_LIB_DLL) +# if defined(LIBTOOL_TEST_IN_LIB) +# define LIB_IMPEXP __attribute__ ((dllexport)) +# else +# define LIB_IMPEXP __attribute__ ((dllimport)) +# endif +# else +# define LIB_IMPEXP +# endif +#else +# define LIB_IMPEXP +#endif + +class LIB_IMPEXP libexc : public std::exception { public: libexc (std::string str) : message (str) { } ~libexc () throw () { } @@ -90,11 +158,12 @@ public: private: std::string message; }; -int libfoo () throw (libexc); +int LIB_IMPEXP libfoo () throw (libexc); ]]) AT_DATA([lib.cpp], [[#include +#define LIBTOOL_TEST_IN_LIB #include "lib.h" int libbar (void) throw (libexc) @@ -121,6 +190,7 @@ AT_DATA([main.cpp], #include #include #include +#include "common.h" #include "lib.h" #include "module.h" @@ -202,11 +272,17 @@ int exceptions_in_module (void) return 1; } + bool exception_caught = false; try { (*pf) (); } catch (modexc e) { std::cerr << "caught: " << e.what () << '\n'; + exception_caught = true; + } + + if (exception_caught) + { if (lt_dlclose (handle)) { std::cerr << "dlclose failed: " << lt_dlerror () << '\n'; @@ -244,26 +320,34 @@ moddir=$inst/mod mkdir l m $inst $libdir $bindir $moddir # If the C++ compiler isn't capable, don't bother. -AT_CHECK([$CXX $CPPFLAGS $CXXFLAGS -c main.cpp || exit 77], [], [ignore], [ignore]) +AT_CHECK([$CXX $CPPFLAGS $CXXFLAGS -DUSING_COMMON_DLL -DUSING_MODULE_DLL -DUSING_LIB_DLL -c main.cpp || exit 77], [], [ignore], [ignore]) -for file in lib.cpp module.cpp; do - AT_CHECK([$LIBTOOL --mode=compile --tag=CXX $CXX $CPPFLAGS $CXXFLAGS -c $file], +AT_CHECK([$LIBTOOL --mode=compile --tag=CXX $CXX $CPPFLAGS $CXXFLAGS -c common.cpp], + [], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --mode=compile --tag=CXX $CXX $CPPFLAGS $CXXFLAGS -c lib.cpp], + [], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --mode=compile --tag=CXX $CXX $CPPFLAGS $CXXFLAGS -DUSING_COMMON_DLL -c module.cpp], [], [ignore], [ignore]) -done + +AT_CHECK([$LIBTOOL --mode=link --tag=CXX $CXX $CXXFLAGS $LDFLAGS -o l/libcommon.la ]dnl + [common.lo -no-undefined -version-info 1:0:0 -rpath $libdir], + [], [ignore], [ignore]) AT_CHECK([$LIBTOOL --mode=link --tag=CXX $CXX $CXXFLAGS $LDFLAGS -o l/liba.la ]dnl [lib.lo -no-undefined -version-info 1:0:0 -rpath $libdir], [], [ignore], [ignore]) AT_CHECK([$LIBTOOL --mode=link --tag=CXX $CXX $CXXFLAGS $LDFLAGS -o m/module.la ]dnl - [module.lo -module -avoid-version -no-undefined -rpath $moddir], + [module.lo l/libcommon.la -module -avoid-version -no-undefined -rpath $moddir], [], [ignore], [ignore]) # We need -export-dynamic for the exception handling in modules to work. AT_CHECK([$LIBTOOL --mode=link --tag=CXX $CXX $CXXFLAGS $LDFLAGS -o main$EXEEXT ]dnl - [main.$OBJEXT l/liba.la -dlopen m/module.la $LIBLTDL -export-dynamic], + [main.$OBJEXT l/liba.la l/libcommon.la -dlopen m/module.la $LIBLTDL -export-dynamic], [], [ignore], [ignore]) LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen m/module.la], [], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --mode=install cp l/libcommon.la $libdir], + [], [ignore], [ignore]) AT_CHECK([$LIBTOOL --mode=install cp l/liba.la $libdir], [], [ignore], [ignore]) AT_CHECK([$LIBTOOL --mode=install cp m/module.la $moddir],