summaryrefslogtreecommitdiffstats
blob: 935423c0d750f0b23fb959327bbb396c4ef9573e (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
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#ifndef SWIFTEN_MockTreeWidgetFactory_H
#define SWIFTEN_MockTreeWidgetFactory_H

#include "Swiften/Roster/TreeWidgetFactory.h"

#include <vector>
#include "Swiften/Base/foreach.h"
#include "Swiften/Roster/UnitTest/MockTreeWidget.h"
#include "Swiften/Roster/UnitTest/MockTreeWidgetItem.h"

namespace Swift {

class MockTreeWidgetItem;
class MockTreeWidget;

class MockTreeWidgetFactory : public TreeWidgetFactory {
	public:
		virtual ~MockTreeWidgetFactory() {}
		virtual TreeWidget* createTreeWidget() {
			root_ = new MockTreeWidget();
			return root_;
		};
		virtual TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem* group) {
			MockTreeWidgetItem* entry = new MockTreeWidgetItem();
			groupMembers_[group].push_back(entry);
			return entry;
		};
		virtual TreeWidgetItem* createTreeWidgetItem(TreeWidget*) {
			MockTreeWidgetItem* group = new MockTreeWidgetItem();
			groups_.push_back(group);
			return group;
		};
		virtual std::vector<String> getGroups() {
			std::vector<String> groupNames;
			foreach (MockTreeWidgetItem* group, groups_) {
				groupNames.push_back(group->getText());
			}
			return groupNames;
		};
	private:
		std::vector<MockTreeWidgetItem*> groups_;
		std::map<TreeWidgetItem*, std::vector<MockTreeWidgetItem*> > groupMembers_;
		MockTreeWidget* root_;
};

}

#endif