diff --git a/src/core/traced-callback-test-suite.cc b/src/core/traced-callback-test-suite.cc new file mode 100644 index 000000000..8f369b2de --- /dev/null +++ b/src/core/traced-callback-test-suite.cc @@ -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 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; diff --git a/src/core/traced-callback.cc b/src/core/traced-callback.cc deleted file mode 100644 index b85e50827..000000000 --- a/src/core/traced-callback.cc +++ /dev/null @@ -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 - */ -#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 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 */ diff --git a/src/core/wscript b/src/core/wscript index 49b1611f7..30b661ae3 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -70,7 +70,6 @@ def build(bld): 'object-vector.cc', 'object-factory.cc', 'global-value.cc', - 'traced-callback.cc', 'trace-source-accessor.cc', 'config.cc', 'callback.cc', @@ -80,6 +79,7 @@ def build(bld): 'callback-test-suite.cc', 'names-test-suite.cc', 'type-traits-test-suite.cc', + 'traced-callback-test-suite.cc', ] headers = bld.new_task_gen('ns3header')