fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / intrusive-list / test_intrusive_list_hp.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #ifndef CDSUNIT_LIST_TEST_INTRUSIVE_LIST_HP_H
31 #define CDSUNIT_LIST_TEST_INTRUSIVE_LIST_HP_H
32
33 #include "test_intrusive_list.h"
34
35 namespace cds_test {
36
37     class intrusive_list_hp : public intrusive_list_common
38     {
39     protected:
40         template <typename List>
41         void test_hp( List& l )
42         {
43             // Precondition: list is empty
44             // Postcondition: list is empty
45
46             static const size_t nSize = 20;
47             typedef typename List::value_type value_type;
48             value_type arr[ nSize ];
49
50             for ( size_t i = 0; i < nSize; ++i ) {
51                 arr[i].nKey = static_cast<int>( i );
52                 arr[i].nVal = arr[i].nKey * 10;
53             }
54             shuffle( arr, arr + nSize );
55
56             typedef typename List::guarded_ptr guarded_ptr;
57
58             ASSERT_TRUE( l.empty());
59             ASSERT_CONTAINER_SIZE( l, 0 );
60
61             guarded_ptr gp;
62
63             // get() test
64             for ( auto& i : arr ) {
65                 gp = l.get( i.nKey );
66                 EXPECT_TRUE( !gp );
67                 gp = l.get_with( other_item( i.nKey ), other_less());
68                 EXPECT_TRUE( !gp );
69
70                 EXPECT_TRUE( l.insert( i ));
71
72                 gp = l.get( i.nKey );
73                 ASSERT_FALSE( !gp );
74                 EXPECT_EQ( gp->nKey, i.nKey );
75                 EXPECT_EQ( gp->nVal, i.nVal );
76                 gp = l.get_with( other_item( i.nKey ), other_less());
77                 ASSERT_FALSE( !gp );
78                 EXPECT_EQ( gp->nKey, i.nKey );
79                 EXPECT_EQ( gp->nVal, i.nVal );
80             }
81
82             // extract() test
83             for ( int i = 0; i < static_cast<int>(nSize); ++i ) {
84                 if ( i & 1 )
85                     gp = l.extract( i );
86                 else
87                     gp = l.extract_with( other_item(i), other_less());
88                 ASSERT_FALSE( !gp );
89                 EXPECT_EQ( gp->nKey, i );
90
91                 gp = l.extract( i );
92                 EXPECT_TRUE( !gp );
93                 gp = l.extract_with( other_item( i ), other_less());
94                 EXPECT_TRUE( !gp );
95             }
96
97             ASSERT_TRUE( l.empty());
98             ASSERT_CONTAINER_SIZE( l, 0 );
99
100             List::gc::force_dispose();
101             for ( auto const& i : arr ) {
102                 EXPECT_EQ( i.s.nDisposeCount, 1 );
103                 EXPECT_FALSE( l.contains( i ));
104             }
105         }
106     };
107
108 } // namespace cds_test
109
110 #endif // CDSUNIT_LIST_TEST_INTRUSIVE_LIST_HP_H