Changeset - a00d7859f663
[Not reviewed]
0 4 3
HanzZ - 14 years ago 2011-08-21 13:41:23
hanzz.k@gmail.com
Dummy unit test
7 files changed with 105 insertions and 3 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -137,6 +137,13 @@ ADD_SUBDIRECTORY(backends)
 
#ADD_SUBDIRECTORY(tests)
 
ADD_SUBDIRECTORY(spectrum_manager)
 

	
 
if (CPPUNIT_FOUND)
 
	message("tests             : yes")
 
	include_directories(${CPPUNIT_INCLUDE_DIR})
 
else()
 
	message("tests             : no (install CPPUnit)")
 
endif()
 

	
 
if(DOXYGEN_FOUND)
 
	message("Docs              : yes")
 
	ADD_SUBDIRECTORY(docs)
include/transport/config.h
Show inline comments
 
@@ -62,6 +62,10 @@ class Config {
 
		/// \param opts extra options which will be recognized by a parser
 
		bool load(const std::string &configfile, boost::program_options::options_description &opts);
 

	
 
		bool load(std::istream &ifs, boost::program_options::options_description &opts);
 

	
 
		bool load(std::istream &ifs);
 

	
 
		/// Loads data from config file.
 
		
 
		/// This function loads only config variables needed by libtransport.
src/CMakeLists.txt
Show inline comments
 
@@ -7,6 +7,14 @@ if (PROTOBUF_FOUND)
 
	PROTOBUF_GENERATE_CPP(PROTOBUF_SRC PROTOBUF_HDRS "pbnetwork.proto")
 
endif()
 
 
if (CPPUNIT_FOUND)
 
	FILE(GLOB SRC_TEST tests/*.cpp)
 
 
	ADD_EXECUTABLE(libtransport_test ${SRC_TEST})
 
 
	target_link_libraries(libtransport_test transport ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES})
 
endif()
 
 
# SOURCE_GROUP(headers FILES ${HEADERS})
 
 
ADD_LIBRARY(transport SHARED ${HEADERS} ${SRC} ${SWIFTEN_SRC} ${PROTOBUF_SRC} ${PROTOBUF_HDRS})
src/config.cpp
Show inline comments
 
@@ -26,11 +26,19 @@ using namespace boost::program_options;
 
namespace Transport {
 

	
 
bool Config::load(const std::string &configfile, boost::program_options::options_description &opts) {
 
	m_unregistered.clear();
 
	std::ifstream ifs(configfile.c_str());
 
	if (!ifs.is_open())
 
		return false;
 

	
 
	m_file = configfile;
 
	bool ret = load(ifs, opts);
 
	ifs.close();
 

	
 
	return ret;
 
}
 

	
 
bool Config::load(std::istream &ifs, boost::program_options::options_description &opts) {
 
	m_unregistered.clear();
 
	opts.add_options()
 
		("service.jid", value<std::string>()->default_value(""), "Transport Jabber ID")
 
		("service.server", value<std::string>()->default_value(""), "Server to connect to")
 
@@ -84,13 +92,16 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 
	store(parsed, m_variables);
 
	notify(m_variables);
 

	
 
	m_file = configfile;
 

	
 
	onConfigReloaded();
 

	
 
	return true;
 
}
 

	
 
bool Config::load(std::istream &ifs) {
 
	options_description opts("Transport options");
 
	return load(ifs, opts);
 
}
 

	
 
bool Config::load(const std::string &configfile) {
 
	options_description opts("Transport options");
 
	return load(configfile, opts);
src/tests/main.cpp
Show inline comments
 
new file 100644
 
#include "main.h"
 
#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 ();
 

	
 
	// return 0 if tests were successful
 
	return collectedresults.wasSuccessful () ? 0 : 1;
 
}
src/tests/main.h
Show inline comments
 
new file 100644
 
#ifndef TESTS_MAIN_H
 
#define TESTS_MAIN_H
 
#include <cppunit/TestFixture.h>
 
#include <cppunit/extensions/HelperMacros.h>
 

	
 
#endif
src/tests/userregistry.cpp
Show inline comments
 
new file 100644
 
#include "transport/userregistry.h"
 
#include "transport/config.h"
 
#include <cppunit/TestFixture.h>
 
#include <cppunit/extensions/HelperMacros.h>
 

	
 
using namespace Transport;
 

	
 
class UserRegistryTest : public CPPUNIT_NS :: TestFixture {
 
	CPPUNIT_TEST_SUITE (UserRegistryTest);
 
// 	CPPUNIT_TEST (storeBuddies);
 
// 	CPPUNIT_TEST (storeBuddiesRemove);
 
	CPPUNIT_TEST_SUITE_END ();
 

	
 
	public:
 
		void setUp (void) {
 
			std::istringstream ifs;
 
			cfg = new Config();
 
			cfg->load(ifs);
 
			userRegistry = new UserRegistry(cfg);
 
		}
 

	
 
		void tearDown (void) {
 
			delete userRegistry;
 
			delete cfg;
 
		}
 

	
 
	private:
 
		UserRegistry *userRegistry;
 
		Config *cfg;
 

	
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (UserRegistryTest);
0 comments (0 inline, 0 general)