main.cpp 1.62 KB
//#include <iostream>

#include <stdio.h>
#include <string.h>

#include "cppunit/TestResult.h"
#include "cppunit/TestResultCollector.h"
#include "cppunit/TestRunner.h"
#include "cppunit/extensions/TestFactoryRegistry.h"
#include "cppunit/CompilerOutputter.h"

#include "Common/TREPS_kernel_config.h"
#include "Application/Application.h"

//path to TREPS application config file
#define APP_CONF_FILE "config/app.config"

using namespace std;
using namespace CppUnit;
using namespace TREPS::Application;

int main(int argc, char *argv[])
{
	if ((argc == 2) && (strcmp(argv[1],"unittest") == 0))
	{
		cout << "Run unit tests : " << endl;

		//Init Application
		ApplicationClass *app = ApplicationClass::getInstance();

		if (!app->init(APP_CONF_FILE))
		{
			app->kill();
			return 1;
		}

		//run unit tests
		TestResult testResult;

		TestResultCollector collectedResults;
		testResult.addListener(&collectedResults);

		TestRunner testRunner;
		testRunner.addTest(TestFactoryRegistry::getRegistry().makeTest());
		testRunner.run(testResult);

		CompilerOutputter compilerOutPutter(&collectedResults, std::cerr);
		compilerOutPutter.write();

		app->kill();

		return collectedResults.wasSuccessful() ? 0 : 1;
	}
	else if ((argc == 2) && (strcmp(argv[1],"-v") == 0))
	{
		cout << TREPS_KERNEL_VERSION << endl;
		return 0;
	}

	//Init Application
	ApplicationClass *app = ApplicationClass::getInstance();

	if (!app->init(APP_CONF_FILE))
	{
		app->kill();
		return 1;
	}

	//Run the request
	if (!app->run(argc,argv))
	{
		app->kill();
		return 1;
	}
	
	app->kill();
	
	return 0;
}