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.

DnsQuery.cpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Created by robin on 1/9/18.
  3. //
  4. #include <gtest/gtest.h>
  5. #include <QByteArray>
  6. #include <QString>
  7. #include "dns/QDnsQuery.h"
  8. struct DnsQueryTestParams
  9. {
  10. bool isValid;
  11. const char* hexData;
  12. quint32 pos;
  13. const char* label;
  14. quint16 type;
  15. quint16 clazz;
  16. };
  17. class DnsQueryTest : public ::testing::TestWithParam<DnsQueryTestParams>
  18. {
  19. };
  20. TEST_P(DnsQueryTest, parse)
  21. {
  22. auto params = GetParam();
  23. auto data = QByteArray::fromHex(params.hexData);
  24. auto query = QDns::QDnsQuery::parse(data, params.pos);
  25. ASSERT_EQ(query.isValid(), params.isValid);
  26. if (query.isValid())
  27. {
  28. ASSERT_STREQ(query.getName().toStdString().c_str(), params.label);
  29. ASSERT_EQ(query.getType(), params.type);
  30. ASSERT_EQ(query.getClass(), params.clazz);
  31. }
  32. }
  33. INSTANTIATE_TEST_CASE_P(DnsQueryTestInst,
  34. DnsQueryTest,
  35. ::testing::Values(
  36. DnsQueryTestParams {false, "", 0},
  37. DnsQueryTestParams {false, "00", 0},
  38. DnsQueryTestParams {true,
  39. "0377777706676f6f676c650266720000010001",
  40. 0,
  41. "www.google.fr",
  42. 1,
  43. 1
  44. },
  45. DnsQueryTestParams {true,
  46. "03777777067274686f6e6903636f6d0000030008",
  47. 0,
  48. "www.rthoni.com",
  49. 3,
  50. 8
  51. },
  52. DnsQueryTestParams {true,
  53. "0003777777067274686f6e6903636f6d0000030008",
  54. 1,
  55. "www.rthoni.com",
  56. 3,
  57. 8
  58. }
  59. ));