12 #define ECL_MEM_CHECK_ARRAYS // Make sure we use mem checking arrays, not regular
19 #include <gtest/gtest.h>
20 #include "../../include/ecl/containers/array.hpp"
35 TEST(ArrayMemCheckTests,constructors) {
37 EXPECT_EQ(3,array1[0]);
38 EXPECT_EQ(3,array1[1]);
39 EXPECT_EQ(3,array1[2]);
40 EXPECT_EQ(3,array1[3]);
42 EXPECT_EQ(4,array2[0]);
43 EXPECT_EQ(4,array2[1]);
44 EXPECT_EQ(4,array2[2]);
45 EXPECT_EQ(4,array2[3]);
47 EXPECT_EQ(3,array3[0]);
48 EXPECT_EQ(3,array3[1]);
49 EXPECT_EQ(3,array3[2]);
50 EXPECT_EQ(3,array3[3]);
53 EXPECT_EQ(3,darray1[0]);
54 EXPECT_EQ(3,darray1[1]);
55 EXPECT_EQ(3,darray1[2]);
56 EXPECT_EQ(3,darray1[3]);
60 TEST(ArrayMemCheckTests,copyConstructors) {
68 EXPECT_EQ(3,array2[0]);
69 EXPECT_EQ(3,array2[1]);
70 EXPECT_EQ(3,array2[2]);
71 EXPECT_EQ(3,array2[3]);
73 EXPECT_EQ(3,darray2[0]);
74 EXPECT_EQ(3,darray2[1]);
75 EXPECT_EQ(3,darray2[2]);
76 EXPECT_EQ(3,darray2[3]);
79 TEST(ArrayMemCheckTests,blueprintAssignment) {
84 EXPECT_EQ(3,array[0]);
85 EXPECT_EQ(3,array[1]);
86 EXPECT_EQ(3,array[2]);
87 EXPECT_EQ(3,array[3]);
89 TEST(ArrayMemCheckTests,commaInitialisation) {
96 EXPECT_EQ(1,array[0]);
97 EXPECT_EQ(2,array[1]);
98 EXPECT_EQ(3,array[2]);
99 EXPECT_EQ(4,array[3]);
101 EXPECT_EQ(1,darray[0]);
102 EXPECT_EQ(2,darray[1]);
103 EXPECT_EQ(3,darray[2]);
104 EXPECT_EQ(4,darray[3]);
106 TEST(ArrayMemCheckTests,Accessors) {
124 TEST(ArrayMemCheckTests,rangeChecking) {
146 TEST(ArrayMemCheckTests,iterators) {
150 for ( iterator = array.
begin(); iterator != array.
end(); ++iterator ) {
151 EXPECT_EQ(3,*iterator);
155 TEST(ArrayMemCheckTests,resize) {
158 darray << 0,1,2,3,4,5,6,7,8,9;
161 for ( iterator = darray.
begin(); iterator != darray.
end(); ++iterator ) {
162 EXPECT_EQ(i,*iterator);
168 TEST(ArrayMemCheckTests,bufferRuns) {
179 istart = &array_under[0];
180 for (
unsigned int i = 0; i < 3; ++i ) {
185 istart = &array_over[0];
186 for (
unsigned int i = 0; i < array_over.
size() + 1; ++i ) {
191 EXPECT_TRUE(array_under.bufferUnderRun());
192 EXPECT_FALSE(array_under.bufferOverRun());
194 EXPECT_TRUE(array_over.bufferOverRun());
195 EXPECT_FALSE(array_over.bufferUnderRun());
197 EXPECT_FALSE(array_ok.bufferOverRun());
198 EXPECT_FALSE(array_ok.bufferUnderRun());
203 Array<int> darray_ok(4); darray_ok << 1, 2, 3, 4;
204 Array<int> darray_under(4); darray_under << 1, 2, 3, 4;
205 Array<int> darray_over(4); darray_over << 1, 2, 3, 4;
210 istart = &darray_under[0];
211 for (
unsigned int i = 0; i < darray_under.
size()+1; ++i ) {
216 istart = &darray_over[0];
217 for (
unsigned int i = 0; i < darray_over.
size()+1; ++i ) {
221 EXPECT_TRUE(darray_under.bufferUnderRun());
222 EXPECT_FALSE(darray_under.bufferOverRun());
224 EXPECT_TRUE(darray_over.bufferOverRun());
225 EXPECT_FALSE(darray_over.bufferUnderRun());
227 EXPECT_FALSE(darray_ok.bufferOverRun());
228 EXPECT_FALSE(darray_ok.bufferUnderRun());
235 int main(
int argc,
char **argv) {
237 testing::InitGoogleTest(&argc,argv);
238 return RUN_ALL_TESTS();