diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-08-02 12:18:07 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-08-02 12:18:21 (GMT) |
commit | 2a3da91e474f645fe8d83cb2809dcc4b9bfe6a32 (patch) | |
tree | 873846ea1ed08a0ab1d69dd0ae002588fa45c281 | |
parent | 7368b120827e4e9da659da62398bb37a68c19ab5 (diff) | |
download | swift-2a3da91e474f645fe8d83cb2809dcc4b9bfe6a32.zip swift-2a3da91e474f645fe8d83cb2809dcc4b9bfe6a32.tar.bz2 |
Add MenuletControllerTest.
-rw-r--r-- | Slimber/MenuletController.cpp | 2 | ||||
-rw-r--r-- | Slimber/UnitTest/Makefile.inc | 3 | ||||
-rw-r--r-- | Slimber/UnitTest/MenuletControllerTest.cpp | 145 |
3 files changed, 148 insertions, 2 deletions
diff --git a/Slimber/MenuletController.cpp b/Slimber/MenuletController.cpp index 09face5..ec11785 100644 --- a/Slimber/MenuletController.cpp +++ b/Slimber/MenuletController.cpp @@ -37,7 +37,7 @@ void MenuletController::update() { menulet->setIcon("UsersOnline"); menulet->addItem("Online users:"); foreach(const String& user, linkLocalUsers) { - menulet->addItem(user); + menulet->addItem(String(" ") + user); } } menulet->addSeparator(); diff --git a/Slimber/UnitTest/Makefile.inc b/Slimber/UnitTest/Makefile.inc index f2c4db8..5bc0c8a 100644 --- a/Slimber/UnitTest/Makefile.inc +++ b/Slimber/UnitTest/Makefile.inc @@ -1,2 +1,3 @@ UNITTEST_SOURCES += \ - Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp + Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp \ + Slimber/UnitTest/MenuletControllerTest.cpp diff --git a/Slimber/UnitTest/MenuletControllerTest.cpp b/Slimber/UnitTest/MenuletControllerTest.cpp new file mode 100644 index 0000000..d50e2c0 --- /dev/null +++ b/Slimber/UnitTest/MenuletControllerTest.cpp @@ -0,0 +1,145 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Slimber/Menulet.h" +#include "Slimber/MenuletController.h" + +using namespace Swift; + +class MenuletControllerTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(MenuletControllerTest); + CPPUNIT_TEST(testConstructor); + CPPUNIT_TEST(testUpdate); + CPPUNIT_TEST(testSetXMPPStatus_Online); + CPPUNIT_TEST(testSetXMPPStatus_Offline); + CPPUNIT_TEST(testSetUserNames); + CPPUNIT_TEST(testSetUserNames_NoUsers); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + menulet = new FakeMenulet(); + } + + void tearDown() { + delete menulet; + } + + void testConstructor() { + MenuletController testling(menulet); + + CPPUNIT_ASSERT_EQUAL(7, static_cast<int>(menulet->items.size())); + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("[Offline] "), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("*About*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("*Exit*"), menulet->items[i++]); + } + + void testUpdate() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are connected", MenuletController::Online); + + CPPUNIT_ASSERT_EQUAL(7, static_cast<int>(menulet->items.size())); + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("[Online] You are connected"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("*About*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("*Exit*"), menulet->items[i++]); + } + + void testSetXMPPStatus_Online() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are connected", MenuletController::Online); + + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("[Online] You are connected"), menulet->items[i++]); + } + + + void testSetXMPPStatus_Offline() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are not connected", MenuletController::Offline); + + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("[Offline] You are not connected"), menulet->items[i++]); + } + + void testSetUserNames() { + MenuletController testling(menulet); + + std::vector<String> users; + users.push_back("Alice In Wonderland"); + users.push_back("The Mad Hatter"); + testling.setUserNames(users); + + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("Online users:"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String(" Alice In Wonderland"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String(" The Mad Hatter"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + } + + void testSetUserNames_NoUsers() { + MenuletController testling(menulet); + + std::vector<String> users; + testling.setUserNames(users); + + int i = 0; + CPPUNIT_ASSERT_EQUAL(String("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(String("-"), menulet->items[i++]); + } + + private: + struct FakeMenulet : public Menulet { + virtual void clear() { + items.clear(); + } + + virtual void addItem(const String& name, const String& icon = String()) { + String result; + if (!icon.isEmpty()) { + result += "[" + icon + "] "; + } + result += name; + items.push_back(result); + } + + virtual void addAboutItem() { + items.push_back("*About*"); + } + + virtual void addExitItem() { + items.push_back("*Exit*"); + } + + virtual void addSeparator() { + items.push_back("-"); + } + + virtual void setIcon(const String& i) { + icon = i; + } + + std::vector<String> items; + String icon; + }; + + FakeMenulet* menulet; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MenuletControllerTest); |