File: PluginManagerTest.cpp

package info (click to toggle)
clutils 20031216-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,348 kB
  • ctags: 540
  • sloc: sh: 7,191; cpp: 4,128; makefile: 192
file content (116 lines) | stat: -rw-r--r-- 3,062 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2000-2002 Clifton Labs, Inc.  
// All rights reserved.

// Clifton Labs MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF 
// THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  Clifton Labs SHALL NOT BE LIABLE
// FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
// RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
// DERIVATIVES.

// By using or copying this Software, Licensee agrees to abide by the
// intellectual property laws, and all other applicable laws of the
// U.S., and the terms of this license.

// Authors: Dale E. Martin   dmartin@cliftonlabs.com

#include "PluginManagerTest.h"
#include <clutils/PluginManager.h>
#include <clutils/StringUtilities.h>
#include <clutils/Debug.h>
#include <clutils/PluginBase.h>
#include "Greeter.h"

using std::endl;
using std::cout;
using std::cerr;;

PluginManagerTest *
PluginManagerTest::instance(){
  static PluginManagerTest *myPluginManagerTest = new PluginManagerTest();
  
  return myPluginManagerTest;
}

int 
PluginManagerTest::instanceTest() const {
  int retval = 0;

  clutils::debug << "Starting instance test - ";

  const PluginManager *fm1 = PluginManager::instance();
  const PluginManager *fm2 = PluginManager::instance();

  if( fm1 == 0 || fm2 == 0 ){
    cerr << "Got a null instance for a PluginManager!" << endl;
    retval = -1;
    goto end;
  }

  if( fm1 != fm2 ){
    cerr << "Got a two separate instances for PluginManagers!" << endl;
    retval = -1;
    goto end;
  }

 end:
  if( retval == 0 ){
    clutils::debug << "passed." << endl;
  }

  return retval;
}

int
PluginManagerTest::pluginListTest( const string &directory ) const {
  int retval = 0;

  clutils::debug << "Starting plugin list test - ";

  PluginManager *mm = PluginManager::instance();
  const vector<PluginBase *> *pluginList = mm->getPluginList( directory );
  clutils::debug << "Found " << pluginList->size() << " plugins" << endl;
  if( pluginList->size() > 0 ){
    for( vector<PluginBase *>::const_iterator i = pluginList->begin();
	 i != pluginList->end();
	 i++ ){
      PluginBase *currentPlugin = *i;
      clutils::debug << "Found " << currentPlugin->getPluginName() << endl;
      Greeter *asGreeter = static_cast<Greeter *>(currentPlugin);
      if( asGreeter == 0 ){
	clutils::debug << "Plugin loaded, but cast to Greeter * failed" << endl;
	retval = -1;
	break;
      }
      else{
	const string &greetings = asGreeter->getGreetings();
	clutils::debug << "Greetings = " << greetings << endl;
      }
    }
  }
  else{
    cerr << "Failed to find any plugins - something is wrong!" << endl;
    retval = -1;
  }
  if( retval == 0 ){
    clutils::debug << "passed." << endl;
  }

  return retval;
}

int 
PluginManagerTest::regressionTest(){
  int status = instanceTest();
  const string directory = "plugins";

  if( status != 0 ){
    goto end;
  }

  status = pluginListTest( directory );

 end:
  return status;
}