123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // Created by robin on 1/9/18.
- //
-
- #include <gtest/gtest.h>
- #include <QByteArray>
- #include <QString>
-
- #include "dns/QDnsResourceRecord.h"
-
- struct DnsResourceRecordParseTestParams
- {
- bool isValid;
- const char* hexData;
- quint32 pos;
- const char* label;
- quint16 type;
- quint16 clazz;
- quint32 ttl;
- const char* hexData2;
- };
-
- class DnsResourceRecordParseTest : public ::testing::TestWithParam<DnsResourceRecordParseTestParams>
- {
- };
-
- TEST_P(DnsResourceRecordParseTest, parse)
- {
- auto params = GetParam();
- auto data = QByteArray::fromHex(params.hexData);
- auto rr = QDns::QDnsResourceRecord::parse(data, params.pos);
-
- ASSERT_EQ(rr.isValid(), params.isValid);
-
- if (rr.isValid())
- {
- ASSERT_STREQ(rr.getName().toStdString().c_str(), params.label);
- ASSERT_EQ(rr.getType(), params.type);
- ASSERT_EQ(rr.getClass(), params.clazz);
- ASSERT_EQ(rr.getTtl(), params.ttl);
- ASSERT_EQ(rr.getData().toHex(), QString(params.hexData2).remove(" "));
- }
- }
-
- INSTANTIATE_TEST_CASE_P(DnsResourceRecordParseTestInst,
- DnsResourceRecordParseTest,
- ::testing::Values(
- DnsResourceRecordParseTestParams {false, "", 0},
- DnsResourceRecordParseTestParams {false, "00", 0},
- DnsResourceRecordParseTestParams {true,
- "e1bc818000010000000100000266720000010001c00c0006000100000e100030086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518",
- 20,
- "fr",
- 6,
- 1,
- 3600,
- "086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518"
- },
- DnsResourceRecordParseTestParams {true,
- "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
- 32,
- "www.rthoni.com",
- 5,
- 1,
- 600,
- "057365727633c010"
- },
- DnsResourceRecordParseTestParams {true,
- "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
- 52,
- "serv3.rthoni.com",
- 1,
- 1,
- 600,
- "d5f6343d"
- }
- ));
-
- struct DnsResourceRecordSerializeTestParams
- {
- const char* hexData;
-
- const char* name;
- quint16 type;
- quint16 clazz;
- quint32 ttl;
- const char* hexData2;
- };
-
- class DnsResourceRecordSerializeTest : public ::testing::TestWithParam<DnsResourceRecordSerializeTestParams>
- {
- };
-
- TEST_P(DnsResourceRecordSerializeTest, serialize)
- {
- auto params = GetParam();
- QDns::QDnsResourceRecord rr;
-
- rr.setName(params.name);
- rr.setType(params.type);
- rr.setClass(params.clazz);
- rr.setTtl(params.ttl);
- rr.setData(QByteArray::fromHex(params.hexData2));
-
- ASSERT_EQ(rr.serialize().toHex(), QString(params.hexData).remove(" "));
- }
-
- INSTANTIATE_TEST_CASE_P(DnsResourceRecordSerializeTestInst,
- DnsResourceRecordSerializeTest,
- ::testing::Values(
- DnsResourceRecordSerializeTestParams {"026672000006000100000e100030086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518",
- "fr",
- 6,
- 1,
- 3600,
- "086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518"
- },
- DnsResourceRecordSerializeTestParams {"03777777067274686f6e6903636f6d0000050001000002580008057365727633c010",
- "www.rthoni.com",
- 5,
- 1,
- 600,
- "057365727633c010"
- }
- ));
|