Created
January 12, 2013 00:39
-
-
Save Lewuathe/4515294 to your computer and use it in GitHub Desktop.
CPPUnitの使い方 ref: http://qiita.com/items/0bb755f8a251fc148379
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXX=g++ | |
LIBS=-lcppunit | |
SOURCES=someTest.cc some.cc | |
TARGETS=mainTest | |
all : | |
g++ -o mainTest mainTest.cc $(SOURCES) $(LIBS) | |
clean : | |
rm $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cppunit/TestResult.h> | |
#include <cppunit/TestResultCollector.h> | |
#include <cppunit/BriefTestProgressListener.h> | |
#include <cppunit/TestRunner.h> | |
#include <cppunit/extensions/TestFactoryRegistry.h> | |
#include <cppunit/CompilerOutputter.h> | |
using namespace CPPUNIT_NS; | |
int main(int argc, char **argv) { | |
TestResult controller; | |
TestResultCollector result; | |
controller.addListener(&result); | |
BriefTestProgressListener progress; | |
controller.addListener(&progress); | |
TestRunner runner; | |
runner.addTest(TestFactoryRegistry::getRegistry().makeTest()); | |
runner.run(controller); | |
CompilerOutputter outputter(&result, stdCOut()); | |
outputter.write(); | |
return result.wasSuccessful() ? 0 : 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool some(bool tf){ | |
return !tf; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "some.cc" | |
#include <cppunit/extensions/HelperMacros.h> | |
using namespace CPPUNIT_NS; | |
class someTest : public TestFixture { | |
CPPUNIT_TEST_SUITE(someTest); | |
CPPUNIT_TEST(test1); | |
CPPUNIT_TEST(test2); | |
CPPUNIT_TEST_SUITE_END(); | |
void test1(){ | |
CPPUNIT_ASSERT( some(true) == false ); | |
} | |
void test2(){ | |
CPPUNIT_ASSERT( some(false) == true ); | |
} | |
}; | |
CPPUNIT_TEST_SUITE_REGISTRATION(reverseTest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment