You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DnsPacket.cpp 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // Created by robin on 1/10/18.
  3. //
  4. #include <gtest/gtest.h>
  5. #include <QByteArray>
  6. #include <QString>
  7. #include "dns/QDnsPacket.h"
  8. struct DnsPacketParseTestParams
  9. {
  10. bool isValid;
  11. const char* hexData;
  12. };
  13. class DnsPacketParseTest : public ::testing::TestWithParam<DnsPacketParseTestParams>
  14. {
  15. };
  16. TEST_P(DnsPacketParseTest, parse)
  17. {
  18. auto params = GetParam();
  19. auto data = QByteArray::fromHex(params.hexData);
  20. auto packet = QDns::QDnsPacket::parse(data);
  21. ASSERT_EQ(packet.isValid(), params.isValid);
  22. if (packet.isValid())
  23. {
  24. // TODO improve tests
  25. }
  26. }
  27. INSTANTIATE_TEST_CASE_P(DnsPacketParseTestInst,
  28. DnsPacketParseTest,
  29. ::testing::Values(
  30. DnsPacketParseTestParams {false, ""},
  31. DnsPacketParseTestParams {true, "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d"},
  32. DnsPacketParseTestParams {true, "1c580100000100000000000003777777067274686f6e6903636f6d0000010001"},
  33. DnsPacketParseTestParams {true, "42c3818000010001000000000377777706676f6f676c650266720000010001c00c000100010000012c0004d83ad3a3"},
  34. DnsPacketParseTestParams {true, "42c3010000010000000000000377777706676f6f676c650266720000010001"},
  35. DnsPacketParseTestParams {true, "07298180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd913e3"},
  36. DnsPacketParseTestParams {true, "07290100000100000000000006676f6f676c650266720000010001"},
  37. DnsPacketParseTestParams {true, "e1bc818000010000000100000266720000010001c00c0006000100000e100030086e736d6173746572036e6963c00c0a686f73746d6173746572c029849e46cf00000e10000007080036ee8000001518"},
  38. DnsPacketParseTestParams {true, "e1bc010000010000000000000266720000010001"}
  39. ));
  40. struct DnsPacketSerializeTestParams
  41. {
  42. const char* hexData1;
  43. const char* hexData2;
  44. };
  45. class DnsPacketSerializeTest : public ::testing::TestWithParam<DnsPacketSerializeTestParams>
  46. {
  47. };
  48. TEST_P(DnsPacketSerializeTest, parse)
  49. {
  50. auto params = GetParam();
  51. auto data1 = QByteArray::fromHex(params.hexData1);
  52. auto packet = QDns::QDnsPacket::parse(data1);
  53. // TODO improve tests
  54. ASSERT_EQ(packet.serialize().toHex(), QString(params.hexData2).remove(" "));
  55. }
  56. INSTANTIATE_TEST_CASE_P(DnsPacketSerializeTestInst,
  57. DnsPacketSerializeTest,
  58. ::testing::Values(
  59. DnsPacketSerializeTestParams {
  60. "07290100000100000000000006676f6f676c650266720000010001",
  61. "07290100000100000000000006676f6f676c650266720000010001"
  62. },
  63. DnsPacketSerializeTestParams {
  64. "1c588580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
  65. "1c588580000100020000000003777777067274686f6e6903636f6d000001000103777777067274686f6e6903636f6d0000050001000002580008057365727633c010057365727633067274686f6e6903636f6d0000010001000002580004d5f6343d"
  66. }
  67. ));