// // Created by robin on 1/9/18. // #include #include #include #include "dns/QDnsLabel.h" struct DnsLabelTestParams { bool isValid; const char* hexData; quint32 pos; const char* label; }; class DnsLabelTest : public ::testing::TestWithParam { }; TEST_P(DnsLabelTest, 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(DnsLabelTestInst, DnsLabelTest, ::testing::Values( DnsLabelTestParams {false, "", 0}, DnsLabelTestParams {true, "00", 0, ""}, DnsLabelTestParams {true, "06676f6f676c6502667200", 0, "google.fr" }, DnsLabelTestParams {true, "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3", 12, "google.fr" }, DnsLabelTestParams {true, "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3", 27, "google.fr" }, DnsLabelTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 12, "www.rthoni.com" }, DnsLabelTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 32, "www.rthoni.com" }, DnsLabelTestParams {true, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d", 44, "serv3.rthoni.com" }, DnsLabelTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 c02c c02c00010001000002580004d5f6343d", 44 }, DnsLabelTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 802c c02c00010001000002580004d5f6343d", 44 }, DnsLabelTestParams {false, "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 402c c02c00010001000002580004d5f6343d", 44 } ));