File: test_list.cpp

package info (click to toggle)
stlport4.6 4.6.2-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 7,056 kB
  • ctags: 16,390
  • sloc: ansic: 46,190; cpp: 18,805; sh: 266; asm: 93; perl: 58; makefile: 10
file content (108 lines) | stat: -rw-r--r-- 3,794 bytes parent folder | download | duplicates (4)
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
/***********************************************************************************
	test_list.cpp
	
 * Copyright (c) 1997
 * Mark of the Unicorn, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Mark of the Unicorn makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.

***********************************************************************************/
#include "Tests.h"
#include "TestClass.h"
#include "LeakCheck.h"
# if defined (EH_NEW_HEADERS)
#include <list>
#else
#include <list.h>
#endif
#include "test_construct.h"
#include "test_assign_op.h"
#include "test_push_back.h"
#include "test_insert.h"
#include "test_push_front.h"
#include "nc_alloc.h"

typedef EH_STD::__list__<TestClass, eh_allocator(TestClass) > TestList;

inline sequence_container_tag
container_category(const TestList&)
{
  return sequence_container_tag();
}

//
//	list sort() member test operation. Does not verify stability.
//
struct test_list_sort
{
    test_list_sort()
    {
        gTestController.SetCurrentTestName("list::sort()");
    }
    
    void operator()( TestList& list ) const
    {
        list.sort();
        
        gTestController.CancelFailureCountdown();
        
        for ( TestList::iterator p = list.begin(); p != list.end(); p++ )
            if ( p != list.begin() ) {
                TestList::iterator tmp=p;
                --tmp;
                EH_ASSERT( *p >= *tmp );
            }
    }
};

void test_list()
{
    TestList testList, testList2;
    size_t listSize = random_number(random_base);
	
    while ( testList.size() < listSize )
    {
        TestClass x;
        testList.push_back( x );
        testList2.push_back( TestClass() );
    }

    StrongCheck( testList, test_insert_one<TestList>(testList) );
    StrongCheck( testList, test_insert_one<TestList>(testList, 0) );
    StrongCheck( testList, test_insert_one<TestList>(testList, (int)testList.size()) );

    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base) ) );
    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), 0 ) );
    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), (int)testList.size() ) );
	
    size_t insCnt = random_number(random_base);
    TestClass *insFirst = new TestList::value_type[1+insCnt];

    WeakCheck( testList, insert_range_tester(testList, insFirst, insFirst+insCnt) );
    WeakCheck( testList, insert_range_at_begin_tester(testList, insFirst, insFirst+insCnt) );
    WeakCheck( testList, insert_range_at_end_tester(testList, insFirst, insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestList>(insFirst, insFirst+insCnt) );
    delete[] insFirst;

    WeakCheck( testList, insert_range_tester(testList, testList2.begin(), testList2.end() ) );

    StrongCheck( testList, test_push_front<TestList>(testList) );
    StrongCheck( testList, test_push_back<TestList>(testList) );

    StrongCheck( testList, test_list_sort() );	// Simply to verify strength.
       
    ConstCheck( 0, test_default_construct<TestList>() );
    ConstCheck( 0, test_construct_n<TestList>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_n_instance<TestList>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestList>( testList2 ) );
    ConstCheck( testList, test_copy_construct<TestList>() );

    WeakCheck( testList, test_assign_op<TestList>( testList2 ) );
}