|
| 1 | +/* |
| 2 | + * Copyright (c) 2011, 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 | +#include "CppUTest/CppUTestConfig.h" |
| 29 | +#include "CppUTest/Utest.h" |
| 30 | +#include "CppUTest/TestResult.h" |
| 31 | +#include "CppUTest/TestFailure.h" |
| 32 | + |
| 33 | +#define TEST(testGroup, testName) \ |
| 34 | + /* external declaration */ \ |
| 35 | + class TEST_##testGroup##_##testName##_TestShell; \ |
| 36 | + extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_TestShell_Instance; \ |
| 37 | + class TEST_##testGroup##_##testName##_Test : public Utest \ |
| 38 | +{ public: TEST_##testGroup##_##testName##_Test () : Utest () {} \ |
| 39 | + void testBody(); }; \ |
| 40 | + class TEST_##testGroup##_##testName##_TestShell : public UtestShell \ |
| 41 | +{ public: virtual Utest* createTest() { return new TEST_##testGroup##_##testName##_Test; } \ |
| 42 | + } TEST_##testGroup##_##testName##_TestShell_Instance; \ |
| 43 | + static TestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_TestShell_Instance, #testGroup, #testName, __FILE__,__LINE__); \ |
| 44 | + void TEST_##testGroup##_##testName##_Test::testBody() |
| 45 | + |
| 46 | +#define TEST_F(testGroup, testName) \ |
| 47 | +/* external declaration */ \ |
| 48 | + class TEST_##testGroup##_##testName##_TestShell; \ |
| 49 | + extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_TestShell_instance; \ |
| 50 | + class TEST_##testGroup##_##testName##_Test : public testGroup \ |
| 51 | +{ public: TEST_##testGroup##_##testName##_Test () : testGroup () {} \ |
| 52 | + void testBody(); }; \ |
| 53 | + class TEST_##testGroup##_##testName##_TestShell : public UtestShell { \ |
| 54 | + virtual Utest* createTest() { return new TEST_##testGroup##_##testName##_Test; } \ |
| 55 | + } TEST_##testGroup##_##testName##_TestShell_instance; \ |
| 56 | + static TestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \ |
| 57 | + void TEST_##testGroup##_##testName##_Test::testBody() |
| 58 | + |
| 59 | +/* |
| 60 | + * NOTICE: |
| 61 | + * |
| 62 | + * Code duplicated from UtestMacros.h. Its hard to share as don't want to include the CppUTest |
| 63 | + * macros in the gtest interface. |
| 64 | + * |
| 65 | + */ |
| 66 | + |
| 67 | +#define EXPECT_EQ(expected, actual) \ |
| 68 | + { UtestShell::getCurrent()->assertEquals(((expected) != (actual)), StringFrom(expected).asCharString(), StringFrom(actual).asCharString(), __FILE__, __LINE__); } |
| 69 | + |
| 70 | +#define EXPECT_TRUE(condition) \ |
| 71 | + { UtestShell::getCurrent()->assertTrue((condition) != 0, "EXPECT_TRUE", #condition, __FILE__, __LINE__); } |
| 72 | + |
| 73 | +#define EXPECT_FALSE(condition) \ |
| 74 | + { UtestShell::getCurrent()->assertTrue((condition) == 0, "EXPECT_FALSE", #condition, __FILE__, __LINE__); } |
| 75 | + |
| 76 | +#define EXPECT_STREQ(expected, actual) \ |
| 77 | + { UtestShell::getCurrent()->assertCstrEqual(expected, actual, __FILE__, __LINE__); } |
| 78 | + |
| 79 | +#define ASSERT_EQ(expected, actual) EXPECT_EQ(expected, actual) |
| 80 | + |
| 81 | +#define ASSERT_TRUE(condition) EXPECT_TRUE(condition) |
| 82 | + |
| 83 | +namespace testing |
| 84 | +{ |
| 85 | + class Test : public Utest |
| 86 | + { |
| 87 | + virtual void SetUp(){} |
| 88 | + virtual void TearDown(){} |
| 89 | + |
| 90 | + void setup() |
| 91 | + { |
| 92 | + SetUp(); |
| 93 | + } |
| 94 | + |
| 95 | + void teardown() |
| 96 | + { |
| 97 | + TearDown(); |
| 98 | + } |
| 99 | + |
| 100 | + }; |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | + |
0 commit comments