Chromium Code Reviews| 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" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } | 154 } |
| 155 case PP_VARTYPE_RESOURCE: { | 155 case PP_VARTYPE_RESOURCE: { |
| 156 ResourceVar* expected_var = ResourceVar::FromPPVar(expected); | 156 ResourceVar* expected_var = ResourceVar::FromPPVar(expected); |
| 157 ResourceVar* actual_var = ResourceVar::FromPPVar(actual); | 157 ResourceVar* actual_var = ResourceVar::FromPPVar(actual); |
| 158 DCHECK(expected_var && actual_var); | 158 DCHECK(expected_var && actual_var); |
| 159 if (expected_var->pp_resource() != actual_var->pp_resource()) { | 159 if (expected_var->pp_resource() != actual_var->pp_resource()) { |
| 160 LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " | 160 LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " |
| 161 << actual_var->pp_resource(); | 161 << actual_var->pp_resource(); |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 IPC::Message actual_message(actual_var->creation_message()); | 164 HostResourceVar* expected_host_var = expected_var->AsHostResourceVar(); |
| 165 const IPC::Message& expected_message = expected_var->creation_message(); | 165 HostResourceVar* actual_host_var = expected_var->AsHostResourceVar(); |
| 166 if (expected_message.size() != actual_message.size()) { | 166 if (expected_host_var && !actual_host_var) { |
| 167 LOG(ERROR) << "expected creation message size: " | 167 LOG(ERROR) << "expected var is host, actual is not host"; |
| 168 << expected_message.size() << " actual: " | 168 return false; |
| 169 << actual_message.size(); | 169 } else if (!expected_host_var && actual_host_var) { |
| 170 LOG(ERROR) << "expected var is not host, actual is host"; | |
| 170 return false; | 171 return false; |
| 171 } | 172 } |
| 173 if (expected_host_var) { | |
| 174 IPC::Message actual_message(actual_host_var->creation_message()); | |
| 175 const IPC::Message& expected_message = | |
| 176 expected_host_var->creation_message(); | |
| 177 if (expected_message.size() != actual_message.size()) { | |
| 178 LOG(ERROR) << "expected creation message size: " | |
| 179 << expected_message.size() << " actual: " | |
| 180 << actual_message.size(); | |
| 181 return false; | |
| 182 } | |
| 172 | 183 |
| 173 // Set the upper 24 bits of actual creation_message flags to the same as | 184 // Set the upper 24 bits of actual creation_message flags to the same as |
| 174 // expected. This is an unpredictable reference number that changes | 185 // expected. This is an unpredictable reference number that changes |
| 175 // between serialization/deserialization, and we do not want it to cause | 186 // between serialization/deserialization, and we do not want it to cause |
| 176 // the comparison to fail. | 187 // the comparison to fail. |
| 177 actual_message.SetHeaderValues(actual_message.routing_id(), | 188 actual_message.SetHeaderValues(actual_message.routing_id(), |
| 178 actual_message.type(), | 189 actual_message.type(), |
| 179 (expected_message.flags() & 0xffffff00) | | 190 (expected_message.flags() & 0xffffff00) | |
|
dmichael (off chromium)
2013/09/13 17:29:03
I think I mentioned this in another CL... would i
raymes
2013/09/13 17:41:33
+1
Matt Giuca
2013/09/13 21:23:11
See my response there:
https://codereview.chromium
dmichael (off chromium)
2013/09/13 22:54:45
Okay, thanks. Sorry I missed that. Makes sense.
| |
| 180 (actual_message.flags() & 0xff)); | 191 (actual_message.flags() & 0xff)); |
| 181 if (memcmp(expected_message.data(), actual_message.data(), | 192 if (memcmp(expected_message.data(), actual_message.data(), |
| 182 expected_message.size()) != 0) { | 193 expected_message.size()) != 0) { |
| 183 LOG(ERROR) << "expected creation message does not match actual."; | 194 LOG(ERROR) << "expected creation message does not match actual."; |
| 184 return false; | 195 return false; |
| 196 } | |
| 185 } | 197 } |
| 186 return true; | 198 return true; |
| 187 } | 199 } |
| 188 } | 200 } |
| 189 NOTREACHED(); | 201 NOTREACHED(); |
| 190 return false; | 202 return false; |
| 191 } | 203 } |
| 192 | 204 |
| 193 } // namespace | 205 } // namespace |
| 194 | 206 |
| 195 bool TestEqual(const PP_Var& expected, const PP_Var& actual) { | 207 bool TestEqual(const PP_Var& expected, const PP_Var& actual) { |
| 196 base::hash_map<int64_t, int64_t> visited_map; | 208 base::hash_map<int64_t, int64_t> visited_map; |
| 197 return Equals(expected, actual, &visited_map); | 209 return Equals(expected, actual, &visited_map); |
| 198 } | 210 } |
| 199 | 211 |
| 200 } // namespace ppapi | 212 } // namespace ppapi |
| OLD | NEW |