OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/shared_impl/unittest_utils.h" | 5 #include "ppapi/shared_impl/unittest_utils.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ppapi/shared_impl/array_var.h" | 11 #include "ppapi/shared_impl/array_var.h" |
12 #include "ppapi/shared_impl/dictionary_var.h" | 12 #include "ppapi/shared_impl/dictionary_var.h" |
13 #include "ppapi/shared_impl/resource_var.h" | |
13 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
14 #include "ppapi/shared_impl/var_tracker.h" | 15 #include "ppapi/shared_impl/var_tracker.h" |
15 | 16 |
16 namespace ppapi { | 17 namespace ppapi { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // When two vars x and y are found to be equal, an entry is inserted into | 21 // When two vars x and y are found to be equal, an entry is inserted into |
21 // |visited_map| with (x.value.as_id, y.value.as_id). This allows reference | 22 // |visited_map| with (x.value.as_id, y.value.as_id). This allows reference |
22 // cycles to be avoided. It also allows us to associate nodes in |expected| with | 23 // cycles to be avoided. It also allows us to associate nodes in |expected| with |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 return false; | 145 return false; |
145 } | 146 } |
146 if (!Equals(expected_iter->second.get(), | 147 if (!Equals(expected_iter->second.get(), |
147 actual_iter->second.get(), | 148 actual_iter->second.get(), |
148 visited_map)) { | 149 visited_map)) { |
149 return false; | 150 return false; |
150 } | 151 } |
151 } | 152 } |
152 return true; | 153 return true; |
153 } | 154 } |
155 case PP_VARTYPE_RESOURCE: { | |
156 ResourceVar* expected_var = ResourceVar::FromPPVar(expected); | |
157 ResourceVar* actual_var = ResourceVar::FromPPVar(actual); | |
158 DCHECK(expected_var && actual_var); | |
159 if (expected_var->pp_resource() != actual_var->pp_resource()) { | |
160 LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " | |
161 << actual_var->pp_resource(); | |
162 return false; | |
163 } | |
164 IPC::Message actual_message(actual_var->creation_message()); | |
165 const IPC::Message& expected_message = expected_var->creation_message(); | |
166 if (expected_message.size() != actual_message.size()) { | |
167 LOG(ERROR) << "expected creation message size: " | |
168 << expected_message.size() << " actual: " | |
169 << actual_message.size(); | |
170 return false; | |
171 } | |
172 | |
173 // Set the upper 24 bits of actual creation_message flags to the same as | |
174 // expected. This is an unpredictable reference number that changes | |
175 // between serialization/deserialization, and we do not want it to cause | |
176 // the comparison to fail. | |
177 actual_message.SetHeaderValues(actual_message.routing_id(), | |
178 actual_message.type(), | |
179 (expected_message.flags() & 0xffffff00) | | |
180 (actual_message.flags() & 0xff)); | |
181 if (memcmp(expected_message.data(), actual_message.data(), | |
182 expected_message.size()) != 0) { | |
dmichael (off chromium)
2013/09/11 18:30:05
Why not just memcmp the data that is expected to b
Matt Giuca
2013/09/12 07:08:24
That would assume implementation details about the
| |
183 LOG(ERROR) << "expected creation message does not match actual."; | |
184 return false; | |
185 } | |
186 return true; | |
187 } | |
154 } | 188 } |
155 NOTREACHED(); | 189 NOTREACHED(); |
156 return false; | 190 return false; |
157 } | 191 } |
158 | 192 |
159 } // namespace | 193 } // namespace |
160 | 194 |
161 bool TestEqual(const PP_Var& expected, const PP_Var& actual) { | 195 bool TestEqual(const PP_Var& expected, const PP_Var& actual) { |
162 base::hash_map<int64_t, int64_t> visited_map; | 196 base::hash_map<int64_t, int64_t> visited_map; |
163 return Equals(expected, actual, &visited_map); | 197 return Equals(expected, actual, &visited_map); |
164 } | 198 } |
165 | 199 |
166 } // namespace ppapi | 200 } // namespace ppapi |
OLD | NEW |