fork

Fork of cpputest by Rohit Grover

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TestTestingFixture.h Source File

TestTestingFixture.h

00001 /*
00002  * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *     * Redistributions of source code must retain the above copyright
00008  *       notice, this list of conditions and the following disclaimer.
00009  *     * Redistributions in binary form must reproduce the above copyright
00010  *       notice, this list of conditions and the following disclaimer in the
00011  *       documentation and/or other materials provided with the distribution.
00012  *     * Neither the name of the <organization> nor the
00013  *       names of its contributors may be used to endorse or promote products
00014  *       derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
00017  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
00020  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #ifndef D_TestTestingFixture_H
00029 #define D_TestTestingFixture_H
00030 
00031 #include "TestRegistry.h"
00032 #include "TestOutput.h"
00033 
00034 class TestTestingFixture
00035 {
00036 public:
00037 
00038     TestTestingFixture()
00039     {
00040         output_ = new StringBufferTestOutput();
00041         result_ = new TestResult(*output_);
00042         genTest_ = new ExecFunctionTestShell();
00043         registry_ = new TestRegistry();
00044 
00045         registry_->setCurrentRegistry(registry_);
00046         registry_->addTest(genTest_);
00047     }
00048 
00049     virtual ~TestTestingFixture()
00050     {
00051         registry_->setCurrentRegistry(0);
00052         delete registry_;
00053         delete result_;
00054         delete output_;
00055         delete genTest_;
00056     }
00057 
00058     void addTest(UtestShell * test)
00059     {
00060         registry_->addTest(test);
00061     }
00062 
00063     void setTestFunction(void(*testFunction)())
00064     {
00065         genTest_->testFunction_ = testFunction;
00066     }
00067 
00068     void setSetup(void(*setupFunction)())
00069     {
00070         genTest_->setup_ = setupFunction;
00071     }
00072 
00073     void setTeardown(void(*teardownFunction)())
00074     {
00075         genTest_->teardown_ = teardownFunction;
00076     }
00077 
00078     void runAllTests()
00079     {
00080         registry_->runAllTests(*result_);
00081     }
00082 
00083     int getFailureCount()
00084     {
00085         return result_->getFailureCount();
00086     }
00087 
00088     int getCheckCount()
00089     {
00090         return result_->getCheckCount();
00091     }
00092 
00093     int getIgnoreCount()
00094     {
00095         return result_->getIgnoredCount();
00096     }
00097 
00098     bool hasTestFailed()
00099     {
00100         return genTest_->hasFailed();
00101     }
00102 
00103 
00104     void assertPrintContains(const SimpleString& contains)
00105     {
00106         assertPrintContains(output_, contains);
00107     }
00108 
00109     static void assertPrintContains(StringBufferTestOutput* output,
00110             const SimpleString& contains)
00111     {
00112         STRCMP_CONTAINS(contains.asCharString(), output->getOutput().asCharString());
00113 
00114     }
00115 
00116     TestRegistry* registry_;
00117     ExecFunctionTestShell* genTest_;
00118     StringBufferTestOutput* output_;
00119     TestResult * result_;
00120 };
00121 
00122 class SetBooleanOnDestructorCall
00123 {
00124     bool& booleanToSet_;
00125 public:
00126     SetBooleanOnDestructorCall(bool& booleanToSet) : booleanToSet_(booleanToSet)
00127     {
00128     }
00129 
00130     virtual ~SetBooleanOnDestructorCall()
00131     {
00132         booleanToSet_ = true;
00133     }
00134 };
00135 
00136 #endif