fork

Fork of cpputest by Rohit Grover

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TestPlugin.h Source File

TestPlugin.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_TestPlugin_h
00029 #define D_TestPlugin_h
00030 
00031 class UtestShell;
00032 class TestResult;
00033 
00034 class TestPlugin
00035 {
00036 public:
00037 
00038     TestPlugin(const SimpleString& name);
00039     virtual ~TestPlugin();
00040 
00041     virtual void preTestAction(UtestShell&, TestResult&)
00042     {
00043     }
00044 
00045     virtual void postTestAction(UtestShell&, TestResult&)
00046     {
00047     }
00048 
00049     virtual bool parseArguments(int /* ac */, const char** /* av */, int /* index */ )
00050     {
00051         return false;
00052     }
00053 
00054     virtual void runAllPreTestAction(UtestShell&, TestResult&);
00055     virtual void runAllPostTestAction(UtestShell&, TestResult&);
00056     virtual bool parseAllArguments(int ac, const char** av, int index);
00057     virtual bool parseAllArguments(int ac, char** av, int index);
00058 
00059     virtual TestPlugin* addPlugin(TestPlugin*);
00060     virtual TestPlugin* removePluginByName(const SimpleString& name);
00061     virtual TestPlugin* getNext();
00062 
00063     virtual void disable();
00064     virtual void enable();
00065     virtual bool isEnabled();
00066 
00067     const SimpleString& getName();
00068     TestPlugin* getPluginByName(const SimpleString& name);
00069 
00070 protected:
00071     TestPlugin(TestPlugin* next_);
00072 
00073 private:
00074     TestPlugin* next_;
00075     SimpleString name_;
00076     bool enabled_;
00077 };
00078 
00079 ///////////////////////////////////////////////////////////////////////////////
00080 //
00081 // SetPointerPlugin
00082 //
00083 // This is a very small plugin_ that resets pointers to their original value.
00084 //
00085 ///////////////////////////////////////////////////////////////////////////////
00086 
00087 extern void CppUTestStore(void **location);
00088 
00089 class SetPointerPlugin: public TestPlugin
00090 {
00091 public:
00092     SetPointerPlugin(const SimpleString& name);
00093     virtual ~SetPointerPlugin();
00094     virtual void postTestAction(UtestShell&, TestResult&) _override;
00095 
00096     enum
00097     {
00098         MAX_SET = 16
00099     };
00100 };
00101 
00102 #define UT_PTR_SET(a, b) { CppUTestStore( (void**)&a ); a = b; }
00103 
00104 ///////////// Null Plugin
00105 
00106 class NullTestPlugin: public TestPlugin
00107 {
00108 public:
00109 
00110     NullTestPlugin();
00111     virtual ~NullTestPlugin()
00112     {
00113     }
00114 
00115     virtual void runAllPreTestAction(UtestShell& test, TestResult& result) _override;
00116     virtual void runAllPostTestAction(UtestShell& test, TestResult& result) _override;
00117 
00118     static NullTestPlugin* instance();
00119 };
00120 
00121 #endif