ReactOS 0.4.15-dev-8119-g4fb2fdb
test_vector.cpp
Go to the documentation of this file.
1/***********************************************************************************
2 test_vector.cpp
3
4 * Copyright (c) 1997
5 * Mark of the Unicorn, Inc.
6 *
7 * Permission to use, copy, modify, distribute and sell this software
8 * and its documentation for any purpose is hereby granted without fee,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation. Mark of the Unicorn makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
14
15***********************************************************************************/
16#include "Tests.h"
17#include "TestClass.h"
18#include "LeakCheck.h"
19# if defined (EH_NEW_HEADERS)
20#include <vector>
21#else
22#include <vector.h>
23#endif
24#include "test_construct.h"
25#include "test_assign_op.h"
26#include "test_push_back.h"
27#include "test_insert.h"
28#include "test_push_front.h"
29
30# if defined (__GNUC__) && defined (__APPLE__)
31typedef EH_STD::vector<TestClass, eh_allocator(TestClass) > TestVector;
32# else
33typedef EH_STD::__vector__<TestClass, eh_allocator(TestClass) > TestVector;
34# endif
35
38{
40}
41
42void prepare_insert_n( TestVector& c, size_t insCnt );
43
44void prepare_insert_n( TestVector& c, size_t insCnt )
45{
46 if ( random_number(2) )
47 c.reserve( c.size() + insCnt );
48}
49
51{
52 test_reserve( size_t n ) : fAmount(n) {
53 gTestController.SetCurrentTestName("vector::reserve()");
54 }
55
56 void operator()( TestVector& v ) const
57 {
58 v.reserve( fAmount );
59 }
60private:
61 size_t fAmount;
62};
63
65{
66 if ( random_number(2) )
67 {
68 ptrdiff_t d = 0;
70 vec.reserve( vec.size() + d );
71 }
72}
73
75{
76
78
79 TestVector emptyVector;
80 TestVector testVector, testVector2;
81 size_t vectorSize = random_number(random_base);
82
83 testVector.reserve(vectorSize*4);
84 while ( testVector.size() < vectorSize )
85 {
87 testVector.push_back( x );
88 testVector2.push_back( TestClass() );
89 }
90
91 size_t insCnt = random_number(random_base);
92 TestClass *insFirst = new TestVector::value_type[1+ insCnt];
93
94 ConstCheck( 0, test_construct_pointer_range<TestVector>(insFirst, insFirst+insCnt) );
95
96 WeakCheck( testVector, insert_range_tester(testVector, insFirst, insFirst+insCnt) );
97 WeakCheck( testVector, insert_range_at_begin_tester(testVector, insFirst, insFirst+insCnt) );
98 WeakCheck( testVector, insert_range_at_end_tester(testVector, insFirst, insFirst+insCnt) );
99 delete[] insFirst;
100
101 WeakCheck( testVector, test_insert_one<TestVector>(testVector) );
102 WeakCheck( testVector, test_insert_one<TestVector>(testVector, 0) );
103 WeakCheck( testVector, test_insert_one<TestVector>(testVector, (int)testVector.size()) );
104
105 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base) ) );
106 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), 0 ) );
107 WeakCheck( testVector, test_insert_n<TestVector>(testVector, random_number(random_base), (int)testVector.size() ) );
108
109 WeakCheck( testVector, insert_range_tester(testVector, testVector2.begin(), testVector2.end() ) );
110
111
112 StrongCheck( testVector, test_reserve( testVector.capacity() + random_number(random_base) ) );
113 StrongCheck( testVector, test_push_back<TestVector>(testVector) );
114 StrongCheck( emptyVector, test_push_back<TestVector>(emptyVector) );
115
120
121 testVector2.resize( testVector.size() * 3 / 2 );
122 WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) );
123 testVector2.clear();
124 testVector2.resize( testVector.size() * 2 / 3 );
125 WeakCheck( testVector, test_assign_op<TestVector>( testVector2 ) );
126}
void ConstCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:103
void StrongCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:145
void WeakCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:65
#define eh_allocator(T)
Definition: Prefix.h:174
#define EH_DISTANCE(a, b, result)
Definition: Prefix.h:98
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
FT_Vector * vec
Definition: ftbbox.c:448
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLdouble n
Definition: glext.h:7729
const GLubyte * c
Definition: glext.h:8905
const GLint * first
Definition: glext.h:5794
#define d
Definition: ke_i.h:81
static UINT UINT last
Definition: font.c:45
TestController gTestController
Definition: nc_alloc.cpp:46
unsigned random_number(size_t range)
unsigned random_base
static void SetCurrentTestName(const char *str)
Definition: nc_alloc.h:172
size_t fAmount
Definition: test_vector.cpp:61
test_reserve(size_t n)
Definition: test_vector.cpp:52
void operator()(TestVector &v) const
Definition: test_vector.cpp:56
test_insert_range< C, Iter > insert_range_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:535
test_insert_range< C, Iter > insert_range_at_begin_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:541
test_insert_range< C, Iter > insert_range_at_end_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:547
void prepare_insert_n(TestVector &c, size_t insCnt)
Definition: test_vector.cpp:44
EH_STD::__vector__< TestClass, eh_allocator(TestClass) > TestVector
Definition: test_vector.cpp:33
sequence_container_tag container_category(const TestVector &)
Definition: test_vector.cpp:37
void test_vector()
Definition: test_vector.cpp:74
void prepare_insert_range(TestVector &vec, size_t, TestClass *first, TestClass *last)
Definition: test_vector.cpp:64