2 //! @brief Implementation file for the CampaignTest class
4 #include <cppunit/TestCase.h>
5 #include <cppunit/TestFixture.h>
6 #include <cppunit/ui/text/TextTestRunner.h>
7 #include <cppunit/extensions/HelperMacros.h>
8 #include <cppunit/extensions/TestFactoryRegistry.h>
9 #include <cppunit/TestResult.h>
10 #include <cppunit/TestResultCollector.h>
11 #include <cppunit/TestRunner.h>
12 #include <cppunit/BriefTestProgressListener.h>
13 #include <cppunit/CompilerOutputter.h>
14 #include <cppunit/XmlOutputter.h>
16 using namespace CppUnit
;
18 //! Test Class for the Campaign class
19 class CampaignTest
: public CppUnit::TestFixture
21 CPPUNIT_TEST_SUITE(CampaignTest
);
24 CPPUNIT_TEST(testAddMap
);
25 CPPUNIT_TEST(testRemoveMap
);
26 CPPUNIT_TEST_SUITE_END();
39 //! cppunit registry creation
40 CPPUNIT_TEST_SUITE_REGISTRATION(CampaignTest
);
42 //! method called before every test case in this test class
43 void CampaignTest::setUp()
45 // Create a map with 5 rows and 5 columns
47 campaign
= new Campaign();
50 //! method called after every test case in this test class
51 void CampaignTest::tearDown()
57 //! test method to test the addMap method of the Campaign class
58 //! Test Case: the returned value should be 1 if the map is added correctly
59 //! Tested item: Campaign::addMap()
60 void CampaignTest::testAddMap()
62 cout
<< "\n\nTesting testAddMap: ";
63 campaign
->addMap(map
);
65 // Should be a map in the campaign now
66 CPPUNIT_ASSERT(1 == campaign
->getMapsInCampaign());
69 //! test method to test the removeMap method of the Campaign class
70 //! Test Case: the returned value should be 0 if the map that is added is immediately removed
71 //! Tested item: Campaign::removeMap()
72 void CampaignTest::testRemoveMap()
74 cout
<< "\n\nTesting testRemoveMap: ";
76 // Created to avoid the program from crashing due to the tear down
77 Map
* map2
= new Map(map
);
78 campaign
->addMap(map2
);
79 campaign
->removeMap(map2
);
81 // Should be a map in the campaign now
82 CPPUNIT_ASSERT(0 == campaign
->getMapsInCampaign());