// // Created by robin on 1/9/18. // #include #include #include #include "dns/QDnsLabel.h" struct DnsLabelParseTestParams { bool isValid; const char* hexData; quint32 pos; const char* label; }; class DnsLabelParseTest : public ::testing::TestWithParam { }; TEST_P(DnsLabelParseTest, parse) { auto params = GetParam(); auto data = QByteArray::fromHex(params.hexData); auto label = QDns::QDnsLabel::parse(data, params.pos); if (params.isValid) { ASSERT_FALSE(label.isNull()); ASSERT_STREQ(params.label, label.toStdString().c_str()); } else { ASSERT_TRUE(label.isNull()); } } INSTANTIATE_TEST_CASE_P(DnsLabelParseTestInst, DnsLabelParseTest, ::testing::Values( DnsLabelParseTestParams {false, "", 0}, DnsLabelParseTestParams {true, "00", 0, ""}, DnsLabelParseTestParams {true, "06676f6f676c6502667200", 0, "google.fr" }, DnsLabelParseTestParams {true, "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3", 12, "google.fr" }, DnsLabelParseTestParams {true, "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3", 27, "google.fr" }, DnsLabelParseTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 12, "www.rthoni.com" }, DnsLabelParseTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 32, "www.rthoni.com" }, DnsLabelParseTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 44, "serv3.rthoni.com" }, DnsLabelParseTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 c02c c02c00010001000002580004d5f6343d", 44 }, DnsLabelParseTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 802c c02c00010001000002580004d5f6343d", 44 }, DnsLabelParseTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 402c c02c00010001000002580004d5f6343d", 44 } )); struct DnsLabelSerializeTestParams { const char* label; const char* hexData; }; class DnsLabelSerializeTest : public ::testing::TestWithParam { }; TEST_P(DnsLabelSerializeTest, parse) { auto params = GetParam(); auto label = QDns::QDnsLabel::serialize(params.label); auto data = QByteArray::fromHex(params.hexData); ASSERT_EQ(label, data); } INSTANTIATE_TEST_CASE_P(DnsLabelSerializeTestInst, DnsLabelSerializeTest, ::testing::Values( DnsLabelSerializeTestParams {"", "00"}, DnsLabelSerializeTestParams {"com", "03636f6d00"}, DnsLabelSerializeTestParams {"fr", "02667200"}, DnsLabelSerializeTestParams {"google.fr", "06676f6f676c6502667200"}, DnsLabelSerializeTestParams {"www.rthoni.com", "03777777067274686f6e6903636f6d00"} ));