hash_key_unittest.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2010 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. // $Id$
  15. #include <algorithm>
  16. #include <string>
  17. #include <vector>
  18. #include <gtest/gtest.h>
  19. #include <boost/lexical_cast.hpp>
  20. #include "../hash_key.h"
  21. #include <dns/rrclass.h>
  22. using namespace std;
  23. using namespace isc::dns;
  24. namespace isc {
  25. namespace nsas {
  26. /// \brief Test Fixture Class
  27. class HashKeyTest : public ::testing::Test {
  28. };
  29. // Test of the constructor
  30. TEST_F(HashKeyTest, Constructor) {
  31. // Basic constructor
  32. string test1("ABCDEF");
  33. HashKey key1(test1.c_str(), test1.size(), RRClass::IN());
  34. EXPECT_EQ(key1.key, test1.c_str());
  35. EXPECT_EQ(key1.keylen, test1.size());
  36. EXPECT_EQ(key1.class_code, RRClass::IN());
  37. // String constructor
  38. string test2("uvwxyz");
  39. HashKey key2(test2, RRClass::CH());
  40. EXPECT_EQ(key2.key, test2.c_str());
  41. EXPECT_EQ(key2.keylen, test2.size());
  42. EXPECT_EQ(key2.class_code, RRClass::CH());
  43. }
  44. // Equality check
  45. TEST_F(HashKeyTest, Equality) {
  46. string test1("abcdef123"); // Simple string
  47. string test2("abcdef123"); // Same key, different object
  48. string test3("AbCdEf123"); // Same key, different case (unequal)
  49. string test4("ABCDE123"); // Different key (almost same)
  50. string test5("uvwxyz987"); // Different key
  51. EXPECT_TRUE(HashKey(test1, RRClass::IN()) == HashKey(test1,
  52. RRClass::IN())); // Same key and class
  53. EXPECT_FALSE(HashKey(test1, RRClass::IN()) == HashKey(test1,
  54. RRClass::CH())); // Different class
  55. EXPECT_TRUE(HashKey(test1, RRClass::CH()) == HashKey(test2,
  56. RRClass::CH())); // Same value key/class
  57. EXPECT_FALSE(HashKey(test1, RRClass::CH()) == HashKey(test2,
  58. RRClass::IN()));
  59. EXPECT_TRUE(HashKey(test1, RRClass::HS()) == HashKey(test3,
  60. RRClass::HS())); // Same key
  61. EXPECT_FALSE(HashKey(test1, RRClass::HS()) == HashKey(test3,
  62. RRClass::IN()));
  63. EXPECT_FALSE(HashKey(test1, RRClass::IN()) == HashKey(test4,
  64. RRClass::IN()));
  65. EXPECT_FALSE(HashKey(test1, RRClass::IN()) == HashKey(test5,
  66. RRClass::IN()));
  67. }
  68. } // namespace nsas
  69. } // namespace isc