Commit cf6b8e44 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

started adding cppunit tests

parent 8c14bbdc
add_executable(mytest test.cpp)
target_include_directories(mytest PUBLIC $<INSTALL_INTERFACE:include>)
target_include_directories(mytest BEFORE PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
target_link_libraries(mytest sonata-admin sonata-server sonata-client)
include_directories(../include)
add_library(sonata-test Main.cpp)
target_link_libraries(sonata-test ${CPPUNIT_LIBRARIES} sonata-server sonata-admin sonata-client)
#include <fstream>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <sonata/Client.hpp>
#include <sonata/Admin.hpp>
#include <sonata/Provider.hpp>
namespace tl = thallium;
tl::engine* engine = nullptr;
int main(int argc, char** argv) {
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
// Adds the test to the list of test to run
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );
std::ofstream xmlOutFile;
if(argc >= 2) {
const char* xmlOutFileName = argv[1];
xmlOutFile.open(xmlOutFileName);
// Change the default outputter to output XML results into a file
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), xmlOutFile));
} else {
// Change the default outputter to output XML results into stderr
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), std::cerr));
}
// Initialize the thallium server
tl::engine theEngine("na+sm", THALLIUM_SERVER_MODE);
engine = &theEngine;
// Initialize the Sonata provider
sonata::Provider provider(theEngine);
// Run the tests.
bool wasSucessful = runner.run();
// Finalize the engine
theEngine.finalize();
if(argc >= 2)
xmlOutFile.close();
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment