Skip to content
This repository
Browse code

- fix UnitMoveFlag deserialization in optimized binaries (put read op…

…erations explicitly to not allow msvc compiler change their order)

- more gtest improvements
- update project files
  • Loading branch information...
commit 99a416ca5e83da273975416ecdd94500a29eb6f4 1 parent 3f53286
authored December 11, 2011
4  Movement/ClientMoveStatus.h
@@ -41,13 +41,13 @@ namespace Movement
41 41
 
42 42
     struct ClientMoveState : public _ClientMoveState
43 43
     {
44  
-        ClientMoveState() : t_guid(0)
  44
+        ClientMoveState() : transport_guid(0)
45 45
         {
46 46
         }
47 47
 
48 48
         Location world_position;
49 49
         Location transport_position;
50  
-        uint64 t_guid;
  50
+        uint64 transport_guid;
51 51
         UnitMoveFlag moveFlags;
52 52
         MSTime ms_time;
53 53
 
3  Movement/MovementMessage.h
@@ -95,7 +95,8 @@ namespace Movement
95 95
 
96 96
     inline void operator >> (ByteBuffer& b, UnitMoveFlag& v)
97 97
     {
98  
-        v.raw = uint64(b.read<uint32>()) | (uint64(b.read<uint16>()) << 32);
  98
+        v.raw = b.read<uint32>();
  99
+        v.raw |= (uint64(b.read<uint16>()) << 32);
99 100
     }
100 101
 
101 102
     inline void operator << (ByteBuffer& b, const UnitMoveFlag& v)
4  Movement/packet_builder.hpp
@@ -200,7 +200,7 @@ namespace Movement
200 200
 
201 201
         if (mov.moveFlags.ontransport)
202 202
         {
203  
-            mov.t_guid = data.readPackGUID();
  203
+            mov.transport_guid = data.readPackGUID();
204 204
             data >> mov.transport_position;
205 205
             data >> mov.transport_time;
206 206
             data >> mov.transport_seat;
@@ -238,7 +238,7 @@ namespace Movement
238 238
 
239 239
         if (mov.moveFlags.ontransport)
240 240
         {
241  
-            data.appendPackGUID(mov.t_guid);
  241
+            data.appendPackGUID(mov.transport_guid);
242 242
             data << mov.transport_position;
243 243
             data << mov.transport_time;
244 244
             data << mov.transport_seat;
12  VC9/movement.vcproj
@@ -92,6 +92,7 @@
92 92
 			/>
93 93
 			<Tool
94 94
 				Name="VCPostBuildEventTool"
  95
+				CommandLine="$(TargetPath)"
95 96
 			/>
96 97
 		</Configuration>
97 98
 		<Configuration
@@ -171,6 +172,7 @@
171 172
 			/>
172 173
 			<Tool
173 174
 				Name="VCPostBuildEventTool"
  175
+				CommandLine="$(TargetPath)"
174 176
 			/>
175 177
 		</Configuration>
176 178
 	</Configurations>
@@ -185,10 +187,6 @@
185 187
 				>
186 188
 			</File>
187 189
 			<File
188  
-				RelativePath="..\Movement\Imports.h"
189  
-				>
190  
-			</File>
191  
-			<File
192 190
 				RelativePath="..\Movement\LinkedList.h"
193 191
 				>
194 192
 			</File>
@@ -252,7 +250,7 @@
252 250
 					>
253 251
 				</File>
254 252
 				<File
255  
-					RelativePath="..\Movement\UnitMovement.Requests.hpp"
  253
+					RelativePath="..\Movement\UnitMovement.Effects.hpp"
256 254
 					>
257 255
 				</File>
258 256
 				<File
@@ -450,6 +448,10 @@
450 448
 			>
451 449
 		</File>
452 450
 		<File
  451
+			RelativePath="..\Movement\Imports.h"
  452
+			>
  453
+		</File>
  454
+		<File
453 455
 			RelativePath="..\Movement\Location.h"
454 456
 			>
455 457
 		</File>
79  gtest/gtest.cpp
@@ -51,7 +51,7 @@ namespace testing
51 51
         std::vector<TestInfo*> tests;
52 52
 
53 53
         ~TestRegistry() {
54  
-            std::for_each(tests.begin(),tests.end(),TestInfo::Delete);
  54
+            Clear();
55 55
         }
56 56
 
57 57
         size_t totalAmount() {
@@ -62,6 +62,11 @@ namespace testing
62 62
             tests.push_back(test);
63 63
         }
64 64
 
  65
+        void Clear() {
  66
+            std::for_each(tests.begin(),tests.end(),TestInfo::Delete);
  67
+            tests.clear();
  68
+        }
  69
+
65 70
         static TestRegistry& instance() {
66 71
             static TestRegistry reg;
67 72
             return reg;
@@ -79,15 +84,13 @@ namespace testing
79 84
         size_t countChecksFailed;
80 85
         size_t countDisabledTests;
81 86
         size_t countFailedTests;
82  
-
83  
-        size_t countTestsFailed() {
84  
-            return countFailedTests;
85  
-        }
  87
+        size_t countTotalTests;
86 88
 
87 89
         explicit Statistics() {
88 90
             countChecksFailed = 0;
89 91
             countDisabledTests = 0;
90 92
             countFailedTests = 0;
  93
+            countTotalTests = 0;
91 94
         }
92 95
 
93 96
         void OnCheckFailed() {
@@ -96,6 +99,13 @@ namespace testing
96 99
         void OnTestFailed() {
97 100
             ++countFailedTests;
98 101
         }
  102
+
  103
+        void OnTestsComplete() {
  104
+            printf("\n");
  105
+            printf("%u tests failed\n", countFailedTests);
  106
+            printf("%u tests disabled\n", countDisabledTests);
  107
+            printf("%u tests total amount\n", countTotalTests);
  108
+        }
99 109
     };
100 110
 
101 111
     struct TestRunner
@@ -107,45 +117,37 @@ namespace testing
107 117
             currentTest = NULL;
108 118
         }
109 119
 
110  
-        bool RunAllTests()
  120
+        bool RunAllTests(const std::vector<TestInfo*>& tests)
111 121
         {
112  
-            std::vector<TestInfo*>& tests = TestRegistry::instance().tests;
113 122
             // No need sort tests: their natural order is important. Tests from the same compile unit will be grouped together
114 123
             //std::sort(tests.begin(),tests.end(),TestInfo::Compare);
115 124
             statistics.countDisabledTests = std::count_if(tests.begin(),tests.end(),TestInfo::Disabled);
  125
+            statistics.countTotalTests = tests.size();
116 126
 
117  
-            for(std::vector<TestInfo*>::iterator it = tests.begin(); it!=tests.end(); ++it)
  127
+            for(std::vector<TestInfo*>::const_iterator it = tests.begin(); it!=tests.end(); ++it)
118 128
                 InvokeTest(*it);
119 129
 
120  
-            OnTestsComplete();
  130
+            statistics.OnTestsComplete();
121 131
 
122  
-            return statistics.countTestsFailed() == 0;
123  
-        }
124  
-
125  
-        void OnTestsComplete() {
126  
-            printf("\n");
127  
-            printf("%u tests failed\n", statistics.countTestsFailed());
128  
-            printf("%u tests disabled\n", statistics.countDisabledTests);
129  
-            printf("%u tests total amount\n", TestRegistry::instance().totalAmount());
  132
+            return statistics.countFailedTests == 0;
130 133
         }
131 134
 
132 135
         void InvokeTest(TestInfo * test)
133 136
         {
134  
-            currentTest = test;
135  
-            try {
136  
-                if (TestInfo::Disabled(test)) 
137  
-                    printf("\n    %s::%s is disabled\n", test->Name, test->Name2);
138  
-                else {
139  
-                    printf("\n    %s::%s has been invoked\n", test->Name, test->Name2);
140  
-                    test->testFn();
141  
-                    if (test->isFailed)
142  
-                        printf("\n    %s::%s has been failed!\n", test->Name, test->Name2);
143  
-                }
  137
+            if (TestInfo::Disabled(test)) {
  138
+                printf("\n    %s::%s is disabled\n", test->Name, test->Name2);
  139
+                return;
144 140
             }
145  
-            catch (...) {
146  
-                _check(false, "current test", "exception wasn't expected");
  141
+
  142
+            currentTest = test;
  143
+            printf("\n    %s::%s has been invoked\n", test->Name, test->Name2);
  144
+            {
  145
+                EXPECT_NOTHROW( test->testFn(), ... );
147 146
             }
148 147
             currentTest = NULL;
  148
+
  149
+            if (test->isFailed)
  150
+                printf("\n    %s::%s has been failed!\n", test->Name, test->Name2);
149 151
         }
150 152
 
151 153
         void OnCheckFailed()
@@ -178,8 +180,25 @@ namespace testing
178 180
             __debugbreak();
179 181
     }
180 182
 
  183
+    /** Returns true in case all tests succeed */
181 184
     bool RunAllTests()
182 185
     {
183  
-        return TestRunner::instance().RunAllTests();
  186
+        bool succeed = TestRunner::instance().RunAllTests(TestRegistry::instance().tests);
  187
+        TestRegistry::instance().Clear();
  188
+        return succeed;
  189
+    }
  190
+
  191
+    TEST(gtest, test_self)
  192
+    {
  193
+        EXPECT_TRUE( true );
  194
+        EXPECT_EQ( 1, 1);
  195
+
  196
+        EXPECT_THROW( throw "expected_exception", const char* );
  197
+        EXPECT_NOTHROW( ; , const char* );
  198
+    }
  199
+
  200
+    TEST_DISABLED(gtest, disabled)
  201
+    {
  202
+        EXPECT_TRUE( false );
184 203
     }
185 204
 }
14  gtest/gtest.h
@@ -19,20 +19,20 @@ namespace testing
19 19
 
20 20
 #define TESTCASE_NAME(name, name2) testFunction_##name##_##name2
21 21
 
22  
-#define EXPECT_TRUE(a) ::testing::_check(a, __FUNCTION__, #a);
  22
+#define EXPECT_TRUE(expression) ::testing::_check(expression, __FUNCTION__, #expression);
23 23
 #define EXPECT_EQ(a, b) EXPECT_TRUE( (a) == (b) );
24 24
 
25  
-#define EXPECT_THROW(a, exception) \
  25
+#define EXPECT_THROW(expression, exception) \
26 26
     try { \
27  
-        a; \
28  
-        ::testing::_check(false, ""); \
  27
+        expression; \
  28
+        ::testing::_check(false, __FUNCTION__, "expression '" #expression " does not throws '" #exception "' exception"); \
29 29
     } \
30 30
     catch( exception ) {}
31 31
 
32  
-#define EXPECT_NOTHROW(a, exception) \
  32
+#define EXPECT_NOTHROW(expression, exception) \
33 33
     try { \
34  
-        a; \
  34
+        expression; \
35 35
     } catch( exception ) { \
36  
-        ::testing::_check(false, ""); \
  36
+        ::testing::_check(false, __FUNCTION__, "expression '" #expression "' throws '" #exception "' exception"); \
37 37
     }
38 38
 

0 notes on commit 99a416c

Please sign in to comment.
Something went wrong with that request. Please try again.