CppUTest
TestTestingFixture.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_TestTestingFixture_H
29 #define D_TestTestingFixture_H
30 
31 #include "TestRegistry.h"
32 
34 {
35 public:
36 
38  {
39  output_ = new StringBufferTestOutput();
40  result_ = new TestResult(*output_);
41  genTest_ = new ExecFunctionTestShell();
42  registry_ = new TestRegistry();
43 
44  registry_->setCurrentRegistry(registry_);
45  registry_->addTest(genTest_);
46  }
47 
48  virtual ~TestTestingFixture()
49  {
50  registry_->setCurrentRegistry(0);
51  delete registry_;
52  delete result_;
53  delete output_;
54  delete genTest_;
55  }
56 
57  void setTestFunction(void(*testFunction)())
58  {
59  genTest_->testFunction_ = testFunction;
60  }
61 
62  void setSetup(void(*setupFunction)())
63  {
64  genTest_->setup_ = setupFunction;
65  }
66 
67  void setTeardown(void(*teardownFunction)())
68  {
69  genTest_->teardown_ = teardownFunction;
70  }
71 
72  void runAllTests()
73  {
74  registry_->runAllTests(*result_);
75  }
76 
77  int getFailureCount()
78  {
79  return result_->getFailureCount();
80  }
81 
82  void assertPrintContains(const SimpleString& contains)
83  {
84  assertPrintContains(output_, contains);
85  }
86 
87  static void assertPrintContains(StringBufferTestOutput* output,
88  const SimpleString& contains)
89  {
90  STRCMP_CONTAINS(contains.asCharString(), output->getOutput().asCharString());
91 
92  }
93 
94  TestRegistry* registry_;
95  ExecFunctionTestShell* genTest_;
96  StringBufferTestOutput* output_;
97  TestResult * result_;
98 };
99 
100 #endif
Definition: TestTestingFixture.h:33
Definition: Utest.h:182
Definition: TestResult.h:41
Definition: TestRegistry.h:43
Definition: TestOutput.h:134
Definition: SimpleString.h:46