wiredata.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include "wiredata.h"
  15. #include <gtest/gtest.h>
  16. #include <algorithm> // for std::min
  17. #include <stdint.h>
  18. using namespace std;
  19. namespace isc {
  20. namespace util {
  21. namespace unittests {
  22. void
  23. matchWireData(const void* expected_data, size_t expected_len,
  24. const void* actual_data, size_t actual_len)
  25. {
  26. const size_t cmplen = std::min(expected_len, actual_len);
  27. for (size_t i = 0; i < cmplen; ++i) {
  28. const int ebyte = static_cast<const uint8_t*>(expected_data)[i];
  29. const int abyte = static_cast<const uint8_t*>(actual_data)[i];
  30. // Once we find a mismatch, it's quite likely that there will be many
  31. // mismatches after this point. So we stop here by using ASSERT not
  32. // to be too noisy.
  33. ASSERT_EQ(ebyte, abyte) << "Wire data mismatch at " << i << "th byte\n"
  34. << " Actual: " << abyte << "\n"
  35. << "Expected: " << ebyte << "\n";
  36. }
  37. EXPECT_EQ(expected_len, actual_len)
  38. << "Wire data mismatch in length:\n"
  39. << " Actual: " << actual_len << "\n"
  40. << "Expected: " << expected_len << "\n";
  41. }
  42. } // unittests
  43. } // util
  44. } // isc