BIND 10 track1914, updated. 1455f670ced8213e01848e24e3a2d994ed16b74d [1914] More tests for matching

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 17 17:44:44 UTC 2012


The branch, track1914 has been updated
       via  1455f670ced8213e01848e24e3a2d994ed16b74d (commit)
      from  6d4b2e6b54ae93bcd438e253573b62c11535b436 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1455f670ced8213e01848e24e3a2d994ed16b74d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu May 17 19:44:07 2012 +0200

    [1914] More tests for matching
    
    Check that we can wildcard match commands and replies.
    Check that we don't match what we shouldn't.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/config/tests/ccsession_unittests.cc |  149 +++++++++++++++++++--------
 1 files changed, 105 insertions(+), 44 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/config/tests/ccsession_unittests.cc b/src/lib/config/tests/ccsession_unittests.cc
index 7762544..a3ff1c5 100644
--- a/src/lib/config/tests/ccsession_unittests.cc
+++ b/src/lib/config/tests/ccsession_unittests.cc
@@ -726,6 +726,7 @@ protected:
         // This is just to make sure the messages get through the fake
         // session.
         session.subscribe("test group");
+        session.subscribe("other group");
         session.subscribe("<ignored>");
         // Get rid of all unrelated stray messages
         while (session.getMsgQueue()->size() > 0) {
@@ -764,6 +765,77 @@ protected:
     ModuleCCSession mccs_;
     /// \brief The value of message on the last called callback.
     ConstElementPtr last_msg_;
+    // Shared part of the simpleCommand and similar tests.
+    void commandTest(const string& group) {
+        // Push the message inside
+        ConstElementPtr msg(el("{\"command\": [\"bla\"]}"));
+        session.addMessage(msg, "test group", "<unused>");
+        EXPECT_TRUE(mccs_.hasQueuedMsgs());
+        // Register the callback
+        registerCommand(group);
+        // But the callback should not be called yet
+        // (even if the message is there).
+        nothingCalled();
+        // But when we call the checkCommand(), it should be called.
+        mccs_.checkCommand();
+        called(0);
+        EXPECT_EQ(msg, last_msg_);
+        // But only once
+        nothingCalled();
+        // And the message should be eaten
+        EXPECT_FALSE(mccs_.hasQueuedMsgs());
+        // The callback should have been eaten as well, inserting another
+        // message will not invoke it again
+        session.addMessage(msg, "test group", "<unused>");
+        mccs_.checkCommand();
+        nothingCalled();
+    }
+    /// \brief Shared part of the simpleResponse and wildcardResponse tests.
+    void responseTest(int seq) {
+        // Push the message inside
+        ConstElementPtr msg(el("{\"result\": [0]}"));
+        session.addMessage(msg, "<ignored>", "<unused>", 1);
+        EXPECT_TRUE(mccs_.hasQueuedMsgs());
+        // Register the callback
+        registerReply(seq);
+        // But the callback should not be called yet
+        // (even if the message is there).
+        nothingCalled();
+        // But when we call the checkCommand(), it should be called.
+        mccs_.checkCommand();
+        called(0);
+        EXPECT_EQ(msg, last_msg_);
+        // But only once
+        nothingCalled();
+        // And the message should be eaten
+        EXPECT_FALSE(mccs_.hasQueuedMsgs());
+        // The callback should have been eaten as well, inserting another
+        // message will not invoke it again
+        session.addMessage(msg, "test group", "<unused>");
+        mccs_.checkCommand();
+        nothingCalled();
+    }
+    /// \brief Shared part of the noMatch* tests
+    void noMatchTest(int seq, int wanted_seq, bool is_reply) {
+        // Push the message inside
+        ConstElementPtr msg(el("{\"command\": [\"command name\"]}"));
+        session.addMessage(msg, "other group", "<unused>", seq);
+        EXPECT_TRUE(mccs_.hasQueuedMsgs());
+        // Register the callback
+        if (is_reply) {
+            registerReply(wanted_seq);
+        } else {
+            registerCommand("test group");
+        }
+        // But the callback should not be called yet
+        // (even if the message is there).
+        nothingCalled();
+        // And even not now, because it does not match.
+        mccs_.checkCommand();
+        nothingCalled();
+        // And the message should be eaten by the checkCommand
+        EXPECT_FALSE(mccs_.hasQueuedMsgs());
+    }
 private:
     /// \brief The next flag to be handed out
     int next_flag_;
@@ -782,54 +854,43 @@ private:
 
 // Test we can receive a command, without anything fancy yet
 TEST_F(AsyncReceiveCCSessionTest, simpleCommand) {
-    // Push the message inside
-    ConstElementPtr msg(el("{\"command\": [\"bla\"]}"));
-    session.addMessage(msg, "test group", "<unused>");
-    EXPECT_TRUE(mccs_.hasQueuedMsgs());
-    // Register the callback
-    registerCommand("test group");
-    // But the callback should not be called yet
-    // (even if the message is there).
-    nothingCalled();
-    // But when we call the checkCommand(), it should be called.
-    mccs_.checkCommand();
-    called(0);
-    EXPECT_EQ(msg, last_msg_);
-    // But only once
-    nothingCalled();
-    // And the message should be eaten
-    EXPECT_FALSE(mccs_.hasQueuedMsgs());
-    // The callback should have been eaten as well, inserting another
-    // message will not invoke it again
-    session.addMessage(msg, "test group", "<unused>");
-    mccs_.checkCommand();
-    nothingCalled();
+    commandTest("test group");
+}
+
+// Test we can receive a "wildcard" command - without specifying the
+// group to subscribe to. Very similar to simpleCommand test.
+TEST_F(AsyncReceiveCCSessionTest, wildcardCommand) {
+    commandTest("");
 }
 
 // Very similar to simpleCommand, but with a response message
 TEST_F(AsyncReceiveCCSessionTest, simpleResponse) {
-    // Push the message inside
-    ConstElementPtr msg(el("{\"result\": [0]}"));
-    session.addMessage(msg, "<ignored>", "<unused>", 1);
-    EXPECT_TRUE(mccs_.hasQueuedMsgs());
-    // Register the callback
-    registerReply(1);
-    // But the callback should not be called yet
-    // (even if the message is there).
-    nothingCalled();
-    // But when we call the checkCommand(), it should be called.
-    mccs_.checkCommand();
-    called(0);
-    EXPECT_EQ(msg, last_msg_);
-    // But only once
-    nothingCalled();
-    // And the message should be eaten
-    EXPECT_FALSE(mccs_.hasQueuedMsgs());
-    // The callback should have been eaten as well, inserting another
-    // message will not invoke it again
-    session.addMessage(msg, "test group", "<unused>");
-    mccs_.checkCommand();
-    nothingCalled();
+    responseTest(1);
+}
+
+// Matching a response message with wildcard
+TEST_F(AsyncReceiveCCSessionTest, wildcardResponse) {
+    responseTest(-1);
+}
+
+// Check that a wrong command message is not matched
+TEST_F(AsyncReceiveCCSessionTest, noMatchCommand) {
+    noMatchTest(-1, -1, false);
+}
+
+// Check that a wrong response message is not matched
+TEST_F(AsyncReceiveCCSessionTest, noMatchResponse) {
+    noMatchTest(2, 3, true);
+}
+
+// Check that a command will not match on a reply check and vice versa
+TEST_F(AsyncReceiveCCSessionTest, noMatchResponseAgainstCommand) {
+    // Send a command and check it is not matched as a response
+    noMatchTest(-1, -1, true);
+}
+
+TEST_F(AsyncReceiveCCSessionTest, noMatchCommandAgainstResponse) {
+    noMatchTest(2, -1, false);
 }
 
 void doRelatedLoggersTest(const char* input, const char* expected) {



More information about the bind10-changes mailing list