1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // Created by robin on 1/9/18.
- //
-
- #include <gtest/gtest.h>
- #include <QByteArray>
- #include <QString>
-
- #include "dns/QDnsLabel.h"
-
- struct DnsLabelTestParams
- {
- bool isValid;
- const char* hexData;
- quint32 pos;
- const char* label;
- };
-
- class DnsLabelTest : public ::testing::TestWithParam<DnsLabelTestParams>
- {
- };
-
- 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
- }
- ));
|