Browse Source

[trac981] Tests for the NOT operator

Michal 'vorner' Vaner 14 years ago
parent
commit
2e29bef63a
2 changed files with 35 additions and 0 deletions
  1. 15 0
      src/lib/acl/logic_check.h
  2. 20 0
      src/lib/acl/tests/logic_check_test.cc

+ 15 - 0
src/lib/acl/logic_check.h

@@ -200,6 +200,21 @@ private:
     const std::string name_;
     const std::string name_;
 };
 };
 
 
+template<typename Context>
+class NotCheck : public CompoundCheck<Context> {
+public:
+    NotCheck(const boost::shared_ptr<Check<Context> >& expr) {
+
+    }
+    virtual typename CompoundCheck<Context>::Checks getSubexpressions() const {
+
+    }
+    virtual bool matches(const Context& context) const {
+    }
+private:
+    const boost::shared_ptr<Check<Context> > expr_;
+};
+
 }
 }
 }
 }
 
 

+ 20 - 0
src/lib/acl/tests/logic_check_test.cc

@@ -242,4 +242,24 @@ TEST_F(LogicCreatorTest, nested) {
     log_.checkFirst(2);
     log_.checkFirst(2);
 }
 }
 
 
+void notTest(bool value) {
+    NotCheck<Log> notOp(shared_ptr<Check<Log> >(new ConstCheck(value, 0)));
+    Log log;
+    // It returns negated value
+    EXPECT_EQ(!value, notOp.matches(log));
+    // And runs the only one thing there
+    log.checkFirst(1);
+    // Check the getSubexpressions does sane things
+    ASSERT_EQ(1, notOp.getSubexpressions().size());
+    EXPECT_EQ(value, notOp.getSubexpressions()[0]->matches(log));
+}
+
+TEST(Not, trueValue) {
+    notTest(true);
+}
+
+TEST(Not, trueValue) {
+    notTest(true);
+}
+
 }
 }