--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/traced-callback-test-suite.cc Tue Sep 29 20:45:27 2009 -0700
@@ -0,0 +1,125 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "test.h"
+#include "traced-callback.h"
+
+using namespace ns3;
+
+class BasicTracedCallbackTestCase : public TestCase
+{
+public:
+ BasicTracedCallbackTestCase ();
+ virtual ~BasicTracedCallbackTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+
+ void CbOne (uint8_t a, double b);
+ void CbTwo (uint8_t a, double b);
+
+ bool m_one;
+ bool m_two;
+};
+
+BasicTracedCallbackTestCase::BasicTracedCallbackTestCase ()
+ : TestCase ("Check basic TracedCallback operation")
+{
+}
+
+void
+BasicTracedCallbackTestCase::CbOne (uint8_t a, double b)
+{
+ m_one = true;
+}
+
+void
+BasicTracedCallbackTestCase::CbTwo (uint8_t a, double b)
+{
+ m_two = true;
+}
+
+bool
+BasicTracedCallbackTestCase::DoRun (void)
+{
+ //
+ // Create a traced callback and connect it up to our target methods. All that
+ // these methods do is to set corresponding member variables m_one and m_two.
+ //
+ TracedCallback<uint8_t, double> trace;
+
+ //
+ // Connect both callbacks to their respective test methods. If we hit the
+ // trace, both callbacks should be called and the two variables should be set
+ // to true.
+ //
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ //
+ // If we now disconnect callback one then only callback two should be called.
+ //
+ trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ //
+ // If we now disconnect callback two then neither callback should be called.
+ //
+ trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, false, "Callback CbTwo unexpectedly called");
+
+ //
+ // If we connect them back up, then both callbacks should be called.
+ //
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ return GetErrorStatus ();
+}
+
+class TracedCallbackTestSuite : public TestSuite
+{
+public:
+ TracedCallbackTestSuite ();
+};
+
+TracedCallbackTestSuite::TracedCallbackTestSuite ()
+ : TestSuite ("traced-callback", UNIT)
+{
+ AddTestCase (new BasicTracedCallbackTestCase);
+}
+
+TracedCallbackTestSuite tracedCallbackTestSuite;
--- a/src/core/traced-callback.cc Tue Sep 29 19:58:29 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "traced-callback.h"
-
-#ifdef RUN_SELF_TESTS
-
-#include "test.h"
-
-namespace ns3 {
-
-class TracedCallbackTest : public Test
-{
-public:
- TracedCallbackTest ();
- virtual ~TracedCallbackTest ();
- virtual bool RunTests (void);
-private:
- void CbOne (uint8_t a, double b);
- void CbTwo (uint8_t a, double b);
-
- bool m_one;
- bool m_two;
-};
-
-TracedCallbackTest::TracedCallbackTest ()
- : Test ("TracedCallback")
-{}
-TracedCallbackTest::~TracedCallbackTest ()
-{}
-void
-TracedCallbackTest::CbOne (uint8_t a, double b)
-{
- m_one = true;
-}
-void
-TracedCallbackTest::CbTwo (uint8_t a, double b)
-{
- m_two = true;
-}
-bool
-TracedCallbackTest::RunTests (void)
-{
- bool result = true;
-
- TracedCallback<uint8_t,double> trace;
- trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
- trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT (m_one);
- NS_TEST_ASSERT (m_two);
-
- trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT (!m_one);
- NS_TEST_ASSERT (m_two);
- trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT (!m_one);
- NS_TEST_ASSERT (!m_two);
-
- trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
- trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT (m_one);
- NS_TEST_ASSERT (m_two);
-
- return result;
-}
-
-static TracedCallbackTest g_eventTraceTest;
-
-}//namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/core/wscript Tue Sep 29 19:58:29 2009 -0700
+++ b/src/core/wscript Tue Sep 29 20:45:27 2009 -0700
@@ -70,7 +70,6 @@
'object-vector.cc',
'object-factory.cc',
'global-value.cc',
- 'traced-callback.cc',
'trace-source-accessor.cc',
'config.cc',
'callback.cc',
@@ -80,6 +79,7 @@
'callback-test-suite.cc',
'names-test-suite.cc',
'type-traits-test-suite.cc',
+ 'traced-callback-test-suite.cc',
]
headers = bld.new_task_gen('ns3header')