1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "Slimber/Menulet.h"
#include "Slimber/MenuletController.h"
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(8, static_cast<int>(menulet->items.size()));
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("[Offline] "), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
}
void testUpdate() {
MenuletController testling(menulet);
testling.setXMPPStatus("You are connected", MenuletController::Online);
CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size()));
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]);
}
void testSetXMPPStatus_Online() {
MenuletController testling(menulet);
testling.setXMPPStatus("You are connected", MenuletController::Online);
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::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(std::string("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("[Offline] You are not connected"), menulet->items[i++]);
}
void testSetUserNames() {
MenuletController testling(menulet);
std::vector<std::string> users;
users.push_back("Alice In Wonderland");
users.push_back("The Mad Hatter");
testling.setUserNames(users);
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("Online users:"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string(" Alice In Wonderland"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string(" The Mad Hatter"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
}
void testSetUserNames_NoUsers() {
MenuletController testling(menulet);
std::vector<std::string> users;
testling.setUserNames(users);
int i = 0;
CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]);
CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]);
}
private:
struct FakeMenulet : public Menulet {
virtual void clear() {
items.clear();
}
virtual void addItem(const std::string& name, const std::string& icon = std::string()) {
std::string result;
if (!icon.empty()) {
result += "[" + icon + "] ";
}
result += name;
items.push_back(result);
}
virtual void addAboutItem() {
items.push_back("*About*");
}
virtual void addRestartItem() {
items.push_back("*Restart*");
}
virtual void addExitItem() {
items.push_back("*Exit*");
}
virtual void addSeparator() {
items.push_back("-");
}
virtual void setIcon(const std::string& i) {
icon = i;
}
std::vector<std::string> items;
std::string icon;
};
FakeMenulet* menulet;
};
CPPUNIT_TEST_SUITE_REGISTRATION(MenuletControllerTest);
|