ctkTopicRegistryTest.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * ctkTopicRegistryTest.cpp
  3. * ctkEventBusTest
  4. *
  5. * Created by Roberto Mucci on 26/01/11.
  6. * Copyright 2011 B3C. All rights reserved.
  7. *
  8. * See Licence at: http://tiny.cc/QXJ4D
  9. *
  10. */
  11. #include "ctkTestSuite.h"
  12. #include <ctkTopicRegistry.h>
  13. using namespace ctkEventBus;
  14. /**
  15. Class name: ctkTopicRegistryTest
  16. This class implements the test suite for ctkTopicRegistry.
  17. */
  18. //! <title>
  19. //ctkTopicRegistry
  20. //! </title>
  21. //! <description>
  22. //ctkTopicRegistry provides the registration of topic and topic owner in a hash.
  23. //! </description>
  24. class ctkTopicRegistryTest : public QObject {
  25. Q_OBJECT
  26. private Q_SLOTS:
  27. /// Initialize test variables
  28. void initTestCase() {
  29. m_TopicRegistry = ctkTopicRegistry::instance();
  30. }
  31. /// Cleanup test variables memory allocation.
  32. void cleanupTestCase() {
  33. m_TopicRegistry->shutdown();
  34. }
  35. /// ctkTopicRegistry registration test case.
  36. void ctkTopicRegistryRegisterTest();
  37. /// ctkTopicRegistry owner test case.
  38. void ctkTopicRegistryOwnerTest();
  39. private:
  40. ctkTopicRegistry *m_TopicRegistry; ///< Test var.
  41. };
  42. void ctkTopicRegistryTest::ctkTopicRegistryRegisterTest() {
  43. QVERIFY(m_TopicRegistry != NULL);
  44. QString topic("ctk/local/eventBus/testTopic");
  45. bool result = m_TopicRegistry->registerTopic(topic, this);
  46. QVERIFY(result);
  47. result = m_TopicRegistry->registerTopic("ctk/local/eventBus/testTopic1", this);
  48. QVERIFY(result);
  49. result = m_TopicRegistry->registerTopic("ctk/local/eventBus/testTopic2", this);
  50. QVERIFY(result);
  51. result = m_TopicRegistry->registerTopic(topic, this);
  52. QVERIFY(!result);
  53. result = m_TopicRegistry->registerTopic("", this);
  54. QVERIFY(!result);
  55. result = m_TopicRegistry->registerTopic(topic, NULL);
  56. QVERIFY(!result);
  57. result = m_TopicRegistry->registerTopic("", NULL);
  58. QVERIFY(!result);
  59. }
  60. void ctkTopicRegistryTest::ctkTopicRegistryOwnerTest() {
  61. QString topic("ctk/local/eventBus/testTopic");
  62. const QObject *obj = m_TopicRegistry->owner(topic);
  63. QVERIFY(obj == this);
  64. obj = m_TopicRegistry->owner("");
  65. QVERIFY(obj == NULL);
  66. obj = m_TopicRegistry->owner("ctk/local/eventBus/TopicNotRegisterd");
  67. QVERIFY(obj == NULL);
  68. //Check isPresent() method.
  69. bool result = m_TopicRegistry->isTopicRegistered(topic);
  70. QVERIFY(result);
  71. result = m_TopicRegistry->isTopicRegistered("");
  72. QVERIFY(!result);
  73. result = m_TopicRegistry->isTopicRegistered("ctk/local/eventBus/TopicNotRegisterd");
  74. QVERIFY(!result);
  75. // print 3 topic
  76. m_TopicRegistry->dump();
  77. result = m_TopicRegistry->unregisterTopic(topic);
  78. QVERIFY(result);
  79. result = m_TopicRegistry->unregisterTopic("ctk/local/eventBus/TopicNotRegisterd");
  80. QVERIFY(!result);
  81. // print 2 topic
  82. m_TopicRegistry->dump();
  83. }
  84. CTK_REGISTER_TEST(ctkTopicRegistryTest);
  85. #include "ctkTopicRegistryTest.moc"