ReactOS  0.4.14-dev-297-g23e575c
test_list.cpp
Go to the documentation of this file.
1 /***********************************************************************************
2  test_list.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 <list>
21 #else
22 #include <list.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 #include "nc_alloc.h"
30 
32 
35 {
36  return sequence_container_tag();
37 }
38 
39 //
40 // list sort() member test operation. Does not verify stability.
41 //
43 {
45  {
46  gTestController.SetCurrentTestName("list::sort()");
47  }
48 
49  void operator()( TestList& list ) const
50  {
51  list.sort();
52 
54 
55  for ( TestList::iterator p = list.begin(); p != list.end(); p++ )
56  if ( p != list.begin() ) {
57  TestList::iterator tmp=p;
58  --tmp;
59  EH_ASSERT( *p >= *tmp );
60  }
61  }
62 };
63 
64 void test_list()
65 {
66  TestList testList, testList2;
67  size_t listSize = random_number(random_base);
68 
69  while ( testList.size() < listSize )
70  {
71  TestClass x;
72  testList.push_back( x );
73  testList2.push_back( TestClass() );
74  }
75 
76  StrongCheck( testList, test_insert_one<TestList>(testList) );
77  StrongCheck( testList, test_insert_one<TestList>(testList, 0) );
78  StrongCheck( testList, test_insert_one<TestList>(testList, (int)testList.size()) );
79 
81  WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), 0 ) );
82  WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), (int)testList.size() ) );
83 
84  size_t insCnt = random_number(random_base);
85  TestClass *insFirst = new TestList::value_type[1+insCnt];
86 
87  WeakCheck( testList, insert_range_tester(testList, insFirst, insFirst+insCnt) );
88  WeakCheck( testList, insert_range_at_begin_tester(testList, insFirst, insFirst+insCnt) );
89  WeakCheck( testList, insert_range_at_end_tester(testList, insFirst, insFirst+insCnt) );
90 
91  ConstCheck( 0, test_construct_pointer_range<TestList>(insFirst, insFirst+insCnt) );
92  delete[] insFirst;
93 
94  WeakCheck( testList, insert_range_tester(testList, testList2.begin(), testList2.end() ) );
95 
96  StrongCheck( testList, test_push_front<TestList>(testList) );
97  StrongCheck( testList, test_push_back<TestList>(testList) );
98 
99  StrongCheck( testList, test_list_sort() ); // Simply to verify strength.
100 
106 
107  WeakCheck( testList, test_assign_op<TestList>( testList2 ) );
108 }
iterator begin()
Definition: _list.h:367
TestController gTestController
Definition: nc_alloc.cpp:46
void WeakCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:65
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static void SetCurrentTestName(const char *str)
Definition: nc_alloc.h:172
void sort()
Definition: _list.h:660
void test_list()
Definition: test_list.cpp:64
test_insert_range< C, Iter > insert_range_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:535
#define __list__
test_insert_range< C, Iter > insert_range_at_end_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:547
EH_STD::__list__< TestClass, eh_allocator(TestClass) > TestList
Definition: test_list.cpp:31
void ConstCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:103
unsigned random_base
void operator()(TestList &list) const
Definition: test_list.cpp:49
sequence_container_tag container_category(const TestList &)
Definition: test_list.cpp:34
test_insert_range< C, Iter > insert_range_at_begin_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:541
#define EH_ASSERT
Definition: Prefix.h:37
unsigned random_number(size_t range)
Definition: _list.h:228
iterator end()
Definition: _list.h:370
#define eh_allocator(T)
Definition: Prefix.h:174
static void CancelFailureCountdown()
Definition: nc_alloc.h:143
GLfloat GLfloat p
Definition: glext.h:8902
void StrongCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:145