add netbeans project
This commit is contained in:
76
tests/nattest.cpp
Normal file
76
tests/nattest.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* File: nattest.cpp
|
||||
* Author: dev
|
||||
*
|
||||
* Created on 19.08.2015, 21:39:53
|
||||
*/
|
||||
|
||||
#include "nattest.h"
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(nattest);
|
||||
|
||||
nattest::nattest() {
|
||||
}
|
||||
|
||||
nattest::~nattest() {
|
||||
}
|
||||
|
||||
void nattest::setUp() {
|
||||
}
|
||||
|
||||
void nattest::tearDown() {
|
||||
}
|
||||
|
||||
void nattest::testIpCalcEth0() {
|
||||
Tins::IPv4Address expetedIp = deviceIpEth0;
|
||||
Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth0Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = Tins::IPv4Address("10.168.23.42");
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth1, eth0Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = Tins::IPv4Address("10.27.123.4");
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth2, eth0Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
}
|
||||
|
||||
void nattest::testIpCalcEth1() {
|
||||
Tins::IPv4Address expetedIp = Tins::IPv4Address("192.168.23.40");
|
||||
Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth1Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = deviceIpEth1;
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth1, eth1Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = Tins::IPv4Address("192.168.23.4");
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth2, eth1Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
}
|
||||
|
||||
void nattest::testIpCalcEth2() {
|
||||
Tins::IPv4Address expetedIp = Tins::IPv4Address("172.16.3.40");
|
||||
Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth2Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = Tins::IPv4Address("172.24.23.42");
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth1, eth2Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
|
||||
expetedIp = deviceIpEth2;
|
||||
resultIp = natMap.mapIPv4Address(deviceIpEth2, eth2Info);
|
||||
CPPUNIT_ASSERT_EQUAL(expetedIp, resultIp);
|
||||
}
|
||||
|
||||
void nattest::testTranslateIp() {
|
||||
Tins::EthernetII eth = Tins::EthernetII() / Tins::IP() / Tins::TCP();
|
||||
otonat::NatMap natMap = otonat::NatMap();
|
||||
natMap.handlePdu(ð);
|
||||
}
|
||||
|
||||
void nattest::testNatInterfaces() {
|
||||
CPPUNIT_ASSERT(!natMap.interfaces.empty());
|
||||
}
|
||||
|
||||
70
tests/nattest.h
Normal file
70
tests/nattest.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* File: nattest.h
|
||||
* Author: dev
|
||||
*
|
||||
* Created on 19.08.2015, 21:39:53
|
||||
*/
|
||||
|
||||
#ifndef NATTEST_H
|
||||
#define NATTEST_H
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "../src/map/natmap.h"
|
||||
#include <tins/tins.h>
|
||||
#include <vector>
|
||||
|
||||
class nattest : public CPPUNIT_NS::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(nattest);
|
||||
|
||||
CPPUNIT_TEST(testNatInterfaces);
|
||||
CPPUNIT_TEST(testIpCalcEth0);
|
||||
CPPUNIT_TEST(testIpCalcEth1);
|
||||
CPPUNIT_TEST(testIpCalcEth2);
|
||||
CPPUNIT_TEST(testTranslateIp);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
nattest();
|
||||
virtual ~nattest();
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
private:
|
||||
otonat::NatMap natMap = otonat::NatMap();
|
||||
Tins::IPv4Address deviceIpEth0 = Tins::IPv4Address("10.0.3.40");
|
||||
Tins::IPv4Address deviceIpEth1 = Tins::IPv4Address("192.168.23.42");
|
||||
Tins::IPv4Address deviceIpEth2 = Tins::IPv4Address("172.27.123.4");
|
||||
Tins::NetworkInterface::Info eth0Info = {
|
||||
.ip_addr = Tins::IPv4Address("10.0.0.2"),
|
||||
.netmask = Tins::IPv4Address("255.0.0.0"),
|
||||
.bcast_addr = Tins::IPv4Address("10.255.255.255"),
|
||||
.hw_addr = Tins::HWAddress<6>("00:00:00:00:00:01"),
|
||||
.is_up = true
|
||||
};
|
||||
|
||||
Tins::NetworkInterface::Info eth1Info = {
|
||||
.ip_addr = Tins::IPv4Address("192.168.23.42"),
|
||||
.netmask = Tins::IPv4Address("255.255.255.0"),
|
||||
.bcast_addr = Tins::IPv4Address("192.168.23.255"),
|
||||
.hw_addr = Tins::HWAddress<6>("00:00:00:00:00:02"),
|
||||
.is_up = true
|
||||
};
|
||||
|
||||
Tins::NetworkInterface::Info eth2Info = {
|
||||
.ip_addr = Tins::IPv4Address("172.16.47.11"),
|
||||
.netmask = Tins::IPv4Address("255.240.0.0"),
|
||||
.bcast_addr = Tins::IPv4Address("172.31.255.255"),
|
||||
.hw_addr = Tins::HWAddress<6>("00:00:00:00:00:03"),
|
||||
.is_up = true
|
||||
};
|
||||
|
||||
void testNatInterfaces();
|
||||
void testIpCalcEth0();
|
||||
void testIpCalcEth1();
|
||||
void testIpCalcEth2();
|
||||
void testTranslateIp();
|
||||
};
|
||||
|
||||
#endif /* NATTEST_H */
|
||||
|
||||
37
tests/nattestrunner.cpp
Normal file
37
tests/nattestrunner.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* File: nattestrunner.cpp
|
||||
* Author: dev
|
||||
*
|
||||
* Created on 19.08.2015, 21:39:53
|
||||
*/
|
||||
|
||||
#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>
|
||||
|
||||
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.
|
||||
CPPUNIT_NS::BriefTestProgressListener 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;
|
||||
}
|
||||
Reference in New Issue
Block a user