aboutsummaryrefslogtreecommitdiff
path: root/test/common/list.h
blob: 3026b204c5eb2217d1f8ba3a666b5d9a1f00d30a (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
#include <cxxtest/TestSuite.h>

#include "common/stdafx.h"
#include "common/list.h"

class ListTestSuite : public CxxTest::TestSuite
{
	public:
	void test_isEmpty_clear( void )
	{
		Common::List<int> list;
		TS_ASSERT( list.isEmpty() );
		list.push_back(17);
		list.push_back(33);
		TS_ASSERT( !list.isEmpty() );
		list.clear();
		TS_ASSERT( list.isEmpty() );
	}

	void test_iterator( void )
	{
		Common::List<int> list;
		Common::List<int>::iterator iter;

		// Fill the list with some random data
		list.push_back(17);
		list.push_back(33);
		list.push_back(-11);

		// Iterate over the list and verify that we encounter the elements in
		// the order we expect them to be.

		iter = list.begin();

		TS_ASSERT( *iter == 17 );
		++iter;
		TS_ASSERT( iter != list.end() );

		TS_ASSERT( *iter == 33 );
		++iter;
		TS_ASSERT( iter != list.end() );

		// Also test the postinc
		TS_ASSERT( *iter == -11 );
		iter++;
		TS_ASSERT( iter == list.end() );
	}


	void test_insert( void )
	{
		Common::List<int> list;
		Common::List<int>::iterator iter;

		// Fill the list with some random data
		list.push_back(17);
		list.push_back(33);
		list.push_back(-11);

		// Iterate to after the second element
		iter = list.begin();
		++iter;
		++iter;

		// Now insert some values here
		list.insert(iter, 42);
		list.insert(iter, 43);

		iter = list.begin();

		TS_ASSERT( *iter == 17 );
		++iter;
		TS_ASSERT( iter != list.end() );

		TS_ASSERT( *iter == 33 );
		++iter;
		TS_ASSERT( iter != list.end() );

		TS_ASSERT( *iter == 42 );
		++iter;
		TS_ASSERT( iter != list.end() );

		TS_ASSERT( *iter == 43 );
		++iter;
		TS_ASSERT( iter != list.end() );

		TS_ASSERT( *iter == -11 );
		++iter;
		TS_ASSERT( iter == list.end() );
	}
};