// The original version of this code (revision 2 of the Subversion // archive) was released subject to the following license: // Copyright (c) 2006, Sun Microsystems, Inc. All rights reserved. // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following // conditions are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Sun Microsystems or the names of // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED BY SUN AND ITS LICENSORS ``AS IS'' AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN OR ITS // LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // Subsequent additions and modifications are Copyright (c) 2006 David // Carlton, and may be used subject to the same conditions. // A helper class for the UnitTest test suite: it can pass or fail as // desired, and give feedback as to when setup/run/teardown were // called. #ifndef UNITTESTTEST_HELPERTEST_H #define UNITTESTTEST_HELPERTEST_H #include #include class Helper : public UnitTest::ExistingObject, public UnitTest::Test { public: Helper(); // If this is set to true, the test will do an assertion failure. // (Default is for the test to pass.) void shouldFail(bool fail); // If this is called with a non-zero STATUS argument then, // whenever setup/run/teardown is called, // "NAME:{setup,run,teardown};" is appended to the end of *STATUS. void statusString(std::string *status, const char *name); // Return the number of passes/failures; default is 0. int passes() const; int failures() const; // Sets the number of passes/failures. void passes(int count); void failures(int count); protected: void setUp(); void run(); void tearDown(); private: void event(const char *body); void appendStatus(const char *text); const char *name_; std::string *status_; bool shouldFail_; int passes_; int failures_; }; typedef UnitTest::ExistingBase HelperBase; #endif // UNITTESTTEST_HELPERTEST_H