Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/util/mboolTest.cc @ 10612

Last change on this file since 10612 was 9114, checked in by landauf, 13 years ago

added tests for several classes and functions in util

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1#include <gtest/gtest.h>
2#include "util/mbool.h"
3
4namespace orxonox
5{
6    TEST(mbool, Create)
7    {
8        // default constructor
9        mbool test1;
10        EXPECT_FALSE((bool)test1);
11
12        // initialize with false
13        mbool test2(false);
14        EXPECT_FALSE((bool)test2);
15
16        // initialize with true
17        mbool test3(true);
18        EXPECT_TRUE((bool)test3);
19
20        // copy constructor
21        mbool test4(test2);
22        EXPECT_FALSE((bool)test4);
23
24        // copy constructor
25        mbool test5(test3);
26        EXPECT_TRUE((bool)test5);
27
28        // default constructor & assignment
29        mbool test6;
30        test6 = test2;
31        EXPECT_FALSE((bool)test6);
32
33        // default constructor & assignment
34        mbool test7;
35        test7 = test3;
36        EXPECT_TRUE((bool)test7);
37    }
38
39    TEST(mbool, Compare)
40    {
41        mbool test1(false);
42        mbool test2(true);
43        mbool test3(false);
44        mbool test4(true);
45
46        EXPECT_NE(test1, test2);
47        EXPECT_EQ(test1, test3);
48        EXPECT_EQ(test2, test4);
49
50        EXPECT_FALSE(test1 == true);
51        EXPECT_TRUE (test1 != true);
52        EXPECT_FALSE(test1 == test2);
53        EXPECT_TRUE (test1 != test2);
54        EXPECT_TRUE (test1 == false);
55        EXPECT_FALSE(test1 != false);
56        EXPECT_TRUE (test1 == test3);
57        EXPECT_FALSE(test1 != test3);
58
59
60        EXPECT_FALSE(test2 == false);
61        EXPECT_TRUE (test2 != false);
62        EXPECT_FALSE(test2 == test1);
63        EXPECT_TRUE (test2 != test1);
64        EXPECT_TRUE (test2 == true);
65        EXPECT_FALSE(test2 != true);
66        EXPECT_TRUE (test2 == test4);
67        EXPECT_FALSE(test2 != test4);
68
69        EXPECT_EQ(!test1, true);
70        EXPECT_EQ(!test2, false);
71    }
72
73    TEST(mbool, Assign)
74    {
75        mbool test(false);
76        mbool test_false = false;
77        mbool test_true = true;
78
79        EXPECT_EQ(test, false);        // eq because initialized with false
80        EXPECT_NE(test, true);         // "
81        EXPECT_EQ(test, test_false);   // eq because both initialized with false
82        EXPECT_NE(test, test_true);    // ne because initialized differently
83
84        test = false; // expect no change after assigning false again
85
86        EXPECT_EQ(test, false);        // no change, so still the same
87        EXPECT_NE(test, true);         // "
88        EXPECT_EQ(test, test_false);   // "
89        EXPECT_NE(test, test_true);    // "
90
91        test = true; // expect change after assigning true
92
93        EXPECT_NE(test, false);        // ne because assigned true
94        EXPECT_EQ(test, true);         // eq "
95        EXPECT_NE(test, test_false);   // ne "
96        EXPECT_EQ(test, test_true);    // eq "
97
98        test = false; // expect change after assigning false again
99
100        EXPECT_EQ(test, false);        // eq because assigned false again
101        EXPECT_NE(test, true);         // ne "
102        EXPECT_NE(test, test_false);   // ne because changed state in between, so internal memory differs !!!!!
103        EXPECT_NE(test, test_true);    // ne because assigned false again
104    }
105}
Note: See TracBrowser for help on using the repository browser.