summaryrefslogtreecommitdiff
path: root/src/msvc6/testpluginrunner/TestPlugIn.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-27 20:23:22 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2001-06-27 20:23:22 +0000
commit5813e2e80e995893a0a2d2fe4a6f6a8c2155d82c (patch)
tree317da54d9f4aaa23d85b996b7624f21f96b010e0 /src/msvc6/testpluginrunner/TestPlugIn.cpp
parentd52bd686fe91e4c5104b60632ed18eb26ae827f6 (diff)
downloadcppunit-5813e2e80e995893a0a2d2fe4a6f6a8c2155d82c.tar.gz
Examples/msvc6/CppUnitTestApp/CppUnitTestApp.
examples/msvc6/CppUnitTestApp/CppUnitTestApp.dsp: moved dll copy from post-build to custom build setting, so that the dll is copied even if the CppUnitTestApp was not modified. * examples/msvc6/TestPlugIn/: a new example of test plug in. * src/msvc6/TestRunner/ListCtrlFormatter.* * src/msvc6/TestRunner/ListCtrlSetter.*: added, helper to manipulate list control. * src/msvc6/TestRunner/TestRunnerDlg.*: change to make the error list more compact. text moved to string resources. icons added for typ test tfailure type. * src/msvc6/TestRunner/MostRecentTests.*: added, classes that will replace the current implementation of MRU test which make it hard to subclass the dialog. * src/msvc6/TestRunner/res/errortype.bmp: added, bitmap with error types (failure and error). * src/msvc6/TestPlugInRunner/: A test runner to run test plug in. Test plug in are DLL that publish a specified plug in interface. Those DLL are loaded and reloaded by the TestPlugInRunner to run tests. This remove the need to wrap DLL with a executable to test them. * src/cppunit/cppunit.dsp: removed config.h from project added Portability.h and config-msvc6.h * include/cppunit/config-msvc6.h: undef CPPUNIT_FUNC_STRING_COMPARE_STRING_FIRST
Diffstat (limited to 'src/msvc6/testpluginrunner/TestPlugIn.cpp')
-rw-r--r--src/msvc6/testpluginrunner/TestPlugIn.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/msvc6/testpluginrunner/TestPlugIn.cpp b/src/msvc6/testpluginrunner/TestPlugIn.cpp
new file mode 100644
index 0000000..6ab8487
--- /dev/null
+++ b/src/msvc6/testpluginrunner/TestPlugIn.cpp
@@ -0,0 +1,122 @@
+// //////////////////////////////////////////////////////////////////////////
+// Implementation file TestPlugIn.cpp for class TestPlugIn
+// (c)Copyright 2000, Baptiste Lepilleur.
+// Created: 2001/06/23
+// //////////////////////////////////////////////////////////////////////////
+
+#include "StdAfx.h"
+#include "TestPlugIn.h"
+#include <cppunit/TestCase.h>
+#include "TestPlugInException.h"
+
+
+TestPlugIn::TestPlugIn( const std::string fileName ) :
+ m_fileName( fileName ),
+ m_dllHandle( NULL ),
+ m_interfaceFunction( NULL )
+{
+ m_copyFileName = m_fileName + "-hotrunner";
+}
+
+
+TestPlugIn::~TestPlugIn()
+{
+ releaseDll();
+ deleteDllCopy();
+}
+
+
+void
+TestPlugIn::releaseDll()
+{
+ if ( m_dllHandle != NULL )
+ ::FreeLibrary( m_dllHandle );
+ m_dllHandle = NULL;
+ m_interfaceFunction = NULL;
+}
+
+
+void
+TestPlugIn::deleteDllCopy()
+{
+ ::DeleteFile( m_copyFileName.c_str() );
+}
+
+
+class NullTest : public CppUnit::TestCase
+{
+public:
+ NullTest( std::string name ) : TestCase( name )
+ {
+ }
+
+ ~NullTest()
+ {
+ }
+
+ void runTests()
+ {
+ CPPUNIT_ASSERT_MESSAGE( "Failed to load" + getName(), FALSE );
+ }
+};
+
+
+CppUnit::Test *
+TestPlugIn::makeTest()
+{
+ reloadDll();
+ TestPlugInInterface *theInterface = (*m_interfaceFunction)();
+
+ try
+ {
+ return theInterface->makeTest();
+ }
+ catch ( ... )
+ {
+ throw TestPlugInException( "Failed to make test using GetTestPlugInInterface",
+ TestPlugInException::failedToMakeTest );
+ }
+}
+
+
+void
+TestPlugIn::reloadDll()
+{
+ releaseDll();
+ makeDllCopy();
+ loadDll();
+ getDllInterface();
+}
+
+
+void
+TestPlugIn::makeDllCopy()
+{
+ if ( ::CopyFile( m_fileName.c_str(), m_copyFileName.c_str(), FALSE ) == FALSE )
+ {
+ throw TestPlugInException( "Failed to copy DLL" + m_fileName +
+ " to " + m_copyFileName, TestPlugInException::failedToCopyDll );
+ }
+}
+
+
+void
+TestPlugIn::loadDll()
+{
+ m_dllHandle = ::LoadLibrary( m_copyFileName.c_str() );
+ if ( m_dllHandle == NULL )
+ throw TestPlugInException( "Failed to load DLL " + m_copyFileName,
+ TestPlugInException::failedToLoadDll );
+}
+
+
+void
+TestPlugIn::getDllInterface()
+{
+ m_interfaceFunction = (GetTestPlugInInterfaceFunction )
+ ::GetProcAddress( m_dllHandle, "GetTestPlugInInterface" );
+ if ( m_interfaceFunction == NULL )
+ throw TestPlugInException( "Failed to locate function GetTestPlugInInterface "
+ " in DLL " + m_fileName,
+ TestPlugInException::failedToGetInterfaceFunction );
+}