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
|
// $Id$
// ============================================================================
//
// = LIBRARY
// tests
//
// = FILENAME
// Vector_Test.cpp
//
// = DESCRIPTION
// This is a simple test of the ACE_Vector class and its iterators.
//
// = AUTHOR
// Gonzalo A. Diethelm <gonzalo.diethelm@aditiva.com>
//
// ============================================================================
#include "test_config.h"
ACE_RCSID(tests, Vector_Test, "$Id$")
#include "ace/Vector_T.h"
typedef size_t DATA;
#if defined (__BORLANDC__) && (__BORLANDC__ <= 0x570)
// Borland C++ Builder 6 and earlier don't handle the second template
// argument correctly. We have to pass it explicitly
typedef ACE_Vector<DATA, ACE_VECTOR_DEFAULT_SIZE> VECTOR;
typedef ACE_Vector<DATA, ACE_VECTOR_DEFAULT_SIZE>::Iterator ITERATOR;
#else
typedef ACE_Vector<DATA> VECTOR;
typedef ACE_Vector<DATA>::Iterator ITERATOR;
#endif
const size_t TOP = 100;
const size_t LEFT = 10;
const size_t RESIZE = 20;
int run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Vector_Test"));
VECTOR vector;
size_t i;
for (i = 0; i < TOP; ++i)
vector.push_back (i);
ACE_ASSERT (vector.size () == TOP);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Size: %d\n"),
vector.size ()));
for (i = 0; i < TOP; ++i)
ACE_ASSERT (vector[i] == i);
// Test to be sure the iterator gets the correct count and entries.
ITERATOR iter (vector);
DATA *p_item = 0 ;
size_t iter_count = 0;
while (!iter.done ())
{
if (iter.next (p_item) == 0)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Fail to get value on iter pass %d\n"),
iter_count));
if (*p_item != iter_count)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Iter pass %d got %d\n"),
iter_count, *p_item));
iter_count++;
iter.advance();
}
if (iter_count != TOP)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Iterated %d elements; expected %d\n"),
iter_count, TOP));
for (i = 0; i < (TOP - LEFT); ++i)
vector.pop_back ();
ACE_ASSERT (vector.size () == LEFT);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Size: %d\n"),
vector.size ()));
for (i = 0; i < LEFT; ++i)
{
ACE_ASSERT (vector[i] == i);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("vector[%d]:%d\n"),
i, vector[i]));
}
vector.resize(RESIZE, 0);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("After resize\n")));
for (i = 0; i < RESIZE ; ++i)
{
// The original vector of size LEFT must have the same original contents
// the new elements should have the value 0 (this value is passed as
// second argument of the resize() call.
if (i < LEFT)
{
ACE_ASSERT (vector[i] == i);
}
else
{
ACE_ASSERT (vector[i] == 0);
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("vector[%d]:%d\n"),
i, vector[i]));
}
vector.clear ();
ACE_ASSERT (vector.size () == 0);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Size: %d\n"),
vector.size ()));
VECTOR v1;
VECTOR v2;
v1.push_back (1);
v2.push_back (1);
v1.push_back (2);
v2.push_back (2);
if (v1 != v2)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Inequality test failed!\n")));
if (!(v1 == v2))
ACE_ERROR ((LM_ERROR, ACE_TEXT ("Equality test failed!\n")));
ACE_END_TEST;
return 0;
}
|