MulticasterTest.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:2k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #ifndef MULTICASTERTEST_H
  2. #define MULTICASTERTEST_H
  3. #include "Multicaster.h"
  4. #ifndef CPPUNIT_TESTCASE_H
  5. #include "TestCase.h"
  6. #endif
  7. class MulticasterTest : public TestCase
  8. {
  9. public:
  10.     class Observer : public MulticastObserver
  11.     {
  12.     public:
  13.         int             m_state;
  14.         std::string     m_lastAddressReceived;
  15.                         Observer () : m_state (0) {}
  16.                         Observer (std::string initialAddress, int state) 
  17.                             : m_lastAddressReceived (initialAddress), m_state (state) {}
  18.         virtual void    accept (std::string address, Value Value)
  19.         { m_lastAddressReceived = address; m_state++; }
  20.     };
  21.     Multicaster                 *m_multicaster;
  22.     Observer                    *m_o1;
  23.     Observer                    *m_o2;
  24.     Observer                    *m_o3;
  25.     Observer                    *m_o4;
  26. protected:
  27.     void                        setUp ();
  28.     void                        tearDown ();
  29.     void                        testSinglePublish ();
  30.     void                        testMultipleHomogenousPublish ();
  31.     void                        testMultipleHeterogenousPublish ();
  32.     void                        testSingleUnsubscribe ();
  33.     void                        testMultipleUnsubscribe ();
  34.     void                        testSimpleUnsubscribeAll ();
  35.     void                        testComplexUnsubscribeAll ();
  36. public:
  37.                                 MulticasterTest (std::string name);
  38.     virtual                     ~MulticasterTest ();
  39.     static Test                 *suite ();
  40. };
  41. inline bool operator== (const MulticasterTest::Observer& o1, const MulticasterTest::Observer& o2)
  42. { return o1.m_state == o2.m_state && o1.m_lastAddressReceived == o2.m_lastAddressReceived; }
  43. #endif