12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // Created by robin on 1/9/18.
- //
-
- #include <gtest/gtest.h>
- #include <QByteArray>
- #include <QString>
-
- #include "dns/QDnsQuery.h"
-
- struct DnsQueryTestParams
- {
- bool isValid;
- const char* hexData;
- quint32 pos;
- const char* label;
- quint16 type;
- quint16 clazz;
- };
-
- class DnsQueryTest : public ::testing::TestWithParam<DnsQueryTestParams>
- {
- };
-
- TEST_P(DnsQueryTest, parse)
- {
- auto params = GetParam();
- auto data = QByteArray::fromHex(params.hexData);
- auto query = QDns::QDnsQuery::parse(data, params.pos);
-
- ASSERT_EQ(query.isValid(), params.isValid);
-
- if (query.isValid())
- {
- ASSERT_STREQ(query.getName().toStdString().c_str(), params.label);
- ASSERT_EQ(query.getType(), params.type);
- ASSERT_EQ(query.getClass(), params.clazz);
- }
- }
-
- INSTANTIATE_TEST_CASE_P(DnsQueryTestInst,
- DnsQueryTest,
- ::testing::Values(
- DnsQueryTestParams {false, "", 0},
- DnsQueryTestParams {false, "00", 0},
- DnsQueryTestParams {true,
- "0377777706676f6f676c650266720000010001",
- 0,
- "www.google.fr",
- 1,
- 1
- },
- DnsQueryTestParams {true,
- "03777777067274686f6e6903636f6d0000030008",
- 0,
- "www.rthoni.com",
- 3,
- 8
- },
- DnsQueryTestParams {true,
- "0003777777067274686f6e6903636f6d0000030008",
- 1,
- "www.rthoni.com",
- 3,
- 8
- }
- ));
|