check_test.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2011 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 <gtest/gtest.h>
  15. #include <acl/check.h>
  16. using namespace isc::acl;
  17. namespace {
  18. // This test has two function. For one, it checks the default implementations
  19. // do what they should and it makes sure the template actually compiles
  20. // (as templates are syntax-checked upon instantiation).
  21. // This is a test check that just passes the boolean it gets.
  22. class Pass : public Check<bool> {
  23. public:
  24. virtual bool matches(const bool& value) const { return (value); }
  25. };
  26. // This is a simple test compound check. It contains two Pass checks
  27. // and passes result of the first one.
  28. class First : public CompoundCheck<bool> {
  29. public:
  30. // The internal checks are public, so we can check the addresses
  31. Pass first, second;
  32. virtual Checks getSubexpressions() const {
  33. Checks result;
  34. result.push_back(&first);
  35. result.push_back(&second);
  36. return (result);
  37. }
  38. virtual bool matches(const bool& value) const {
  39. return (first.matches(value));
  40. }
  41. };
  42. TEST(Check, defaultCheckValues) {
  43. Pass p;
  44. EXPECT_EQ(Check<bool>::UNKNOWN_COST, p.cost());
  45. EXPECT_TRUE(p.matches(true));
  46. EXPECT_FALSE(p.matches(false));
  47. // The exact text is compiler dependant, but we check it returns something
  48. // and can be compiled
  49. EXPECT_FALSE(p.toText().empty());
  50. }
  51. TEST(Check, defaultCompoundValues) {
  52. First f;
  53. EXPECT_EQ(2 * Check<bool>::UNKNOWN_COST, f.cost());
  54. EXPECT_TRUE(f.pure());
  55. First::Checks c(f.getSubexpressions());
  56. ASSERT_EQ(2, c.size());
  57. EXPECT_EQ(&f.first, c[0]);
  58. EXPECT_EQ(&f.second, c[1]);
  59. }
  60. }