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

#include <Swift/Controllers/Roster/TableRoster.h>

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;
}

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

#include <memory>
#include <boost/variant.hpp>

#include <Swiften/Network/DummyTimerFactory.h>
#include <Swift/Controllers/Roster/Roster.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
#include <Swift/Controllers/Roster/ItemOperations/SetPresence.h>

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() {
            /*
            std::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);