Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/public/cpp/bindings/tests/validation_test_input_parser.h" | 5 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | |
| 13 #include <utility> | 14 #include <utility> |
| 14 | 15 |
| 15 #include "mojo/public/c/system/macros.h" | 16 #include "mojo/public/c/system/macros.h" |
| 16 | 17 |
| 17 namespace mojo { | 18 namespace mojo { |
| 18 namespace test { | 19 namespace test { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class ValidationTestInputParser { | 22 class ValidationTestInputParser { |
| 22 public: | 23 public: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 static const size_t kDataTypeCount; | 106 static const size_t kDataTypeCount; |
| 106 | 107 |
| 107 const std::string& input_; | 108 const std::string& input_; |
| 108 size_t input_cursor_; | 109 size_t input_cursor_; |
| 109 | 110 |
| 110 std::vector<uint8_t>* data_; | 111 std::vector<uint8_t>* data_; |
| 111 size_t* num_handles_; | 112 size_t* num_handles_; |
| 112 std::string* error_message_; | 113 std::string* error_message_; |
| 113 | 114 |
| 114 std::map<std::string, PendingDistanceItem> pending_distance_items_; | 115 std::map<std::string, PendingDistanceItem> pending_distance_items_; |
| 116 std::set<std::string> anchors_; | |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 #define DATA_TYPE(name, data_size, parse_data_func) \ | 119 #define DATA_TYPE(name, data_size, parse_data_func) \ |
| 118 {name, sizeof(name) - 1, data_size, parse_data_func} | 120 {name, sizeof(name) - 1, data_size, parse_data_func} |
| 119 | 121 |
| 120 const ValidationTestInputParser::DataType | 122 const ValidationTestInputParser::DataType |
| 121 ValidationTestInputParser::kDataTypes[] = { | 123 ValidationTestInputParser::kDataTypes[] = { |
| 122 DATA_TYPE("[u1]", 1, &ValidationTestInputParser::ParseUnsignedInteger), | 124 DATA_TYPE("[u1]", 1, &ValidationTestInputParser::ParseUnsignedInteger), |
| 123 DATA_TYPE("[u2]", 2, &ValidationTestInputParser::ParseUnsignedInteger), | 125 DATA_TYPE("[u2]", 2, &ValidationTestInputParser::ParseUnsignedInteger), |
| 124 DATA_TYPE("[u4]", 4, &ValidationTestInputParser::ParseUnsignedInteger), | 126 DATA_TYPE("[u4]", 4, &ValidationTestInputParser::ParseUnsignedInteger), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 | 324 |
| 323 PendingDistanceItem item = {data_->size(), type.data_size}; | 325 PendingDistanceItem item = {data_->size(), type.data_size}; |
| 324 data_->resize(data_->size() + type.data_size); | 326 data_->resize(data_->size() + type.data_size); |
| 325 pending_distance_items_[value_string] = item; | 327 pending_distance_items_[value_string] = item; |
| 326 | 328 |
| 327 return true; | 329 return true; |
| 328 } | 330 } |
| 329 | 331 |
| 330 bool ValidationTestInputParser::ParseAnchor(const DataType& type, | 332 bool ValidationTestInputParser::ParseAnchor(const DataType& type, |
| 331 const std::string& value_string) { | 333 const std::string& value_string) { |
| 334 if (anchors_.find(value_string) != anchors_.end()) | |
| 335 return false; | |
|
Tom Sepez
2014/06/17 17:38:33
do we want to set *error_message_ here?
yzshen1
2014/06/17 17:41:24
It will be the general error "Error occurred when
| |
| 336 anchors_.insert(value_string); | |
| 337 | |
| 332 std::map<std::string, PendingDistanceItem>::iterator iter = | 338 std::map<std::string, PendingDistanceItem>::iterator iter = |
| 333 pending_distance_items_.find(value_string); | 339 pending_distance_items_.find(value_string); |
| 334 if (iter == pending_distance_items_.end()) | 340 if (iter == pending_distance_items_.end()) |
| 335 return false; | 341 return false; |
| 336 | 342 |
| 337 PendingDistanceItem dist_item = iter->second; | 343 PendingDistanceItem dist_item = iter->second; |
| 338 pending_distance_items_.erase(iter); | 344 pending_distance_items_.erase(iter); |
| 339 | 345 |
| 340 size_t distance = data_->size() - dist_item.pos; | 346 size_t distance = data_->size() - dist_item.pos; |
| 341 switch (dist_item.data_size) { | 347 switch (dist_item.data_size) { |
| 342 case 4: | 348 case 4: |
| 343 return ConvertAndFillData<uint32_t>(dist_item.pos, distance); | 349 return ConvertAndFillData<uint32_t>(dist_item.pos, distance); |
| 344 case 8: | 350 case 8: |
|
Tom Sepez
2014/06/17 17:38:33
similarly, should these also set error_message_ ?
yzshen1
2014/06/17 17:41:23
They all return the message I mentioned above.
| |
| 345 return ConvertAndFillData<uint64_t>(dist_item.pos, distance); | 351 return ConvertAndFillData<uint64_t>(dist_item.pos, distance); |
| 346 default: | 352 default: |
| 347 assert(false); | 353 assert(false); |
| 348 return false; | 354 return false; |
| 349 } | 355 } |
| 350 } | 356 } |
| 351 | 357 |
| 352 bool ValidationTestInputParser::ParseHandles(const DataType& type, | 358 bool ValidationTestInputParser::ParseHandles(const DataType& type, |
| 353 const std::string& value_string) { | 359 const std::string& value_string) { |
| 354 // It should be the first item. | 360 // It should be the first item. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 bool ParseValidationTestInput(const std::string& input, | 397 bool ParseValidationTestInput(const std::string& input, |
| 392 std::vector<uint8_t>* data, | 398 std::vector<uint8_t>* data, |
| 393 size_t* num_handles, | 399 size_t* num_handles, |
| 394 std::string* error_message) { | 400 std::string* error_message) { |
| 395 ValidationTestInputParser parser(input, data, num_handles, error_message); | 401 ValidationTestInputParser parser(input, data, num_handles, error_message); |
| 396 return parser.Run(); | 402 return parser.Run(); |
| 397 } | 403 } |
| 398 | 404 |
| 399 } // namespace test | 405 } // namespace test |
| 400 } // namespace mojo | 406 } // namespace mojo |
| OLD | NEW |