summaryrefslogtreecommitdiff
path: root/src/msvc6/testpluginrunner/TestPlugIn.cpp
blob: 2612220ea2258f32f8ce1be706814c4c5b6e6129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// //////////////////////////////////////////////////////////////////////////
// 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 <cppunit/plugin/DynamicLibraryManagerException.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "TestPlugInException.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



TestPlugIn::TestPlugIn( const std::string fileName ) :
    m_fileName( fileName )
{
  m_copyFileName = m_fileName + "-hotrunner";
}


TestPlugIn::~TestPlugIn()
{
  deleteDllCopy();
}


void 
TestPlugIn::deleteDllCopy()
{
  m_manager.unload( m_copyFileName );
  ::DeleteFile( m_copyFileName.c_str() );
}


class NullTest : public CPPUNIT_NS::TestCase
{
public:
  NullTest( std::string name ) : TestCase( name ) 
  {
  }

  ~NullTest() 
  {
  }

  void runTests()
  {
    CPPUNIT_ASSERT_MESSAGE( "Failed to load" + getName(), FALSE );
  }
};


CPPUNIT_NS::Test *
TestPlugIn::makeTest()
{
  reloadDll();
  return CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
}


void 
TestPlugIn::reloadDll()
{
  m_manager.unload( m_copyFileName );
  makeDllCopy();
  loadDll();
}


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()
{
  try
  {
    m_manager.load( m_copyFileName );
  }
  catch ( CPPUNIT_NS::DynamicLibraryManagerException &e )
  {
    throw TestPlugInException( e.what(), 
                               TestPlugInException::failedToLoadDll );
  }
}