add test src

This commit is contained in:
stubbfel
2017-02-16 00:55:04 +01:00
parent 9b65fca64a
commit 86ff923e8a
11 changed files with 20199 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
#include "fakeit.hpp"
#include "tins/ethernetII.h"
#include <tins/ip.h>
#include <tins/ipv6.h>
#include <tins/ip_address.h>
#include <tins/ipv6_address.h>
#include <tins/tcp.h>
#include "Ip6ToIp4PacketHandler.h"
#include "IpAddressTranslator.h"
using namespace fakeit;
namespace TestIp6ToIp4PacketHandler
{
Tins::PDU * currentInputPdu = nullptr;
void compareToInputPdu(const Tins::PDU & answerPdu)
{
REQUIRE(currentInputPdu != nullptr);
REQUIRE(answerPdu.find_pdu<Tins::IPv6>() == nullptr);
const Tins::IP * ip = answerPdu.find_pdu<Tins::IP>();
REQUIRE(ip != nullptr);
const Tins::IPv6 * ip6 = currentInputPdu->find_pdu<Tins::IPv6>();
REQUIRE(ip6 != nullptr);
REQUIRE(ip->src_addr() == Tins::IPv4Address(IpAddressTranslator::toIpv4AddressBytes(ip6->src_addr())));
REQUIRE(ip->dst_addr() == Tins::IPv4Address(IpAddressTranslator::toIpv4AddressBytes(ip6->dst_addr())));
REQUIRE(answerPdu.inner_pdu() != nullptr);
const Tins::EthernetII * currEth = currentInputPdu->find_pdu<Tins::EthernetII>();
if (currEth == nullptr)
{
return;
}
const Tins::EthernetII * answerEth = answerPdu.find_pdu<Tins::EthernetII>();
REQUIRE(answerEth->src_addr() == currEth->src_addr());
REQUIRE(answerEth->dst_addr() == currEth->dst_addr());
}
}
TEST_CASE( "test Ip6ToIp4PacketHandler", "[Ip6ToIp4PacketHandler]" ) {
Ip6ToIp4PacketHandler handler;
Mock<IPacketHandler> mockHandler;
When(Method(mockHandler, handle)).AlwaysDo([] (IN const Tins::PDU & pdu,...)
{
TestIp6ToIp4PacketHandler::compareToInputPdu(pdu);
return true;
});
Tins::EthernetII pkt = Tins::EthernetII() / Tins::IPv6() / Tins::TCP();
TestIp6ToIp4PacketHandler::currentInputPdu = &pkt;
REQUIRE(handler.handle(pkt, nullptr) == false);
REQUIRE(handler.handle(pkt, &mockHandler.get()) == true);
Verify(Method(mockHandler, handle)).Once();
pkt = Tins::EthernetII("11:22:33:44:55:66", "66:55:44:33:22:11") / Tins::IPv6("::1", "::2") / Tins::TCP();
REQUIRE(handler.handle(pkt, &mockHandler.get()) == true);
Verify(Method(mockHandler, handle)).Twice();
}