123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // Created by robin on 1/9/18.
- //
-
- #include <gtest/gtest.h>
- #include <QByteArray>
- #include <QString>
-
- #include "dns/QDnsQuery.h"
-
- struct DnsQueryParseTestParams
- {
- bool isValid;
- const char* hexData;
- quint32 pos;
- const char* label;
- quint16 type;
- quint16 clazz;
- };
-
- class DnsQueryParseTest : public ::testing::TestWithParam<DnsQueryParseTestParams>
- {
- };
-
- TEST_P(DnsQueryParseTest, 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(DnsQueryParseTestInst,
- DnsQueryParseTest,
- ::testing::Values(
- DnsQueryParseTestParams {false, "", 0},
- DnsQueryParseTestParams {false, "00", 0},
- DnsQueryParseTestParams {true,
- "0377777706676f6f676c650266720000010001",
- 0,
- "www.google.fr",
- 1,
- 1
- },
- DnsQueryParseTestParams {true,
- "03777777067274686f6e6903636f6d0000030008",
- 0,
- "www.rthoni.com",
- 3,
- 8
- },
- DnsQueryParseTestParams {true,
- "0003777777067274686f6e6903636f6d0000030008",
- 1,
- "www.rthoni.com",
- 3,
- 8
- }
- ));
-
-
-
- struct DnsQuerySerializeTestParams
- {
- const char* hexData;
-
- const char* name;
- quint16 type;
- quint16 clazz;
- };
-
- class DnsQuerySerializeTest : public ::testing::TestWithParam<DnsQuerySerializeTestParams>
- {
- };
-
- TEST_P(DnsQuerySerializeTest, serialize)
- {
- auto params = GetParam();
- auto data = QByteArray::fromHex(params.hexData);
- QDns::QDnsQuery query;
-
- query.setName(params.name);
- query.setType(params.type);
- query.setClass(params.clazz);
-
- ASSERT_EQ(query.serialize().toHex(), QString(params.hexData).remove(" "));
- }
-
- INSTANTIATE_TEST_CASE_P(DnsQuerySerializeTestInst,
- DnsQuerySerializeTest,
- ::testing::Values(
- DnsQuerySerializeTestParams {"0266720000020008",
- "fr",
- 2,
- 8
- },
- DnsQuerySerializeTestParams {"06676f6f676c650266720000010001",
- "google.fr",
- 1,
- 1
- },
- DnsQuerySerializeTestParams {"03777777067274686f6e6903636f6d0000010001",
- "www.rthoni.com",
- 1,
- 1
- }
- ));
|