summaryrefslogtreecommitdiffstats
blob: 271103456625ed839d05ae442bf09b25ba0e3857 (plain)
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
/*
 * Copyright (c) 2011 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include "Swift/Controllers/ChatMessageSummarizer.h"

using namespace Swift;
using namespace std;

class ChatMessageSummarizerTest : public CppUnit::TestFixture {
	CPPUNIT_TEST_SUITE(ChatMessageSummarizerTest);
	CPPUNIT_TEST(testEmpty);
	CPPUNIT_TEST(testCurrentNone);
	CPPUNIT_TEST(testCurrentCount);
	CPPUNIT_TEST(testCurrentCountOthersNone);
	CPPUNIT_TEST(testCurrentCountOtherCount);
	CPPUNIT_TEST(testCurrentNoneOtherCount);
	CPPUNIT_TEST(testCurrentCountOthersCount);
	CPPUNIT_TEST(testCurrentNoneOthersCount);
	CPPUNIT_TEST(testCurrentCountSomeOthersCount);
	CPPUNIT_TEST_SUITE_END();

public:
	ChatMessageSummarizerTest() {}

	void setUp() {

	}

	void testEmpty() {
		string current("");
		vector<UnreadPair> unreads;
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
	}

	void testCurrentNone() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bob", 0));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(current, summary.getSummary(current, unreads));
	}

	void testCurrentCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bob", 3));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
	}

	void testCurrentCountOthersNone() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 0));
		unreads.push_back(UnreadPair("Bob", 3));
		unreads.push_back(UnreadPair("Betty", 0));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob (3)"), summary.getSummary(current, unreads));
	}

	void testCurrentCountOtherCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 0));
		unreads.push_back(UnreadPair("Bob", 3));
		unreads.push_back(UnreadPair("Betty", 7));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob (3); Betty (7)"), summary.getSummary(current, unreads));
	}

	void testCurrentNoneOtherCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 0));
		unreads.push_back(UnreadPair("Bob", 0));
		unreads.push_back(UnreadPair("Betty", 7));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob; Betty (7)"), summary.getSummary(current, unreads));
	}

	void testCurrentNoneOthersCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 2));
		unreads.push_back(UnreadPair("Bob", 0));
		unreads.push_back(UnreadPair("Betty", 7));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob and 2 others (9)"), summary.getSummary(current, unreads));
	}

	void testCurrentCountOthersCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 2));
		unreads.push_back(UnreadPair("Bob", 11));
		unreads.push_back(UnreadPair("Betty", 7));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
	}

	void testCurrentCountSomeOthersCount() {
		string current("Bob");
		vector<UnreadPair> unreads;
		unreads.push_back(UnreadPair("Bert", 2));
		unreads.push_back(UnreadPair("Beverly", 0));
		unreads.push_back(UnreadPair("Bob", 11));
		unreads.push_back(UnreadPair("Beatrice", 0));
		unreads.push_back(UnreadPair("Betty", 7));
		ChatMessageSummarizer summary;
		CPPUNIT_ASSERT_EQUAL(string("Bob (11) and 2 others (9)"), summary.getSummary(current, unreads));
	}

};

CPPUNIT_TEST_SUITE_REGISTRATION(ChatMessageSummarizerTest);