summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/tests/chatnavtests.cpp
blob: fe72d351d4ede14eb90eb743989f1540df6eed7e (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
   Kopete Oscar Protocol - Chat Navigation parsing tests
   Copyright (c) 2005 Matt Rogers <mattr@kde.org>

   Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>

   *************************************************************************
   *                                                                       *
   * This library is free software; you can redistribute it and/or         *
   * modify it under the terms of the GNU Lesser General Public            *
   * License as published by the Free Software Foundation; either          *
   * version 2 of the License, or (at your option) any later version.      *
   *                                                                       *
   *************************************************************************
*/

#include "chatnavtests.h"

#include <iostream>

#include "buffer.h"
#include "oscartypeclasses.h"

using namespace std;
using namespace Oscar;


ChatNavTests::ChatNavTests()
{
	m_buffer = 0;
}


ChatNavTests::~ChatNavTests()
{
}

void ChatNavTests::setupExchangeTestBuffer()
{
	delete m_buffer;
	m_buffer = 0;

	m_buffer = new Buffer();
	//TLV 0x02
	m_buffer->addDWord(0x00020001);
	m_buffer->addByte(0x03);
	//TLV 0x03
	m_buffer->addDWord(0x0003003C);
	m_buffer->addDWord(0x0001000a);
	m_buffer->addDWord(0x00030001);
	m_buffer->addDWord(0x14000400);
	m_buffer->addDWord(0x02200000);
	m_buffer->addDWord(0xC9000200);
	m_buffer->addDWord(0x4400CA00);
	m_buffer->addDWord(0x04000000);
	m_buffer->addDWord(0x0000D000);
	m_buffer->addDWord(0x0000D100);
	m_buffer->addDWord(0x0207D000);
	m_buffer->addDWord(0xD2000200);
	m_buffer->addDWord(0x2F00D400);
	m_buffer->addDWord(0x0000D500);
	m_buffer->addDWord(0x010100DA);
	m_buffer->addDWord(0x00020066);
}

void ChatNavTests::setupRoomInfoTestBuffer()
{

	delete m_buffer;
	m_buffer = 0;

	m_buffer = new Buffer();
	//TLV 0x04
	m_buffer->addDWord(0x000400F8);
	m_buffer->addWord(0x0004); //exchange
	m_buffer->addByte(0x28); //cookie length
	m_buffer->addByte(0x21); //start of cookie
	m_buffer->addDWord(0x616F6C3A);
	m_buffer->addDWord(0x2F2F3237);
	m_buffer->addDWord(0x31393A31);
	m_buffer->addDWord(0x302D342D);
	m_buffer->addDWord(0x63686174);
	m_buffer->addDWord(0x37343739);
	m_buffer->addDWord(0x33333134);
	m_buffer->addDWord(0x30313137);
	m_buffer->addDWord(0x37393435);
	m_buffer->addDWord(0x36363500);
	m_buffer->addDWord(0x00020016);
	m_buffer->addDWord(0x00660002);
	m_buffer->addDWord(0x00000068);
	m_buffer->addDWord(0x00040000);
	m_buffer->addDWord(0x0000006A);
	m_buffer->addDWord(0x00176368);
	m_buffer->addDWord(0x61743734);
	m_buffer->addDWord(0x37393333);
	m_buffer->addDWord(0x31343031);
	m_buffer->addDWord(0x31373739);
	m_buffer->addDWord(0x34353636);
	m_buffer->addDWord(0x35006D00);
	m_buffer->addDWord(0x02000000);
	m_buffer->addDWord(0x6E000200);
	m_buffer->addDWord(0x00006F00);
	m_buffer->addDWord(0x02000000);
	m_buffer->addDWord(0x71000200);
	m_buffer->addDWord(0x00007500);
	m_buffer->addDWord(0x04000000);
	m_buffer->addDWord(0x0000C900);
	m_buffer->addDWord(0x02004000);
	m_buffer->addDWord(0xCA000442);
	m_buffer->addDWord(0xBEF90500);
	m_buffer->addDWord(0xD0000200);
	m_buffer->addDWord(0x0300D100);
	m_buffer->addDWord(0x0207D000);
	m_buffer->addDWord(0xD2000200);
	m_buffer->addDWord(0x2600D300);
	m_buffer->addDWord(0x17636861);
	m_buffer->addDWord(0x74373437);
	m_buffer->addDWord(0x39333331);
	m_buffer->addDWord(0x34303131);
	m_buffer->addDWord(0x37373934);
	m_buffer->addDWord(0x35363635);
	m_buffer->addDWord(0x00D40000);
	m_buffer->addDWord(0x00D50001);
	m_buffer->addDWord(0x0100D600);
	m_buffer->addDWord(0x0875732D);
	m_buffer->addDWord(0x61736369);
	m_buffer->addDWord(0x6900D700);
	m_buffer->addDWord(0x02656E00);
	m_buffer->addDWord(0xD8000875);
	m_buffer->addDWord(0x732D6173);
	m_buffer->addDWord(0x63696900);
	m_buffer->addDWord(0xD9000265);
	m_buffer->addDWord(0x6E00DB00);
	m_buffer->addDWord(0x0D756578);
	m_buffer->addDWord(0x742F782D);
	m_buffer->addDWord(0x616F6C72);
	m_buffer->addDWord(0x746600DA);
	m_buffer->addDWord(0x000200E8);
}

void ChatNavTests::allTests()
{
	exchangeParsingTest();
	roominfoParsingTest();
}

void ChatNavTests::exchangeParsingTest()
{
	setupExchangeTestBuffer();
	Buffer testBuffer(*m_buffer);
	CHECK( testBuffer.length() != 0, true );
	while ( testBuffer.length() != 0 )
	{
		TLV t = testBuffer.getTLV();
		if ( t.type == 0x0002 )
		{
// 			cout << "Max concurrent rooms: " << t.data << endl;
		}
		
		t = testBuffer.getTLV();
		if ( t.type == 0x0003 )
		{
// 			cout << "TLV of type 3 with length " << t.length << endl;
			Buffer b(t.data);
			WORD id = b.getWord();
			CHECK( id > 0, true );
			int tlvCount = b.getWord();
			int realCount = 0;
// 			cout << "Expecting " << tlvCount << " TLVs" << endl;
			while ( b.length() > 0 )
			{
				TLV t = b.getTLV();
				CHECK( t.type != 0, true );
				switch (t.type)
				{
				case 0x02:
					CHECK( t.length == 2, true );
					CHECK( t.data.count() == 2, true );
					break;
				case 0x03:
					CHECK( t.length == 1, true );
					CHECK( t.data.count() == 1, true );
					CHECK( t.data[0] > 0, true );
					break;
				case 0x04:
					CHECK( t.length == 2, true );
					CHECK( t.data.count() == 2, true );
					//CHECK( t.data[0] > 0, true );
					break;
				case 0x05:
					CHECK( t.length > 1, true );
					break;
				case 0x06:
					CHECK( t.length > 2, true );
					break;
				case 0xCA:
					CHECK( t.length == 4, true );
					break;
				case 0xD1:
					CHECK( t.length == 2, true );
					break;
				case 0xD2:
					CHECK( t.length == 2, true );
					break;
				case 0xD3:
					CHECK( t.length > 0, true );
					CHECK( t.data.count() == t.length, true );
					break;
				case 0xD5:
					CHECK( t.length == 1, true );
					break;
				default:
// 					ios::fmtflags origFlags = cout.flags(ios::hex|ios::showbase);
// 					cout << "unknown TLV type " << t.type << endl;
// 					cout.flags(origFlags);
					break;
				}
				realCount++;
			}
			CHECK( tlvCount == realCount, true );
		}
		CHECK( testBuffer.length() == 0, true );
	}
}

void ChatNavTests::roominfoParsingTest()
{
	setupRoomInfoTestBuffer();
	Buffer testBuffer(*m_buffer);
	CHECK( testBuffer.length() != 0, true );
	while ( testBuffer.length() != 0 )
	{
		TLV t = testBuffer.getTLV();
		
// 		cout << "TLV of type " << t.type << " with length " << t.length << endl;
		
		
		CHECK( t.type == 0x04, true );
		CHECK( t.length > 8, true );
		Buffer b( t.data );
		CHECK( b.getWord() > 0, true );
		BYTE cookieLength = b.getByte();
		b.skipBytes( cookieLength );
		CHECK( b.getWord() == 0, true );
		CHECK( b.getByte() > 0, true );
		int tlvCount = b.getWord();
		int realCount = 0;
// 		cout << "Expecting " << tlvCount << " TLVs" << endl;
		while ( b.length() > 0 )
		{
			TLV t = b.getTLV();
// 			ios::fmtflags origFlags = cout.flags(ios::hex|ios::showbase);
// 			cout << "TLV of type " << t.type << endl;
// 			cout.flags(origFlags);
			CHECK( t.type != 0, true );
			switch (t.type)
			{
			case 0x02:
				CHECK( t.length == 2, true );
				CHECK( t.data.count() == 2, true );
				break;
			case 0x03:
				CHECK( t.length == 1, true );
				CHECK( t.data.count() == 1, true );
				CHECK( t.data[0] > 0, true );
				break;
			case 0x04:
				CHECK( t.length == 2, true );
				CHECK( t.data.count() == 2, true );
				//CHECK( t.data[0] > 0, true );
				break;
			case 0x05:
				CHECK( t.length > 1, true );
				break;
			case 0x06:
				CHECK( t.length > 2, true );
				break;
			case 0xCA:
				CHECK( t.length == 4, true );
				break;
			case 0xD1:
				CHECK( t.length == 2, true );
				break;
			case 0xD2:
				CHECK( t.length == 2, true );
				break;
			case 0xD3:
				CHECK( t.length > 0, true );
				CHECK( t.data.count() == t.length, true );
				break;
			case 0xD5:
				CHECK( t.length == 1, true );
				break;
			default:
				break;
			}
			realCount++;
		}
		CHECK( tlvCount == realCount, true );
	}
}