add json config and updaet pkgbuild

This commit is contained in:
stubbfel
2015-11-18 23:22:09 +01:00
parent cb34c4b4f7
commit 20d477be4a
18 changed files with 492 additions and 89 deletions

58
tests/jsontest.cpp Normal file
View File

@@ -0,0 +1,58 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: jsontest.cpp
* Author: dev
*
* Created on 18.11.2015, 20:41:37
*/
#include "jsontest.h"
#include <json/json.h>
#include <json/value.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include "../src/map/NatRange.h"
#include <tins/tins.h>
CPPUNIT_TEST_SUITE_REGISTRATION(jsontest);
jsontest::jsontest() {
}
jsontest::~jsontest() {
}
void jsontest::setUp() {
}
void jsontest::tearDown() {
}
void jsontest::testReadConfig() {
std::ifstream config_doc("src/config.json", std::ifstream::binary);
Json::Value root;
config_doc >> root;
const Json::Value netcards = root;
for (Json::Value netcard : netcards) {
const std::string name = netcard.getMemberNames()[0].c_str();
const Json::Value cardMember = netcard[name];
const std::string ipStr = cardMember["rangeIpAddr"].asString();
const std::string maskStr = cardMember["rangeNetmask"].asString();
CPPUNIT_ASSERT(name == "vboxnet0" || name == "vboxnet1");
CPPUNIT_ASSERT(ipStr == "10.0.0.0" || ipStr == "172.27.0.0");
CPPUNIT_ASSERT(maskStr == "255.255.240.0" || maskStr == "255.255.0.0");
const Tins::NetworkInterface net(name);
const otonat::NatRange netRange(net, Tins::IPv4Address(ipStr), Tins::IPv4Address(maskStr));
CPPUNIT_ASSERT(name == netRange.interface.name());
CPPUNIT_ASSERT(ipStr == netRange.rangeIpAddr.to_string());
CPPUNIT_ASSERT(maskStr == netRange.rangeNetmask.to_string());
}
}

37
tests/jsontest.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: jsontest.h
* Author: dev
*
* Created on 18.11.2015, 20:41:37
*/
#ifndef JSONTEST_H
#define JSONTEST_H
#include <cppunit/extensions/HelperMacros.h>
class jsontest : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST_SUITE(jsontest);
CPPUNIT_TEST(testReadConfig);
CPPUNIT_TEST_SUITE_END();
public:
jsontest();
virtual ~jsontest();
void setUp();
void tearDown();
private:
void testReadConfig();
};
#endif /* JSONTEST_H */

89
tests/jsontestrunner.cpp Normal file
View File

@@ -0,0 +1,89 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: newtestrunner.cpp
* Author: dev
*
* Created on 18.11.2015, 20:41:38
*/
// CppUnit site http://sourceforge.net/projects/cppunit/files
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/Test.h>
#include <cppunit/TestFailure.h>
#include <cppunit/portability/Stream.h>
class ProgressListener : public CPPUNIT_NS::TestListener {
public:
ProgressListener()
: m_lastTestFailed(false) {
}
~ProgressListener() {
}
void startTest(CPPUNIT_NS::Test *test) {
CPPUNIT_NS::stdCOut() << test->getName();
CPPUNIT_NS::stdCOut() << "\n";
CPPUNIT_NS::stdCOut().flush();
m_lastTestFailed = false;
}
void addFailure(const CPPUNIT_NS::TestFailure &failure) {
CPPUNIT_NS::stdCOut() << " : " << (failure.isError() ? "error" : "assertion");
m_lastTestFailed = true;
}
void endTest(CPPUNIT_NS::Test *test) {
if (!m_lastTestFailed)
CPPUNIT_NS::stdCOut() << " : OK";
CPPUNIT_NS::stdCOut() << "\n";
}
private:
/// Prevents the use of the copy constructor.
ProgressListener(const ProgressListener &copy);
/// Prevents the use of the copy operator.
void operator=(const ProgressListener &copy);
private:
bool m_lastTestFailed;
};
int main() {
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener(&result);
// Add a listener that print dots as test run.
ProgressListener progress;
controller.addListener(&progress);
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
runner.run(controller);
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
outputter.write();
return result.wasSuccessful() ? 0 : 1;
}