NetBurner 3.1
TestPlugin.h
1 /*
2  * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef D_TestPlugin_h
29 #define D_TestPlugin_h
30 
31 class UtestShell;
32 class TestResult;
33 
34 class TestPlugin
35 {
36 public:
37 
38  TestPlugin(const SimpleString& name);
39  virtual ~TestPlugin();
40 
41  virtual void preTestAction(UtestShell&, TestResult&)
42  {
43  }
44 
45  virtual void postTestAction(UtestShell&, TestResult&)
46  {
47  }
48 
49  virtual bool parseArguments(int /* ac */, const char** /* av */, int /* index */ )
50  {
51  return false;
52  }
53 
54  virtual void runAllPreTestAction(UtestShell&, TestResult&);
55  virtual void runAllPostTestAction(UtestShell&, TestResult&);
56  virtual bool parseAllArguments(int ac, const char** av, int index);
57  virtual bool parseAllArguments(int ac, char** av, int index);
58 
59  virtual TestPlugin* addPlugin(TestPlugin*);
60  virtual TestPlugin* removePluginByName(const SimpleString& name);
61  virtual TestPlugin* getNext();
62 
63  virtual void disable();
64  virtual void enable();
65  virtual bool isEnabled();
66 
67  const SimpleString& getName();
68  TestPlugin* getPluginByName(const SimpleString& name);
69 
70 protected:
71  TestPlugin(TestPlugin* next_);
72 
73 private:
74  TestPlugin* next_;
75  SimpleString name_;
76  bool enabled_;
77 };
78 
80 //
81 // SetPointerPlugin
82 //
83 // This is a very small plugin_ that resets pointers to their original value.
84 //
86 
87 extern void CppUTestStore(void **location);
88 
89 class SetPointerPlugin: public TestPlugin
90 {
91 public:
92  SetPointerPlugin(const SimpleString& name);
93  virtual void postTestAction(UtestShell&, TestResult&) _override;
94 
95  enum
96  {
97  MAX_SET = 32
98  };
99 };
100 
101 #define UT_PTR_SET(a, b) { CppUTestStore( (void**)&a ); a = b; }
102 
104 
105 class NullTestPlugin: public TestPlugin
106 {
107 public:
108 
109  NullTestPlugin();
110 
111  virtual void runAllPreTestAction(UtestShell& test, TestResult& result) _override;
112  virtual void runAllPostTestAction(UtestShell& test, TestResult& result) _override;
113 
114  static NullTestPlugin* instance();
115 };
116 
117 #endif