1 #include "utilities/sized_array.hpp"
2 #include "server/memory_pool.hpp"
5 #include <boost/test/unit_test.hpp>
9 simple_pool
<false> rt_pool
;
10 } /* namespace nova */
14 #ifdef BOOST_HAS_RVALUE_REFS
20 BOOST_AUTO_TEST_CASE( sized_array_test_1
)
22 sized_array
<int> array(5);
27 BOOST_REQUIRE_EQUAL( array
.size(), 5u );
28 BOOST_REQUIRE_EQUAL( array
[1], 3 );
29 BOOST_REQUIRE_EQUAL( array
[0], -1 );
30 BOOST_REQUIRE_EQUAL( *array
.begin(), -1 );
31 BOOST_REQUIRE_EQUAL( array
.front(), -1 );
32 BOOST_REQUIRE_EQUAL( array
.back(), 44 );
33 BOOST_REQUIRE_EQUAL( *array
.rbegin(), 44 );
34 BOOST_REQUIRE_EQUAL( *(array
.rend()-1), -1 );
36 sized_array
<long> long_array(array
);
37 BOOST_REQUIRE_EQUAL( long_array
.size(), 5u );
38 BOOST_REQUIRE_EQUAL( long_array
[1], 3 );
39 BOOST_REQUIRE_EQUAL( long_array
[0], -1 );
42 sized_array
<int> array3(0);
43 move(&array
, &array
+1, &array3
);
44 BOOST_REQUIRE_EQUAL( array3
.size(), 5u );
45 BOOST_REQUIRE_EQUAL( array3
[1], 3 );
46 BOOST_REQUIRE_EQUAL( array3
[0], -1 );
47 BOOST_REQUIRE_EQUAL( array
.size(), 0u );
50 sized_array
<int> array4(move(array3
));
51 BOOST_REQUIRE_EQUAL( array4
.size(), 5u );
52 BOOST_REQUIRE_EQUAL( array4
[1], 3 );
53 BOOST_REQUIRE_EQUAL( array4
[0], -1 );
54 BOOST_REQUIRE_EQUAL( array3
.size(), 0u );
58 template <typename Alloc1
, typename Alloc2
>
63 std::vector
<int, Alloc1
> vec
;
64 for (int i
= 0; i
!= size
; ++i
)
67 sized_array
<int, Alloc2
> array(vec
);
69 for (int i
= 0; i
!= size
; ++i
)
70 BOOST_REQUIRE_EQUAL( vec
[i
], array
[i
] );
73 BOOST_AUTO_TEST_CASE( sized_array_test_2
)
75 rt_pool
.init(1024*1024);
76 run_test_2
<std::allocator
<void*>, std::allocator
<void*> >();
77 run_test_2
<rt_pool_allocator
<void*>, std::allocator
<void*> >();
78 run_test_2
<std::allocator
<void*>, rt_pool_allocator
<void*> >();
79 run_test_2
<rt_pool_allocator
<void*>, rt_pool_allocator
<void*> >();
82 BOOST_AUTO_TEST_CASE( sized_array_test_3
)
84 sized_array
<int> array(5);
89 BOOST_REQUIRE_EQUAL( array
.size(), 5u );
90 BOOST_REQUIRE_EQUAL( array
[0], -1 );
91 BOOST_REQUIRE_EQUAL( array
[1], 3 );
92 BOOST_REQUIRE_EQUAL( *array
.begin(), -1 );
95 BOOST_REQUIRE_EQUAL( array
.size(), 6u );
96 BOOST_REQUIRE_EQUAL( array
[0], -1 );
97 BOOST_REQUIRE_EQUAL( array
[1], 3 );
98 BOOST_REQUIRE_EQUAL( array
[5], 444 );
101 BOOST_REQUIRE_EQUAL( array
.size(), 2u );
102 BOOST_REQUIRE_EQUAL( array
[0], -1 );
103 BOOST_REQUIRE_EQUAL( array
[1], 3 );
106 BOOST_AUTO_TEST_CASE( sized_array_test_4
)
108 sized_array
<int> array0(int8_t(5));
109 sized_array
<int> array1(uint8_t(5));
110 sized_array
<int> array2(int16_t(5));
111 sized_array
<int> array3(uint16_t(5));
112 sized_array
<int> array4(int32_t(5));
113 sized_array
<int> array5(uint32_t(5));
114 sized_array
<int> array6(int64_t(5));
115 sized_array
<int> array7(uint64_t(5));
117 sized_array
<int> array8(size_t(5));
118 sized_array
<int> array9(short(5));
119 sized_array
<int> array10(int(5));
120 sized_array
<int> array11(long(5));