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
|
//Licensed under the GNU General Public License
#include "ssitest.h"
#include <tqstring.h>
SSITest::SSITest(int argc, char ** argv) : TQApplication( argc, argv )
{
m_manager = new SSIManager(this);
testIt();
}
SSITest::~SSITest()
{
delete m_manager;
}
void SSITest::testIt()
{
TQPtrList<TLV> tlvs;
//add three groups
SSI *ssi = new SSI( "FirstGroup", 1, 1, ROSTER_GROUP, tlvs);
m_manager->newGroup(ssi);
ssi = new SSI( "SecondGroup", 2, 2, ROSTER_GROUP, tlvs);
m_manager->newGroup(ssi);
ssi = new SSI( "ThirdGroup", 3, 3, ROSTER_GROUP, tlvs);
m_manager->newGroup(ssi);
//add six contacts
ssi = new SSI( "FirstContact", 1, 4, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
ssi = new SSI( "SecondContact", 1, 5, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
ssi = new SSI( "ThirdContact", 1, 6, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
ssi = new SSI( "FourthContact", 2, 7, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
ssi = new SSI( "FifthContact", 2, 8, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
ssi = new SSI( "SixthContact", 3, 9, ROSTER_CONTACT, tlvs);
m_manager->newContact(ssi);
//try to find a group by name
ssi = m_manager->findGroup("SecondGroup");
if ( ssi )
qDebug( TQString("Found group SecondGroup with gid=%1").arg( ssi->gid() ).latin1());
else
qDebug( "Oops, group SecondGroup not found" );
//try to find a group by gid
ssi = m_manager->findGroup( 3 );
if ( ssi )
qDebug( TQString("Found group 3 with name=%1").arg( ssi->name() ).latin1() );
else
qDebug( "Oops, group 3 not found" );
//try to find a contact by name
ssi = m_manager->findContact("ThirdContact");
if ( ssi )
qDebug( TQString( "Found contact ThirdContact with gid=%1" ).arg( ssi->gid() ).latin1() );
else
qDebug( "Oops, contact ThirdContact not found" );
//try to find a contact using the name and the group name
ssi = m_manager->findContact("FourthContact","SecondGroup");
if ( ssi )
qDebug( TQString("Found contact FourthContact with bid=%1").arg( ssi->bid() ).latin1() );
else
qDebug( "Oops, contact FourthContact not found" );
//try to find an invalid group
ssi = m_manager->findGroup("InvalidGroup");
if ( !ssi )
qDebug( "Good! It has detected the group is invalid :)" );
//contacts from a group
TQValueList<SSI*> list = m_manager->contactsFromGroup("FirstGroup");
TQValueList<SSI*>::iterator it;
qDebug( "Contacts from group FirtsGroup:" );
for ( it = list.begin(); it != list.end(); ++it)
qDebug( TQString(" name=%1").arg( (*it)->name() ).latin1() );
//the group list
TQValueList<SSI*> list2 = m_manager->groupList();
qDebug( "Group list:" );
for ( it = list2.begin(); it != list2.end(); ++it)
qDebug( TQString(" name=%1").arg( (*it)->name() ).latin1() );
//remove a group - this shouldn't report any debug line
m_manager->removeGroup( "SecondGroup" );
}
int main(int argc, char ** argv)
{
SSITest a( argc, argv );
a.exec();
}
#include "ssitest.moc"
|