1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // Created by robin on 1/10/18.
- //
-
- #include <gtest/gtest.h>
- #include <QByteArray>
- #include <QString>
-
- #include "dns/QDnsPacket.h"
-
- struct DnsPacketParseTestParams
- {
- bool isValid;
- const char* hexData;
- };
-
- class DnsPacketParseTest : public ::testing::TestWithParam<DnsPacketParseTestParams>
- {
- };
-
- TEST_P(DnsPacketParseTest, parse)
- {
- auto params = GetParam();
- auto data = QByteArray::fromHex(params.hexData);
- auto packet = QDns::QDnsPacket::parse(data);
-
- ASSERT_EQ(packet.isValid(), params.isValid);
-
- if (packet.isValid())
- {
- // TODO improve tests
- }
- }
-
- INSTANTIATE_TEST_CASE_P(DnsPacketParseTestInst,
- DnsPacketParseTest,
- ::testing::Values(
- DnsPacketParseTestParams {false, ""},
- DnsPacketParseTestParams {true, "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d"},
- DnsPacketParseTestParams {true, "1c580100000100000000000003777777067274686f6e6903636f6d0000010001"},
- DnsPacketParseTestParams {true, "42c3818000010001000000000377777706676f6f676c650266720000010001c00c000100010000012c0004d83ad3a3"},
- DnsPacketParseTestParams {true, "42c3010000010000000000000377777706676f6f676c650266720000010001"},
- DnsPacketParseTestParams {true, "07298180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd913e3"},
- DnsPacketParseTestParams {true, "07290100000100000000000006676f6f676c650266720000010001"},
- DnsPacketParseTestParams {true, "e1bc818000010000000100000266720000010001c00c0006000100000e100030086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518"},
- DnsPacketParseTestParams {true, "e1bc010000010000000000000266720000010001"}
- ));
-
- struct DnsPacketSerializeTestParams
- {
- const char* hexData1;
- const char* hexData2;
- };
-
- class DnsPacketSerializeTest : public ::testing::TestWithParam<DnsPacketSerializeTestParams>
- {
- };
-
- TEST_P(DnsPacketSerializeTest, parse)
- {
- auto params = GetParam();
- auto data1 = QByteArray::fromHex(params.hexData1);
- auto packet = QDns::QDnsPacket::parse(data1);
-
- // TODO improve tests
- ASSERT_EQ(packet.serialize().toHex(), QString(params.hexData2).remove(" "));
- }
-
- INSTANTIATE_TEST_CASE_P(DnsPacketSerializeTestInst,
- DnsPacketSerializeTest,
- ::testing::Values(
- DnsPacketSerializeTestParams {
- "07290100000100000000000006676f6f676c650266720000010001",
- "07290100000100000000000006676f6f676c650266720000010001"
- },
- DnsPacketSerializeTestParams {
- "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
- "1c588580000100020000000003777777067274686f6e6903636f6d000001000103777777067274686f6e6903636f6d0000050001000002580008057365727633c010057365727633067274686f6e6903636f6d0000010001000002580004d5f6343d"
- }
- ));
|