I'm developing on a project that is mixed C/C++ and I'm trying to figure out how to write test cases for C functions. I've looked at the Cookbook and I cannot see how to do this. Could someone give me some pointers?
Thanks,
Kyle Brost
----
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What doesn't make sense? If I had mixed C/C++, I'd still write the tests in CppUnit/C++, just assert that the returns from the extern "C" functions were as I expected.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I should have been more specific in my message. Attached is a sample of code that has a class and a simple function. The 'main' contains a runner for the class.
My question is, How do I register the test_IsEven_* functions with CppUnit and have it automatically execute and collect the results?
Hello,
I'm developing on a project that is mixed C/C++ and I'm trying to figure out how to write test cases for C functions. I've looked at the Cookbook and I cannot see how to do this. Could someone give me some pointers?
Thanks,
Kyle Brost
----
What doesn't make sense? If I had mixed C/C++, I'd still write the tests in CppUnit/C++, just assert that the returns from the extern "C" functions were as I expected.
I should have been more specific in my message. Attached is a sample of code that has a class and a simple function. The 'main' contains a runner for the class.
My question is, How do I register the test_IsEven_* functions with CppUnit and have it automatically execute and collect the results?
Thanks,
Kyle Brost
----
#include "cppunit/TextTestResult.h"
#include "cppunit/TestCase.h"
#include <cppunit/extensions/HelperMacros.h>
#include <stdio.h>
#include <iostream.h>
class MyMath
{
public:
bool IsOdd(int value_)
{
if(value_ % 2 == 1)
return true;
else
return false;
}
};
class MyMathTest : public CppUnit::TestCase
{
public:
void runTest()
{
MyMath theMath;
CPPUNIT_ASSERT( theMath.IsOdd(0) == 0);
CPPUNIT_ASSERT( theMath.IsOdd(1) == 1);
CPPUNIT_ASSERT( theMath.IsOdd(2) == 0);
}
};
int IsEven(int value_)
{
if(value_ % 2 == 0)
{
return 1;
}
else
{
return 0;
}
}
void test_IsEven_0()
{
CPPUNIT_ASSERT(IsEven(0) == 1);
}
void test_IsEven_1()
{
CPPUNIT_ASSERT(IsEven(1) == 0);
}
void test_IsEven_2()
{
CPPUNIT_ASSERT(IsEven(2) == 1);
}
int
main(int argc, char** argv)
{
CppUnit::TestCaller<MyMathTest> theTest("IsOdd", &MyMathTest::runTest);
CppUnit::TextTestResult theResult;
theTest.run( &theResult );
std::cout << theResult << std::endl;
return 0;
}