Skip to content
Snippets Groups Projects
Commit 8c92e6bc authored by Stéphane Poirier's avatar Stéphane Poirier
Browse files

Added first CPPunit tests

parent 6a1b80d7
Branches
Tags
No related merge requests found
CppUnit - Tutorial
------------------
To compile with GNU make under cygwin or unix-like systems
only type "make" at the shell and start the program with "./ftest".
This tutorial can be found under the tutorial-secion at www.EvoComp.de.
(http://www.EvoComp.de/tutorials/tutorium_cppunit/howto_tutorial_cppunit_en.html)
Please mail me if you have got any questions or suggestions (e-mail-address can
be found in the contact-section of www.EvoComp.de).
#ifndef CPPUNIT_YAT_H
#define CPPUNIT_YAT_H
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <yat/utils/String.h>
#include <yat/utils/StringTemplate.h>
#include <yat/file/FileName.h>
using namespace std;
class cppunit_YAT : public CPPUNIT_NS :: TestFixture
{
// First macro to indicate the beginning of the tests.
CPPUNIT_TEST_SUITE (cppunit_YAT);
// Marcos to launch the tests (each one is indicated by its specific function)
// ----------------------------------------
// Tests in the class "String"
CPPUNIT_TEST (test_String_split_A);
CPPUNIT_TEST (test_String_split_B);
CPPUNIT_TEST (test_String_split_C);
CPPUNIT_TEST (test_String_split_D);
CPPUNIT_TEST (test_String_split_E);
CPPUNIT_TEST (test_String_split_F);
CPPUNIT_TEST (test_String_extract_token_A);
CPPUNIT_TEST (test_String_extract_token_B);
CPPUNIT_TEST (test_String_extract_token_C);
CPPUNIT_TEST (test_String_extract_token_D);
CPPUNIT_TEST (test_String_extract_token_right_A);
CPPUNIT_TEST (test_String_extract_token_right_B);
CPPUNIT_TEST (test_String_extract_token_right_C);
CPPUNIT_TEST (test_String_extract_token_right_D);
// Tests in the class "StringTemplate"
CPPUNIT_TEST (test_StringTemplate_value_A);
CPPUNIT_TEST (test_StringTemplate_value_B);
CPPUNIT_TEST (test_StringTemplate_value_C);
CPPUNIT_TEST (test_StringTemplate_substitute_A);
CPPUNIT_TEST (test_StringTemplate_substitute_B);
CPPUNIT_TEST (test_StringTemplate_substitute_C);
CPPUNIT_TEST (test_StringTemplate_substitute_D);
CPPUNIT_TEST (test_StringTemplate_substitute_E);
CPPUNIT_TEST (test_StringTemplate_substitute_ex_A);
CPPUNIT_TEST (test_StringTemplate_substitute_ex_B);
CPPUNIT_TEST (test_StringTemplate_substitute_ex_C);
// Tests in the class "FSBytes"
CPPUNIT_TEST (test_FSBytes_to);
CPPUNIT_TEST (test_FSBytes_from_A);
CPPUNIT_TEST (test_FSBytes_from_B);
CPPUNIT_TEST (test_FSBytes_to_string_A);
CPPUNIT_TEST (test_FSBytes_to_string_B);
CPPUNIT_TEST (test_FSBytes_operator_A);
CPPUNIT_TEST (test_FSBytes_operator_B);
// Commented code left to illustrate a test based on exception catching (for further developpements)
// CPPUNIT_TEST (exceptionTest);
// Last macro to indicate the end of the tests.
CPPUNIT_TEST_SUITE_END ();
public:
// Functions to override
void setUp (void);
void tearDown (void);
protected:
// -------------------------------------------------------
// Test functions. The name is "test_" + <Class name> + "_" + <function name> + "_" + <ID of function template> .
// -------------------------------------------------------
// Functions in class String
void test_String_split_A (void);
void test_String_split_B (void);
void test_String_split_C (void);
void test_String_split_D (void);
void test_String_split_E (void);
void test_String_split_F (void);
void test_String_extract_token_A (void);
void test_String_extract_token_B (void);
void test_String_extract_token_C (void);
void test_String_extract_token_D (void);
void test_String_extract_token_right_A (void);
void test_String_extract_token_right_B (void);
void test_String_extract_token_right_C (void);
void test_String_extract_token_right_D (void);
// Functions in class StringTemplate
void test_StringTemplate_value_A (void);
void test_StringTemplate_value_B (void);
void test_StringTemplate_value_C (void);
void test_StringTemplate_value_D (void);
void test_StringTemplate_value_E (void);
void test_StringTemplate_substitute_A (void);
void test_StringTemplate_substitute_B (void);
void test_StringTemplate_substitute_C (void);
void test_StringTemplate_substitute_D (void);
void test_StringTemplate_substitute_E (void);
void test_StringTemplate_substitute_ex_A (void);
void test_StringTemplate_substitute_ex_B (void);
void test_StringTemplate_substitute_ex_C (void);
// Functions in class FSBytes
void test_FSBytes_to (void);
void test_FSBytes_from_A (void);
void test_FSBytes_from_B (void);
void test_FSBytes_to_string_A (void);
void test_FSBytes_to_string_B (void);
void test_FSBytes_operator_A (void);
void test_FSBytes_operator_B (void);
// Commented code left to illustrate a test based on exception catching (for further developpements)
// void exceptionTest (void);
private:
};
#endif
# CppUnit-Tutorial
# file: makefile
# next line has to be changed to the installation-path of CppUnit
CPPUNIT_PATH=/opt/cppunit
ftest: ftest.o fractiontest.o Fraction.o
gcc -o ftest ftest.o fractiontest.o Fraction.o -L${CPPUNIT_PATH}/lib -lstdc++ -lcppunit -ldl
Fraction.o: Fraction.cc Fraction.h
gcc -c Fraction.cc
fractiontest.o: fractiontest.cc
gcc -c fractiontest.cc -I${CPPUNIT_PATH}/include
ftest.o: ftest.cc
gcc -c ftest.cc -I${CPPUNIT_PATH}/include
clean:
rm -f *.o ftest
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.soleil</groupId>
<artifactId>super-pom-C-CPP-device</artifactId>
<version>RELEASE</version>
</parent>
<groupId>fr.soleil.device</groupId>
<artifactId>cppunit_YAT-${aol}-${mode}</artifactId>
<version>0.0.1</version>
<packaging>nar</packaging>
<name>cppunit_YAT</name>
<!-- use for the name of executable -->
<description>cppunit_YAT</description>
<build>
<plugins>
<plugin>
<groupId>org.freehep</groupId>
<artifactId>freehep-nar-plugin</artifactId>
<configuration>
<cpp>
<systemIncludePaths>
<systemIncludePath>/home/informatique/ica/poirier/dev/CPPUNIT/include</systemIncludePath>
</systemIncludePaths>
</cpp>
<linker>
<libs>
<lib>
<!-- CppUnit -->
<name>cppunit</name>
<type>shared</type>
<directory>/home/informatique/ica/poirier/dev/CPPUNIT/lib</directory>
</lib>
</libs>
</linker>
</configuration>
</plugin>
<plugin>
<groupId>fr.soleil.maven.plugins</groupId>
<artifactId>maven-check-plugin</artifactId>
<configuration>
<enable>false</enable>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>fr.soleil.lib</groupId>
<artifactId>YAT-${aol}-${library}-${mode}</artifactId>
<version>1.14.6-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
This diff is collapsed.
// file: cppunit_YAT.cpp
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>
int main (int argc, char* argv[])
{
// informs test-listener about testresults
CPPUNIT_NS :: TestResult testresult;
// register listener for collecting the test-results
CPPUNIT_NS :: TestResultCollector collectedresults;
testresult.addListener (&collectedresults);
// register listener for per-test progress output
CPPUNIT_NS :: BriefTestProgressListener progress;
testresult.addListener (&progress);
// insert test-suite at test-runner by registry
CPPUNIT_NS :: TestRunner testrunner;
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
testrunner.run (testresult);
// output results in compiler-format
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
compileroutputter.write ();
// ELD_DEBUG Si assez de temps, voir l'utilisation du plugin pour XML
// // Output XML for Jenkins CPPunit plugin
// std::ofstream xmlFileOut("cppunit_Essai_02_Results.xml");
// XmlOutputter xmlOut(&collectedresults, xmlFileOut);
// xmlOut.write();
// return 0 if tests were successful
return collectedresults.wasSuccessful () ? 0 : 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment