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.

DnsLabel.cpp 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Created by robin on 1/9/18.
  3. //
  4. #include <gtest/gtest.h>
  5. #include <QByteArray>
  6. #include <QString>
  7. #include "dns/QDnsLabel.h"
  8. struct DnsLabelTestParams
  9. {
  10. bool isValid;
  11. const char* hexData;
  12. quint32 pos;
  13. const char* label;
  14. };
  15. class DnsLabelTest : public ::testing::TestWithParam<DnsLabelTestParams>
  16. {
  17. };
  18. TEST_P(DnsLabelTest, parse)
  19. {
  20. auto params = GetParam();
  21. auto data = QByteArray::fromHex(params.hexData);
  22. auto label = QDns::QDnsLabel::parse(data, params.pos);
  23. if (params.isValid)
  24. {
  25. ASSERT_FALSE(label.isNull());
  26. ASSERT_STREQ(params.label, label.toStdString().c_str());
  27. }
  28. else
  29. {
  30. ASSERT_TRUE(label.isNull());
  31. }
  32. }
  33. INSTANTIATE_TEST_CASE_P(DnsLabelTestInst,
  34. DnsLabelTest,
  35. ::testing::Values(
  36. DnsLabelTestParams {false, "", 0},
  37. DnsLabelTestParams {true, "00", 0, ""},
  38. DnsLabelTestParams {true,
  39. "06676f6f676c6502667200",
  40. 0,
  41. "google.fr"
  42. },
  43. DnsLabelTestParams {true,
  44. "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3",
  45. 12,
  46. "google.fr"
  47. },
  48. DnsLabelTestParams {true,
  49. "587a8180000100010000000006676f6f676c650266720000010001c00c000100010000012c0004acd912a3",
  50. 27,
  51. "google.fr"
  52. },
  53. DnsLabelTestParams {true,
  54. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
  55. 12,
  56. "www.rthoni.com"
  57. },
  58. DnsLabelTestParams {true,
  59. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
  60. 32,
  61. "www.rthoni.com"
  62. },
  63. DnsLabelTestParams {true,
  64. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633c010c02c00010001000002580004d5f6343d",
  65. 44,
  66. "serv3.rthoni.com"
  67. },
  68. DnsLabelTestParams {false,
  69. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 c02c c02c00010001000002580004d5f6343d",
  70. 44
  71. },
  72. DnsLabelTestParams {false,
  73. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 802c c02c00010001000002580004d5f6343d",
  74. 44
  75. },
  76. DnsLabelTestParams {false,
  77. "3dcd8580000100020000000003777777067274686f6e6903636f6d0000010001c00c00050001000002580008057365727633 402c c02c00010001000002580004d5f6343d",
  78. 44
  79. }
  80. ));