ReactOS  0.4.15-dev-1201-gb2cf5a4
test_slist.cpp
Go to the documentation of this file.
1 /***********************************************************************************
2  test_slist.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 #if defined( EH_SLIST_IMPLEMENTED )
18 # include "TestClass.h"
19 # include "LeakCheck.h"
20 # if defined (EH_NEW_HEADERS) && defined (EH_USE_SGI_STL)
21 # include <slist>
22 # else
23 # include <slist.h>
24 # endif
25 #include "test_construct.h"
26 #include "test_assign_op.h"
27 #include "test_push_back.h"
28 #include "test_insert.h"
29 #include "test_push_front.h"
30 
31 #if defined (__GNUC__) && defined (__APPLE__)
32 typedef EH_STD::slist<TestClass, eh_allocator(TestClass) > TestSList;
33 #else
35 #endif
36 
39  return sequence_container_tag();
40 }
41 
44  gTestController.SetCurrentTestName("slist::sort()");
45  }
46  void operator()( TestSList& slist ) const {
47  slist.sort();
48  for ( TestSList::iterator p = slist.begin(), q; p != slist.end(); q = p, p++ )
49  if ( p != slist.begin() ) {
50  EH_ASSERT( *p >= *q );
51  }
52  }
53 };
54 
55 void test_slist() {
56  TestSList testSList, testSList2;
57  size_t slistSize = random_number(random_base);
58 
59  while (testSList.size() < slistSize) {
60  TestClass x;
61  testSList.push_front( x );
62  testSList2.push_front( TestClass() );
63  }
64 
65  StrongCheck( testSList, test_insert_one<TestSList>(testSList) );
66  StrongCheck( testSList, test_insert_one<TestSList>(testSList, 0) );
67  StrongCheck( testSList, test_insert_one<TestSList>(testSList, (int)testSList.size()) );
68 
69  WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base) ) );
70  WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base), 0 ) );
71  WeakCheck( testSList, test_insert_n<TestSList>(testSList, random_number(random_base), (int)testSList.size() ) );
72 
73  size_t insCnt = random_number(random_base);
74  TestClass *insFirst = new TestSList::value_type[1+insCnt];
75  WeakCheck( testSList, insert_range_tester(testSList, insFirst, insFirst+insCnt) );
76 
77  ConstCheck( 0, test_construct_pointer_range<TestSList>(insFirst, insFirst+insCnt) );
78  delete[] insFirst;
79  WeakCheck( testSList, test_insert_range<TestSList,TestSList::iterator>(testSList, testSList2.begin(), testSList2.end() ) );
80  StrongCheck( testSList, test_push_front<TestSList>(testSList) );
81  StrongCheck( testSList, test_slist_sort() ); // Simply to verify strength.
82 
88  WeakCheck( testSList, test_assign_op<TestSList>( testSList2 ) );
89 }
90 
91 #endif // EH_SLIST_IMPLEMENTED
TestController gTestController
Definition: nc_alloc.cpp:46
sequence_container_tag container_category(const TestSList &)
Definition: test_slist.cpp:38
Definition: _slist.h:198
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
iterator begin()
Definition: _slist.h:416
test_insert_range< C, Iter > insert_range_tester(const C &orig, const Iter &first, const Iter &last)
Definition: test_insert.h:535
void ConstCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:103
unsigned random_base
void sort()
Definition: _slist.h:790
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
void operator()(TestSList &slist) const
Definition: test_slist.cpp:46
#define EH_ASSERT
Definition: Prefix.h:37
unsigned random_number(size_t range)
iterator end()
Definition: _slist.h:420
#define __slist__
#define eh_allocator(T)
Definition: Prefix.h:174
GLfloat GLfloat p
Definition: glext.h:8902
void StrongCheck(const Value &v, const Operation &op, long max_iters=2000000)
Definition: LeakCheck.h:145
void test_slist()
Definition: test_slist.cpp:55
EH_STD::__slist__< TestClass, eh_allocator(TestClass) > TestSList
Definition: test_slist.cpp:34