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
 
@@ -134,12 +134,19 @@ ADD_SUBDIRECTORY(include)
 
#ADD_SUBDIRECTORY(examples)
 
ADD_SUBDIRECTORY(spectrum)
 
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)
 
else(DOXYGEN_FOUND)
 
	message("Docs              : no (install doxygen)")
 
endif(DOXYGEN_FOUND)
include/transport/config.h
Show inline comments
 
@@ -59,12 +59,16 @@ class Config {
 
		/// You can pass your extra options which will be recognized by
 
		/// the parser using opts parameter.
 
		/// \param configfile path to config file
 
		/// \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.
 
		/// \see load(const std::string &, boost::program_options::options_description &)
 
		/// \param configfile path to config file
 
		bool load(const std::string &configfile);
src/CMakeLists.txt
Show inline comments
 
@@ -4,12 +4,20 @@ FILE(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp)
 
FILE(GLOB HEADERS ../include/transport/*.h)
 
 
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})
 
ADD_DEFINITIONS(-fPIC)
 
 
TARGET_LINK_LIBRARIES(transport ${Boost_LIBRARIES} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} -lpopt)
src/config.cpp
Show inline comments
 
@@ -23,17 +23,25 @@
 

	
 
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")
 
		("service.password", value<std::string>()->default_value(""), "Password used to auth the server")
 
		("service.port", value<int>()->default_value(0), "Port the server is listening on")
 
		("service.backend", value<std::string>()->default_value("libpurple_backend"), "Backend")
 
@@ -81,19 +89,22 @@ 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);
 
}
 

	
 
bool Config::reload() {
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)