summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Roster/UnitTest')
-rw-r--r--Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp558
-rw-r--r--Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp684
-rw-r--r--Swift/Controllers/Roster/UnitTest/RosterTest.cpp248
-rw-r--r--Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp126
4 files changed, 808 insertions, 808 deletions
diff --git a/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp b/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
index 144de77..5844ebe 100644
--- a/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/LeastCommonSubsequenceTest.cpp
@@ -18,294 +18,294 @@
using namespace Swift;
struct IsBOrC {
- bool operator()(char c, char c2) const {
- CPPUNIT_ASSERT_EQUAL(c, c2);
- return c == 'b' || c == 'c';
- }
+ bool operator()(char c, char c2) const {
+ CPPUNIT_ASSERT_EQUAL(c, c2);
+ return c == 'b' || c == 'c';
+ }
};
struct IsXOrY {
- bool operator()(char c, char c2) const {
- CPPUNIT_ASSERT_EQUAL(c, c2);
- return c == 'x' || c == 'y';
- }
+ bool operator()(char c, char c2) const {
+ CPPUNIT_ASSERT_EQUAL(c, c2);
+ return c == 'x' || c == 'y';
+ }
};
struct IsArizonaOrNewJersey {
- bool operator()(const std::string& s, const std::string& s2) const {
- CPPUNIT_ASSERT_EQUAL(s, s2);
- return s == "Arizona" || s == "New Jersey";
- }
+ bool operator()(const std::string& s, const std::string& s2) const {
+ CPPUNIT_ASSERT_EQUAL(s, s2);
+ return s == "Arizona" || s == "New Jersey";
+ }
};
class LeastCommonSubsequenceTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(LeastCommonSubsequenceTest);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_1);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_2);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence1Empty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence2Empty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_NoCommonSequence);
- CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_SameSequences);
- CPPUNIT_TEST(testComputeIndexDiff_1);
- CPPUNIT_TEST(testComputeIndexDiff_2);
- CPPUNIT_TEST(testComputeIndexDiff_Sequence1Empty);
- CPPUNIT_TEST(testComputeIndexDiff_Sequence2Empty);
- CPPUNIT_TEST(testComputeIndexDiff_BothSequencesEmpty);
- CPPUNIT_TEST(testComputeIndexDiff_NoCommonSequence);
- CPPUNIT_TEST(testComputeIndexDiff_SameSequences);
- CPPUNIT_TEST(testComputeIndexDiff_CommonPrefixAndSuffix);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testComputeLeastCommonSubsequenceMatrix_1() {
- std::vector<char> x = boost::assign::list_of('x')('m')('j')('y')('a')('u')('z');
- std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)(0)(0)(0)(0)
- (0)(0)(1)(1)(1)(1)(1)(1)
- (0)(0)(1)(1)(1)(1)(1)(2)
- (0)(0)(1)(2)(2)(2)(2)(2)
- (0)(0)(1)(2)(2)(3)(3)(3)
- (0)(0)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(2)(2)(3)(4)(4);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_2() {
- std::vector<char> x = boost::assign::list_of('x')('x')('x')('m')('j')('y')('a')('u')('z');
- std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)(0)(0)(0)(0)(0)(0)
- (0)(0)(0)(0)(1)(1)(1)(1)(1)(1)
- (0)(0)(0)(0)(1)(1)(1)(1)(1)(2)
- (0)(0)(0)(0)(1)(2)(2)(2)(2)(2)
- (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
- (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(1)(1)(2)(2)(3)(3)(3)
- (0)(1)(1)(1)(1)(2)(2)(3)(4)(4);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_Sequence1Empty() {
- std::vector<char> x;
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)
- (0)
- (0)
- (0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_Sequence2Empty() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y;
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty() {
- std::vector<char> x;
- std::vector<char> y;
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_NoCommonSequence() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0)
- (0)(0)(0)(0);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeLeastCommonSubsequenceMatrix_SameSequences() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<int> result;
- Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
-
- std::vector<int> expected = boost::assign::list_of
- (0)(0)(0)(0)
- (0)(1)(1)(1)
- (0)(1)(2)(2)
- (0)(1)(2)(3);
- CPPUNIT_ASSERT_EQUAL(expected, result);
- }
-
- void testComputeIndexDiff_1() {
- std::vector<std::string> x = boost::assign::list_of("Arizona")("California")("Delaware")("New Jersey")("Washington");
- std::vector<std::string> y = boost::assign::list_of("Alaska")("Arizona")("California")("Georgia")("New Jersey")("Virginia");
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<std::string, std::equal_to<std::string>, IsArizonaOrNewJersey >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(3)(0);
- std::vector<size_t> expectedPostUpdates = boost::assign::list_of(4)(1);
- std::vector<size_t> expectedRemoves = boost::assign::list_of(4)(2);
- std::vector<size_t> expectedInserts = boost::assign::list_of(5)(3)(0);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_2() {
- std::vector<char> x = boost::assign::list_of('x')('y');
- std::vector<char> y = boost::assign::list_of('x');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(1);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(inserts.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- }
-
- void testComputeIndexDiff_Sequence1Empty() {
- std::vector<char> x;
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedInserts = boost::assign::list_of(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_Sequence2Empty() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y;
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_BothSequencesEmpty() {
- std::vector<char> x;
- std::vector<char> y;
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_NoCommonSequence() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
- std::vector<size_t> expectedInserts = boost::assign::list_of(3)(2)(1)(0);
- CPPUNIT_ASSERT(updates.empty());
- CPPUNIT_ASSERT(postUpdates.empty());
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
-
- void testComputeIndexDiff_SameSequences() {
- std::vector<char> x = boost::assign::list_of('a')('b')('c');
- std::vector<char> y = boost::assign::list_of('a')('b')('c');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(1)(2);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, postUpdates);
- CPPUNIT_ASSERT(removes.empty());
- CPPUNIT_ASSERT(inserts.empty());
- }
-
- void testComputeIndexDiff_CommonPrefixAndSuffix() {
- std::vector<char> x = boost::assign::list_of('x')('x')('x')('x')('a')('b')('c')('d')('e')('y')('y')('y');
- std::vector<char> y = boost::assign::list_of('x')('x')('x')('x')('e')('a')('b')('f')('d')('g')('y')('y')('y');
-
- std::vector<size_t> updates;
- std::vector<size_t> postUpdates;
- std::vector<size_t> removes;
- std::vector<size_t> inserts;
- computeIndexDiff<char, std::equal_to<char>, IsXOrY >(x, y, updates, postUpdates, removes, inserts);
-
- std::vector<size_t> expectedUpdates = boost::assign::list_of(0)(1)(2)(3)(11)(10)(9);
- std::vector<size_t> expectedPostUpdates = boost::assign::list_of(0)(1)(2)(3)(12)(11)(10);
- std::vector<size_t> expectedRemoves = boost::assign::list_of(8)(6);
- std::vector<size_t> expectedInserts = boost::assign::list_of(9)(7)(4);
- CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
- CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
- CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
- CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
- }
+ CPPUNIT_TEST_SUITE(LeastCommonSubsequenceTest);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_1);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_2);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence1Empty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_Sequence2Empty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_NoCommonSequence);
+ CPPUNIT_TEST(testComputeLeastCommonSubsequenceMatrix_SameSequences);
+ CPPUNIT_TEST(testComputeIndexDiff_1);
+ CPPUNIT_TEST(testComputeIndexDiff_2);
+ CPPUNIT_TEST(testComputeIndexDiff_Sequence1Empty);
+ CPPUNIT_TEST(testComputeIndexDiff_Sequence2Empty);
+ CPPUNIT_TEST(testComputeIndexDiff_BothSequencesEmpty);
+ CPPUNIT_TEST(testComputeIndexDiff_NoCommonSequence);
+ CPPUNIT_TEST(testComputeIndexDiff_SameSequences);
+ CPPUNIT_TEST(testComputeIndexDiff_CommonPrefixAndSuffix);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testComputeLeastCommonSubsequenceMatrix_1() {
+ std::vector<char> x = boost::assign::list_of('x')('m')('j')('y')('a')('u')('z');
+ std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)(0)(0)(0)(0)
+ (0)(0)(1)(1)(1)(1)(1)(1)
+ (0)(0)(1)(1)(1)(1)(1)(2)
+ (0)(0)(1)(2)(2)(2)(2)(2)
+ (0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(2)(2)(3)(4)(4);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_2() {
+ std::vector<char> x = boost::assign::list_of('x')('x')('x')('m')('j')('y')('a')('u')('z');
+ std::vector<char> y = boost::assign::list_of('m')('z')('j')('a')('w')('x')('u');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)(0)(0)(0)(0)(0)(0)
+ (0)(0)(0)(0)(1)(1)(1)(1)(1)(1)
+ (0)(0)(0)(0)(1)(1)(1)(1)(1)(2)
+ (0)(0)(0)(0)(1)(2)(2)(2)(2)(2)
+ (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(0)(0)(0)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(1)(1)(2)(2)(3)(3)(3)
+ (0)(1)(1)(1)(1)(2)(2)(3)(4)(4);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_Sequence1Empty() {
+ std::vector<char> x;
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)
+ (0)
+ (0)
+ (0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_Sequence2Empty() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y;
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_BothSequencesEmpty() {
+ std::vector<char> x;
+ std::vector<char> y;
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_NoCommonSequence() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0)
+ (0)(0)(0)(0);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeLeastCommonSubsequenceMatrix_SameSequences() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<int> result;
+ Detail::computeLeastCommonSubsequenceMatrix<std::vector<char>::const_iterator, std::vector<char>::const_iterator, int, std::equal_to<char> >(x.begin(), x.end(), y.begin(), y.end(), result);
+
+ std::vector<int> expected = boost::assign::list_of
+ (0)(0)(0)(0)
+ (0)(1)(1)(1)
+ (0)(1)(2)(2)
+ (0)(1)(2)(3);
+ CPPUNIT_ASSERT_EQUAL(expected, result);
+ }
+
+ void testComputeIndexDiff_1() {
+ std::vector<std::string> x = boost::assign::list_of("Arizona")("California")("Delaware")("New Jersey")("Washington");
+ std::vector<std::string> y = boost::assign::list_of("Alaska")("Arizona")("California")("Georgia")("New Jersey")("Virginia");
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<std::string, std::equal_to<std::string>, IsArizonaOrNewJersey >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(3)(0);
+ std::vector<size_t> expectedPostUpdates = boost::assign::list_of(4)(1);
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(4)(2);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(5)(3)(0);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_2() {
+ std::vector<char> x = boost::assign::list_of('x')('y');
+ std::vector<char> y = boost::assign::list_of('x');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(1);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ }
+
+ void testComputeIndexDiff_Sequence1Empty() {
+ std::vector<char> x;
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedInserts = boost::assign::list_of(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_Sequence2Empty() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y;
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_BothSequencesEmpty() {
+ std::vector<char> x;
+ std::vector<char> y;
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_NoCommonSequence() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('d')('e')('f')('g');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(2)(1)(0);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(3)(2)(1)(0);
+ CPPUNIT_ASSERT(updates.empty());
+ CPPUNIT_ASSERT(postUpdates.empty());
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
+
+ void testComputeIndexDiff_SameSequences() {
+ std::vector<char> x = boost::assign::list_of('a')('b')('c');
+ std::vector<char> y = boost::assign::list_of('a')('b')('c');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsBOrC >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(1)(2);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, postUpdates);
+ CPPUNIT_ASSERT(removes.empty());
+ CPPUNIT_ASSERT(inserts.empty());
+ }
+
+ void testComputeIndexDiff_CommonPrefixAndSuffix() {
+ std::vector<char> x = boost::assign::list_of('x')('x')('x')('x')('a')('b')('c')('d')('e')('y')('y')('y');
+ std::vector<char> y = boost::assign::list_of('x')('x')('x')('x')('e')('a')('b')('f')('d')('g')('y')('y')('y');
+
+ std::vector<size_t> updates;
+ std::vector<size_t> postUpdates;
+ std::vector<size_t> removes;
+ std::vector<size_t> inserts;
+ computeIndexDiff<char, std::equal_to<char>, IsXOrY >(x, y, updates, postUpdates, removes, inserts);
+
+ std::vector<size_t> expectedUpdates = boost::assign::list_of(0)(1)(2)(3)(11)(10)(9);
+ std::vector<size_t> expectedPostUpdates = boost::assign::list_of(0)(1)(2)(3)(12)(11)(10);
+ std::vector<size_t> expectedRemoves = boost::assign::list_of(8)(6);
+ std::vector<size_t> expectedInserts = boost::assign::list_of(9)(7)(4);
+ CPPUNIT_ASSERT_EQUAL(expectedUpdates, updates);
+ CPPUNIT_ASSERT_EQUAL(expectedPostUpdates, postUpdates);
+ CPPUNIT_ASSERT_EQUAL(expectedRemoves, removes);
+ CPPUNIT_ASSERT_EQUAL(expectedInserts, inserts);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(LeastCommonSubsequenceTest);
diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
index d774e6d..551bd6b 100644
--- a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
@@ -46,351 +46,351 @@ using namespace Swift;
#define CHILDREN mainWindow_->roster->getRoot()->getChildren()
class DummyCapsProvider : public CapsProvider {
- DiscoInfo::ref getCaps(const std::string&) const {return DiscoInfo::ref(new DiscoInfo());}
+ DiscoInfo::ref getCaps(const std::string&) const {return DiscoInfo::ref(new DiscoInfo());}
};
class RosterControllerTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RosterControllerTest);
- CPPUNIT_TEST(testAdd);
- CPPUNIT_TEST(testAddSubscription);
- CPPUNIT_TEST(testReceiveRename);
- CPPUNIT_TEST(testReceiveRegroup);
- CPPUNIT_TEST(testSendRename);
- CPPUNIT_TEST(testPresence);
- CPPUNIT_TEST(testHighestPresence);
- CPPUNIT_TEST(testNotHighestPresence);
- CPPUNIT_TEST(testUnavailablePresence);
- CPPUNIT_TEST(testRemoveResultsInUnavailablePresence);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- jid_ = JID("testjid@swift.im/swift");
- xmppRoster_ = new XMPPRosterImpl();
- avatarManager_ = new NullAvatarManager();
- mainWindowFactory_ = new MockMainWindowFactory();
- mucRegistry_ = new MUCRegistry();
- nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
- channel_ = new DummyIQChannel();
- router_ = new IQRouter(channel_);
- stanzaChannel_ = new DummyStanzaChannel();
- presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
- subscriptionManager_ = new SubscriptionManager(stanzaChannel_);
- eventController_ = new EventController();
- uiEventStream_ = new UIEventStream();
- settings_ = new DummySettingsProvider();
- nickManager_ = new DummyNickManager();
- capsProvider_ = new DummyCapsProvider();
- entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
- jingleSessionManager_ = new JingleSessionManager(router_);
-
- ftManager_ = new DummyFileTransferManager();
- ftOverview_ = new FileTransferOverview(ftManager_);
- clientBlockListManager_ = new ClientBlockListManager(router_);
- crypto_ = PlatformCryptoProvider::create();
- vcardStorage_ = new VCardMemoryStorage(crypto_);
- vcardManager_ = new VCardManager(jid_, router_, vcardStorage_);
- rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_, clientBlockListManager_, vcardManager_);
- mainWindow_ = mainWindowFactory_->last;
- }
-
- void tearDown() {
- delete rosterController_;
- delete vcardManager_;
- delete vcardStorage_;
- delete crypto_;
- delete clientBlockListManager_;
- delete ftOverview_;
- delete ftManager_;
- delete jingleSessionManager_;
- delete entityCapsManager_;
- delete capsProvider_;
- delete nickManager_;
- delete nickResolver_;
- delete mucRegistry_;
- delete mainWindowFactory_;
- delete avatarManager_;
- delete router_;
- delete channel_;
- delete eventController_;
- delete subscriptionManager_;
- delete presenceOracle_;
- delete stanzaChannel_;
- delete uiEventStream_;
- delete settings_;
- delete xmppRoster_;
- }
-
- GroupRosterItem* groupChild(size_t i) {
- return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
- }
-
- JID withResource(const JID& jid, const std::string& resource) {
- return JID(jid.toBare().toString() + "/" + resource);
- }
-
- void testPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- groups.push_back("testGroup2");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref presence(new Presence());
- presence->setFrom(withResource(from, "bob"));
- presence->setPriority(2);
- presence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(presence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText());
- ContactRosterItem* item2 = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[1])->getChildren()[0]);
- CPPUNIT_ASSERT(item2);
- CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText());
-
- }
-
- void testHighestPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(lowPresence);
- stanzaChannel_->onPresenceReceived(highPresence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- }
-
- void testNotHighestPresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(highPresence);
- stanzaChannel_->onPresenceReceived(lowPresence);
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- }
-
- void testUnavailablePresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
-
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setShow(StatusShow::Away);
- lowPresence->setStatus("Not here");
- Presence::ref lowPresenceOffline(new Presence());
- lowPresenceOffline->setFrom(withResource(from, "bob"));
- lowPresenceOffline->setStatus("Signing out");
- lowPresenceOffline->setType(Presence::Unavailable);
-
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- Presence::ref highPresenceOffline(new Presence());
- highPresenceOffline->setFrom(withResource(from, "bert"));
- highPresenceOffline->setType(Presence::Unavailable);
-
- stanzaChannel_->onPresenceReceived(lowPresence);
- Presence::ref accountPresence = presenceOracle_->getAccountPresence(from);
- CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow());
-
- stanzaChannel_->onPresenceReceived(highPresence);
- accountPresence = presenceOracle_->getAccountPresence(from);
- CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow());
-
- stanzaChannel_->onPresenceReceived(highPresenceOffline);
-
- // After this, the roster should show the low presence.
- ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
-
- Presence::ref low = presenceOracle_->getAccountPresence(from);
-
- CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow());
- CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText());
- stanzaChannel_->onPresenceReceived(lowPresenceOffline);
- item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
- CPPUNIT_ASSERT(item);
- /* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */
- low = presenceOracle_->getHighestPriorityPresence(from);
- CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType());
- CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus());
- CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
- CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
- }
-
- void testAdd() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- groups.push_back("testGroup2");
- xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(CHILDREN.size()));
- //CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
- }
-
- void testAddSubscription() {
- std::vector<std::string> groups;
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::None);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::To);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
-
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
-
- }
-
- void testReceiveRename() {
- std::vector<std::string> groups;
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("name"), groupChild(0)->getChildren()[0]->getDisplayName());
- xmppRoster_->addContact(jid, "NewName", groups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
- }
-
- void testReceiveRegroup() {
- std::vector<std::string> oldGroups;
- std::vector<std::string> newGroups;
- newGroups.push_back("A Group");
- std::vector<std::string> newestGroups;
- newestGroups.push_back("Best Group");
- JID jid("test@testdomain.com");
- xmppRoster_->addContact(jid, "", oldGroups, RosterItemPayload::Both);
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(jid.toString(), groupChild(0)->getChildren()[0]->getDisplayName());
-
- xmppRoster_->addContact(jid, "new name", newGroups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("A Group"), groupChild(0)->getDisplayName());
-
- xmppRoster_->addContact(jid, "new name", newestGroups, RosterItemPayload::Both);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Best Group"), groupChild(0)->getDisplayName());
- }
-
- void testSendRename() {
- JID jid("testling@wonderland.lit");
- std::vector<std::string> groups;
- groups.push_back("Friends");
- groups.push_back("Enemies");
- xmppRoster_->addContact(jid, "Bob", groups, RosterItemPayload::From);
- CPPUNIT_ASSERT_EQUAL(groups.size(), xmppRoster_->getGroupsForJID(jid).size());
- uiEventStream_->send(boost::shared_ptr<UIEvent>(new RenameRosterItemUIEvent(jid, "Robert")));
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), channel_->iqs_.size());
- CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
- boost::shared_ptr<RosterPayload> payload = channel_->iqs_[0]->getPayload<RosterPayload>();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getItems().size());
- RosterItemPayload item = payload->getItems()[0];
- CPPUNIT_ASSERT_EQUAL(jid, item.getJID());
- CPPUNIT_ASSERT_EQUAL(std::string("Robert"), item.getName());
-
- CPPUNIT_ASSERT_EQUAL(groups.size(), item.getGroups().size());
- assertVectorsEqual(groups, item.getGroups(), __LINE__);
- }
-
- void testRemoveResultsInUnavailablePresence() {
- std::vector<std::string> groups;
- groups.push_back("testGroup1");
- JID from("test@testdomain.com");
- xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
- Presence::ref lowPresence(new Presence());
- lowPresence->setFrom(withResource(from, "bob"));
- lowPresence->setPriority(2);
- lowPresence->setStatus("Not here");
- Presence::ref highPresence(new Presence());
- highPresence->setFrom(withResource(from, "bert"));
- highPresence->setPriority(10);
- highPresence->setStatus("So totally here");
- stanzaChannel_->onPresenceReceived(highPresence);
- stanzaChannel_->onPresenceReceived(lowPresence);
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), presenceOracle_->getAllPresence("test@testdomain.com").size());
-
- xmppRoster_->onJIDRemoved(JID("test@testdomain.com"));
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), presenceOracle_->getAllPresence("test@testdomain.com").size());
- CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presenceOracle_->getAllPresence("test@testdomain.com")[0]->getType());
- }
-
- void assertVectorsEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2, int line) {
- foreach (const std::string& entry, v1) {
- if (std::find(v2.begin(), v2.end(), entry) == v2.end()) {
- std::stringstream stream;
- stream << "Couldn't find " << entry << " in v2 (line " << line << ")";
- CPPUNIT_FAIL(stream.str());
- }
- }
- }
-
- private:
- JID jid_;
- XMPPRosterImpl* xmppRoster_;
- MUCRegistry* mucRegistry_;
- AvatarManager* avatarManager_;
- MockMainWindowFactory* mainWindowFactory_;
- NickManager* nickManager_;
- NickResolver* nickResolver_;
- RosterController* rosterController_;
- DummyIQChannel* channel_;
- DummyStanzaChannel* stanzaChannel_;
- IQRouter* router_;
- PresenceOracle* presenceOracle_;
- SubscriptionManager* subscriptionManager_;
- EventController* eventController_;
- UIEventStream* uiEventStream_;
- MockMainWindow* mainWindow_;
- DummySettingsProvider* settings_;
- DummyCapsProvider* capsProvider_;
- EntityCapsManager* entityCapsManager_;
- JingleSessionManager* jingleSessionManager_;
- FileTransferManager* ftManager_;
- FileTransferOverview* ftOverview_;
- ClientBlockListManager* clientBlockListManager_;
- CryptoProvider* crypto_;
- VCardStorage* vcardStorage_;
- VCardManager* vcardManager_;
+ CPPUNIT_TEST_SUITE(RosterControllerTest);
+ CPPUNIT_TEST(testAdd);
+ CPPUNIT_TEST(testAddSubscription);
+ CPPUNIT_TEST(testReceiveRename);
+ CPPUNIT_TEST(testReceiveRegroup);
+ CPPUNIT_TEST(testSendRename);
+ CPPUNIT_TEST(testPresence);
+ CPPUNIT_TEST(testHighestPresence);
+ CPPUNIT_TEST(testNotHighestPresence);
+ CPPUNIT_TEST(testUnavailablePresence);
+ CPPUNIT_TEST(testRemoveResultsInUnavailablePresence);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ jid_ = JID("testjid@swift.im/swift");
+ xmppRoster_ = new XMPPRosterImpl();
+ avatarManager_ = new NullAvatarManager();
+ mainWindowFactory_ = new MockMainWindowFactory();
+ mucRegistry_ = new MUCRegistry();
+ nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_);
+ channel_ = new DummyIQChannel();
+ router_ = new IQRouter(channel_);
+ stanzaChannel_ = new DummyStanzaChannel();
+ presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
+ subscriptionManager_ = new SubscriptionManager(stanzaChannel_);
+ eventController_ = new EventController();
+ uiEventStream_ = new UIEventStream();
+ settings_ = new DummySettingsProvider();
+ nickManager_ = new DummyNickManager();
+ capsProvider_ = new DummyCapsProvider();
+ entityCapsManager_ = new EntityCapsManager(capsProvider_, stanzaChannel_);
+ jingleSessionManager_ = new JingleSessionManager(router_);
+
+ ftManager_ = new DummyFileTransferManager();
+ ftOverview_ = new FileTransferOverview(ftManager_);
+ clientBlockListManager_ = new ClientBlockListManager(router_);
+ crypto_ = PlatformCryptoProvider::create();
+ vcardStorage_ = new VCardMemoryStorage(crypto_);
+ vcardManager_ = new VCardManager(jid_, router_, vcardStorage_);
+ rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_, clientBlockListManager_, vcardManager_);
+ mainWindow_ = mainWindowFactory_->last;
+ }
+
+ void tearDown() {
+ delete rosterController_;
+ delete vcardManager_;
+ delete vcardStorage_;
+ delete crypto_;
+ delete clientBlockListManager_;
+ delete ftOverview_;
+ delete ftManager_;
+ delete jingleSessionManager_;
+ delete entityCapsManager_;
+ delete capsProvider_;
+ delete nickManager_;
+ delete nickResolver_;
+ delete mucRegistry_;
+ delete mainWindowFactory_;
+ delete avatarManager_;
+ delete router_;
+ delete channel_;
+ delete eventController_;
+ delete subscriptionManager_;
+ delete presenceOracle_;
+ delete stanzaChannel_;
+ delete uiEventStream_;
+ delete settings_;
+ delete xmppRoster_;
+ }
+
+ GroupRosterItem* groupChild(size_t i) {
+ return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
+ }
+
+ JID withResource(const JID& jid, const std::string& resource) {
+ return JID(jid.toBare().toString() + "/" + resource);
+ }
+
+ void testPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ groups.push_back("testGroup2");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref presence(new Presence());
+ presence->setFrom(withResource(from, "bob"));
+ presence->setPriority(2);
+ presence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(presence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item->getStatusText());
+ ContactRosterItem* item2 = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[1])->getChildren()[0]);
+ CPPUNIT_ASSERT(item2);
+ CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText());
+
+ }
+
+ void testHighestPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ stanzaChannel_->onPresenceReceived(highPresence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
+ }
+
+ void testNotHighestPresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(highPresence);
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
+ }
+
+ void testUnavailablePresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setShow(StatusShow::Away);
+ lowPresence->setStatus("Not here");
+ Presence::ref lowPresenceOffline(new Presence());
+ lowPresenceOffline->setFrom(withResource(from, "bob"));
+ lowPresenceOffline->setStatus("Signing out");
+ lowPresenceOffline->setType(Presence::Unavailable);
+
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ Presence::ref highPresenceOffline(new Presence());
+ highPresenceOffline->setFrom(withResource(from, "bert"));
+ highPresenceOffline->setType(Presence::Unavailable);
+
+ stanzaChannel_->onPresenceReceived(lowPresence);
+ Presence::ref accountPresence = presenceOracle_->getAccountPresence(from);
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Away, accountPresence->getShow());
+
+ stanzaChannel_->onPresenceReceived(highPresence);
+ accountPresence = presenceOracle_->getAccountPresence(from);
+ CPPUNIT_ASSERT_EQUAL(StatusShow::Online, accountPresence->getShow());
+
+ stanzaChannel_->onPresenceReceived(highPresenceOffline);
+
+ // After this, the roster should show the low presence.
+ ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+
+ Presence::ref low = presenceOracle_->getAccountPresence(from);
+
+ CPPUNIT_ASSERT_EQUAL(Presence::Available, low->getType());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), low->getStatus());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getShow(), item->getStatusShow());
+ CPPUNIT_ASSERT_EQUAL(lowPresence->getStatus(), item->getStatusText());
+ stanzaChannel_->onPresenceReceived(lowPresenceOffline);
+ item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
+ CPPUNIT_ASSERT(item);
+ /* A verification that if the test fails, it's the RosterController, not the PresenceOracle. */
+ low = presenceOracle_->getHighestPriorityPresence(from);
+ CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, low->getType());
+ CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), low->getStatus());
+ CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
+ CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
+ }
+
+ void testAdd() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ groups.push_back("testGroup2");
+ xmppRoster_->addContact(JID("test@testdomain.com/bob"), "name", groups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(CHILDREN.size()));
+ //CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
+ }
+
+ void testAddSubscription() {
+ std::vector<std::string> groups;
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::None);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::To);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+
+ }
+
+ void testReceiveRename() {
+ std::vector<std::string> groups;
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "name", groups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ xmppRoster_->addContact(jid, "NewName", groups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
+ }
+
+ void testReceiveRegroup() {
+ std::vector<std::string> oldGroups;
+ std::vector<std::string> newGroups;
+ newGroups.push_back("A Group");
+ std::vector<std::string> newestGroups;
+ newestGroups.push_back("Best Group");
+ JID jid("test@testdomain.com");
+ xmppRoster_->addContact(jid, "", oldGroups, RosterItemPayload::Both);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(jid.toString(), groupChild(0)->getChildren()[0]->getDisplayName());
+
+ xmppRoster_->addContact(jid, "new name", newGroups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("A Group"), groupChild(0)->getDisplayName());
+
+ xmppRoster_->addContact(jid, "new name", newestGroups, RosterItemPayload::Both);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Best Group"), groupChild(0)->getDisplayName());
+ }
+
+ void testSendRename() {
+ JID jid("testling@wonderland.lit");
+ std::vector<std::string> groups;
+ groups.push_back("Friends");
+ groups.push_back("Enemies");
+ xmppRoster_->addContact(jid, "Bob", groups, RosterItemPayload::From);
+ CPPUNIT_ASSERT_EQUAL(groups.size(), xmppRoster_->getGroupsForJID(jid).size());
+ uiEventStream_->send(boost::shared_ptr<UIEvent>(new RenameRosterItemUIEvent(jid, "Robert")));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), channel_->iqs_.size());
+ CPPUNIT_ASSERT_EQUAL(IQ::Set, channel_->iqs_[0]->getType());
+ boost::shared_ptr<RosterPayload> payload = channel_->iqs_[0]->getPayload<RosterPayload>();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), payload->getItems().size());
+ RosterItemPayload item = payload->getItems()[0];
+ CPPUNIT_ASSERT_EQUAL(jid, item.getJID());
+ CPPUNIT_ASSERT_EQUAL(std::string("Robert"), item.getName());
+
+ CPPUNIT_ASSERT_EQUAL(groups.size(), item.getGroups().size());
+ assertVectorsEqual(groups, item.getGroups(), __LINE__);
+ }
+
+ void testRemoveResultsInUnavailablePresence() {
+ std::vector<std::string> groups;
+ groups.push_back("testGroup1");
+ JID from("test@testdomain.com");
+ xmppRoster_->addContact(from, "name", groups, RosterItemPayload::Both);
+ Presence::ref lowPresence(new Presence());
+ lowPresence->setFrom(withResource(from, "bob"));
+ lowPresence->setPriority(2);
+ lowPresence->setStatus("Not here");
+ Presence::ref highPresence(new Presence());
+ highPresence->setFrom(withResource(from, "bert"));
+ highPresence->setPriority(10);
+ highPresence->setStatus("So totally here");
+ stanzaChannel_->onPresenceReceived(highPresence);
+ stanzaChannel_->onPresenceReceived(lowPresence);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), presenceOracle_->getAllPresence("test@testdomain.com").size());
+
+ xmppRoster_->onJIDRemoved(JID("test@testdomain.com"));
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), presenceOracle_->getAllPresence("test@testdomain.com").size());
+ CPPUNIT_ASSERT_EQUAL(Presence::Unavailable, presenceOracle_->getAllPresence("test@testdomain.com")[0]->getType());
+ }
+
+ void assertVectorsEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2, int line) {
+ foreach (const std::string& entry, v1) {
+ if (std::find(v2.begin(), v2.end(), entry) == v2.end()) {
+ std::stringstream stream;
+ stream << "Couldn't find " << entry << " in v2 (line " << line << ")";
+ CPPUNIT_FAIL(stream.str());
+ }
+ }
+ }
+
+ private:
+ JID jid_;
+ XMPPRosterImpl* xmppRoster_;
+ MUCRegistry* mucRegistry_;
+ AvatarManager* avatarManager_;
+ MockMainWindowFactory* mainWindowFactory_;
+ NickManager* nickManager_;
+ NickResolver* nickResolver_;
+ RosterController* rosterController_;
+ DummyIQChannel* channel_;
+ DummyStanzaChannel* stanzaChannel_;
+ IQRouter* router_;
+ PresenceOracle* presenceOracle_;
+ SubscriptionManager* subscriptionManager_;
+ EventController* eventController_;
+ UIEventStream* uiEventStream_;
+ MockMainWindow* mainWindow_;
+ DummySettingsProvider* settings_;
+ DummyCapsProvider* capsProvider_;
+ EntityCapsManager* entityCapsManager_;
+ JingleSessionManager* jingleSessionManager_;
+ FileTransferManager* ftManager_;
+ FileTransferOverview* ftOverview_;
+ ClientBlockListManager* clientBlockListManager_;
+ CryptoProvider* crypto_;
+ VCardStorage* vcardStorage_;
+ VCardManager* vcardManager_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RosterControllerTest);
diff --git a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
index 314b5c6..dd22cb7 100644
--- a/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/RosterTest.cpp
@@ -16,130 +16,130 @@
using namespace Swift;
class RosterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(RosterTest);
- CPPUNIT_TEST(testGetGroup);
- CPPUNIT_TEST(testRemoveContact);
- CPPUNIT_TEST(testRemoveSecondContact);
- CPPUNIT_TEST(testRemoveSecondContactSameBare);
- CPPUNIT_TEST(testApplyPresenceLikeMUC);
- CPPUNIT_TEST(testReSortLikeMUC);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- jid1_ = JID("a@b.c");
- jid2_ = JID("b@c.d");
- jid3_ = JID("c@d.e");
- roster_ = new Roster();
- }
-
- void tearDown() {
- delete roster_;
- }
-
- void testGetGroup() {
- roster_->addContact(jid1_, JID(), "Bert", "group1", "");
- roster_->addContact(jid2_, JID(), "Ernie", "group2", "");
- roster_->addContact(jid3_, JID(), "Cookie", "group1", "");
-
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster_->getRoot()->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
-
- }
-
- void testRemoveContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
-
- roster_->removeContact(jid1_);
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- }
-
- void testRemoveSecondContact() {
- roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
- roster_->addContact(jid2_, jid2_, "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid2_);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testRemoveSecondContactSameBare() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- roster_->addContact(jid4a, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
-
- roster_->removeContact(jid4b);
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
- }
-
- void testApplyPresenceLikeMUC() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- JID jid4c("a@b/e");
- roster_->addContact(jid4a, JID(), "Bird", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
- roster_->removeContact(jid4b);
- roster_->addContact(jid4c, JID(), "Bert", "group1", "");
- roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setShow(StatusShow::DND);
- presence->setFrom(jid4a);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4b);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- presence->setFrom(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- presence = boost::make_shared<Presence>();
- presence->setFrom(jid4b);
- presence->setShow(StatusShow::Online);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
- std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren();
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size()));
-
- /* Check order */
- CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), children[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bert"), children[1]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("Bird"), children[2]->getDisplayName());
-
- presence = boost::make_shared<Presence>();
- presence->setFrom(jid4c);
- presence->setType(Presence::Unavailable);
- roster_->removeContact(jid4c);
- roster_->applyOnItems(SetPresence(presence, JID::WithResource));
-
- }
-
- void testReSortLikeMUC() {
- JID jid4a("a@b/c");
- JID jid4b("a@b/d");
- JID jid4c("a@b/e");
- roster_->addContact(jid4a, JID(), "Bird", "group1", "");
- roster_->addContact(jid4b, JID(), "Cookie", "group2", "");
- roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
- roster_->getGroup("group1")->setManualSort("2");
- roster_->getGroup("group2")->setManualSort("1");
- GroupRosterItem* root = roster_->getRoot();
- const std::vector<RosterItem*> kids = root->getDisplayedChildren();
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), kids.size());
- CPPUNIT_ASSERT_EQUAL(std::string("group2"), kids[0]->getDisplayName());
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), kids[1]->getDisplayName());
- }
-
- private:
- Roster *roster_;
- JID jid1_;
- JID jid2_;
- JID jid3_;
+ CPPUNIT_TEST_SUITE(RosterTest);
+ CPPUNIT_TEST(testGetGroup);
+ CPPUNIT_TEST(testRemoveContact);
+ CPPUNIT_TEST(testRemoveSecondContact);
+ CPPUNIT_TEST(testRemoveSecondContactSameBare);
+ CPPUNIT_TEST(testApplyPresenceLikeMUC);
+ CPPUNIT_TEST(testReSortLikeMUC);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ jid1_ = JID("a@b.c");
+ jid2_ = JID("b@c.d");
+ jid3_ = JID("c@d.e");
+ roster_ = new Roster();
+ }
+
+ void tearDown() {
+ delete roster_;
+ }
+
+ void testGetGroup() {
+ roster_->addContact(jid1_, JID(), "Bert", "group1", "");
+ roster_->addContact(jid2_, JID(), "Ernie", "group2", "");
+ roster_->addContact(jid3_, JID(), "Cookie", "group1", "");
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster_->getRoot()->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), roster_->getRoot()->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("group2"), roster_->getRoot()->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[1])->getChildren()[0]->getDisplayName());
+
+ }
+
+ void testRemoveContact() {
+ roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+
+ roster_->removeContact(jid1_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ }
+
+ void testRemoveSecondContact() {
+ roster_->addContact(jid1_, jid1_, "Bert", "group1", "");
+ roster_->addContact(jid2_, jid2_, "Cookie", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+
+ roster_->removeContact(jid2_);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ }
+
+ void testRemoveSecondContactSameBare() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ roster_->addContact(jid4a, JID(), "Bert", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
+ CPPUNIT_ASSERT_EQUAL(std::string("Cookie"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[1]->getDisplayName());
+
+ roster_->removeContact(jid4b);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), static_cast<GroupRosterItem*>(roster_->getRoot()->getChildren()[0])->getChildren()[0]->getDisplayName());
+ }
+
+ void testApplyPresenceLikeMUC() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ JID jid4c("a@b/e");
+ roster_->addContact(jid4a, JID(), "Bird", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group1", "");
+ roster_->removeContact(jid4b);
+ roster_->addContact(jid4c, JID(), "Bert", "group1", "");
+ roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setShow(StatusShow::DND);
+ presence->setFrom(jid4a);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ presence->setFrom(jid4b);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ presence->setFrom(jid4c);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+
+ presence = boost::make_shared<Presence>();
+ presence->setFrom(jid4b);
+ presence->setShow(StatusShow::Online);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+ std::vector<RosterItem*> children = static_cast<GroupRosterItem*>(roster_->getRoot()->getDisplayedChildren()[0])->getDisplayedChildren();
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(children.size()));
+
+ /* Check order */
+ CPPUNIT_ASSERT_EQUAL(std::string("Ernie"), children[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bert"), children[1]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("Bird"), children[2]->getDisplayName());
+
+ presence = boost::make_shared<Presence>();
+ presence->setFrom(jid4c);
+ presence->setType(Presence::Unavailable);
+ roster_->removeContact(jid4c);
+ roster_->applyOnItems(SetPresence(presence, JID::WithResource));
+
+ }
+
+ void testReSortLikeMUC() {
+ JID jid4a("a@b/c");
+ JID jid4b("a@b/d");
+ JID jid4c("a@b/e");
+ roster_->addContact(jid4a, JID(), "Bird", "group1", "");
+ roster_->addContact(jid4b, JID(), "Cookie", "group2", "");
+ roster_->addContact(jid4b, JID(), "Ernie", "group1", "");
+ roster_->getGroup("group1")->setManualSort("2");
+ roster_->getGroup("group2")->setManualSort("1");
+ GroupRosterItem* root = roster_->getRoot();
+ const std::vector<RosterItem*> kids = root->getDisplayedChildren();
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), kids.size());
+ CPPUNIT_ASSERT_EQUAL(std::string("group2"), kids[0]->getDisplayName());
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), kids[1]->getDisplayName());
+ }
+
+ private:
+ Roster *roster_;
+ JID jid1_;
+ JID jid2_;
+ JID jid3_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest);
diff --git a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
index 10030ef..086bd6f 100644
--- a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
@@ -9,8 +9,8 @@
std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i);
std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i) {
- os << "(" << i.section << ", " << i.row << ")";
- return os;
+ os << "(" << i.section << ", " << i.row << ")";
+ return os;
}
#include <cppunit/extensions/HelperMacros.h>
@@ -27,67 +27,67 @@ std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i) {
using namespace Swift;
class TableRosterTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(TableRosterTest);
- CPPUNIT_TEST(testAddContact_EmptyRoster);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- timerFactory = new DummyTimerFactory();
- roster = new Roster();
- jid1 = JID("jid1@example.com");
- jid2 = JID("jid2@example.com");
- }
-
- void tearDown() {
- delete roster;
- delete timerFactory;
- }
-
- void testAddContact_EmptyRoster() {
- /*
- boost::shared_ptr<TableRoster> tableRoster(createTestling());
-
- addContact(jid1, "1", "group1");
-
- CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(events.size()));
- CPPUNIT_ASSERT(boost::get<BeginUpdatesEvent>(&events[0]));
- CPPUNIT_ASSERT(boost::get<SectionsInsertedEvent>(&events[1]));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections.size()));
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections[0]));
- CPPUNIT_ASSERT(boost::get<RowsInsertedEvent>(&events[2]));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<RowsInsertedEvent>(events[2]).rows.size()));
- CPPUNIT_ASSERT_EQUAL(TableRoster::Index(0, 0), boost::get<RowsInsertedEvent>(events[2]).rows[0]);
- CPPUNIT_ASSERT(boost::get<EndUpdatesEvent>(&events[3]));
-
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfSections()));
- CPPUNIT_ASSERT_EQUAL(std::string("group1"), tableRoster->getSectionTitle(0));
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfRowsInSection(0)));
- CPPUNIT_ASSERT_EQUAL(jid1, tableRoster->getItem(TableRoster::Index(0, 0)).jid);
- */
- }
-
- private:
- void addContact(const JID& jid, const std::string& name, const std::string& group) {
- roster->addContact(jid, JID(), name, group, "");
- }
-
- TableRoster* createTestling() {
- TableRoster* result = new TableRoster(roster, timerFactory, 10);
- result->onUpdate.connect(boost::bind(&TableRosterTest::handleUpdate, this, _1));
- return result;
- }
-
- void handleUpdate(const TableRoster::Update& update) {
- updates.push_back(update);
- }
-
- private:
- DummyTimerFactory* timerFactory;
- Roster* roster;
- JID jid1;
- JID jid2;
- std::vector<TableRoster::Update> updates;
+ CPPUNIT_TEST_SUITE(TableRosterTest);
+ CPPUNIT_TEST(testAddContact_EmptyRoster);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp() {
+ timerFactory = new DummyTimerFactory();
+ roster = new Roster();
+ jid1 = JID("jid1@example.com");
+ jid2 = JID("jid2@example.com");
+ }
+
+ void tearDown() {
+ delete roster;
+ delete timerFactory;
+ }
+
+ void testAddContact_EmptyRoster() {
+ /*
+ boost::shared_ptr<TableRoster> tableRoster(createTestling());
+
+ addContact(jid1, "1", "group1");
+
+ CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(events.size()));
+ CPPUNIT_ASSERT(boost::get<BeginUpdatesEvent>(&events[0]));
+ CPPUNIT_ASSERT(boost::get<SectionsInsertedEvent>(&events[1]));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(boost::get<SectionsInsertedEvent>(events[1]).sections[0]));
+ CPPUNIT_ASSERT(boost::get<RowsInsertedEvent>(&events[2]));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(boost::get<RowsInsertedEvent>(events[2]).rows.size()));
+ CPPUNIT_ASSERT_EQUAL(TableRoster::Index(0, 0), boost::get<RowsInsertedEvent>(events[2]).rows[0]);
+ CPPUNIT_ASSERT(boost::get<EndUpdatesEvent>(&events[3]));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfSections()));
+ CPPUNIT_ASSERT_EQUAL(std::string("group1"), tableRoster->getSectionTitle(0));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(tableRoster->getNumberOfRowsInSection(0)));
+ CPPUNIT_ASSERT_EQUAL(jid1, tableRoster->getItem(TableRoster::Index(0, 0)).jid);
+ */
+ }
+
+ private:
+ void addContact(const JID& jid, const std::string& name, const std::string& group) {
+ roster->addContact(jid, JID(), name, group, "");
+ }
+
+ TableRoster* createTestling() {
+ TableRoster* result = new TableRoster(roster, timerFactory, 10);
+ result->onUpdate.connect(boost::bind(&TableRosterTest::handleUpdate, this, _1));
+ return result;
+ }
+
+ void handleUpdate(const TableRoster::Update& update) {
+ updates.push_back(update);
+ }
+
+ private:
+ DummyTimerFactory* timerFactory;
+ Roster* roster;
+ JID jid1;
+ JID jid2;
+ std::vector<TableRoster::Update> updates;
};
CPPUNIT_TEST_SUITE_REGISTRATION(TableRosterTest);