OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_VALIDATION_TEST_INPUT_PARSER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_VALIDATION_TEST_INPUT_PARSER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 namespace mojo { |
| 14 namespace test { |
| 15 |
| 16 // Input Format of Mojo Message Validation Tests. |
| 17 // |
| 18 // Data items are separated by whitespaces: |
| 19 // - ' ' (0x20) space; |
| 20 // - '\t' (0x09) horizontal tab; |
| 21 // - '\n' (0x0a) newline; |
| 22 // - '\r' (0x0d) carriage return. |
| 23 // A comment starts with //, extending to the end of the line. |
| 24 // Each data item is of the format [<type>]<value>. The types defined and the |
| 25 // corresponding value formats are described below. |
| 26 // |
| 27 // Type: u1 / u2 / u4 / u8 |
| 28 // Description: Little-endian 1/2/4/8-byte unsigned integer. |
| 29 // Value Format: |
| 30 // - Decimal integer: 0|[1-9][0-9]* |
| 31 // - Hexadecimal integer: 0[xX][0-9a-fA-F]+ |
| 32 // - The type prefix (including the square brackets) of 1-byte unsigned |
| 33 // integer is optional. |
| 34 // |
| 35 // Type: s1 / s2 / s4 / s8 |
| 36 // Description: Little-endian 1/2/4/8-byte signed integer. |
| 37 // Value Format: |
| 38 // - Decimal integer: [-+]?(0|[1-9][0-9]*) |
| 39 // - Hexadecimal integer: [-+]?0[xX][0-9a-fA-F]+ |
| 40 // |
| 41 // Type: b |
| 42 // Description: Binary sequence of 1 byte. |
| 43 // Value Format: [01]{8} |
| 44 // |
| 45 // Type: f / d |
| 46 // Description: Little-endian IEEE-754 format of float (4 bytes) and double (8 |
| 47 // bytes). |
| 48 // Value Format: [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? |
| 49 // |
| 50 // Type: dist4 / dist8 |
| 51 // Description: Little-endian 4/8-byte unsigned integer. The actual value is set |
| 52 // to the byte distance from the location of this integer to the location of the |
| 53 // anchr item with the same ID. A dist8 and anchr pair can be used to easily |
| 54 // represent an encoded pointer. A dist4 and anchr pair can be used to easily |
| 55 // calculate struct/array size. |
| 56 // Value Format: The value is an ID: [0-9a-zA-Z_]+ |
| 57 // |
| 58 // Type: anchr |
| 59 // Description: Mark an anchor location. It doesn’t translate into any actual |
| 60 // data. |
| 61 // Value Format: The value is an ID of the same format as that of dist4/8. |
| 62 // |
| 63 // EXAMPLE: |
| 64 // |
| 65 // Suppose you have the following Mojo types defined: |
| 66 // struct Bar { |
| 67 // int32 a; |
| 68 // bool b; |
| 69 // bool c; |
| 70 // }; |
| 71 // struct Foo { |
| 72 // Bar x; |
| 73 // uint32 y; |
| 74 // }; |
| 75 // |
| 76 // The following describes a valid message whose payload is a Foo struct: |
| 77 // // message header |
| 78 // [dist4]message_header // num_bytes |
| 79 // [u4]3 // num_fields |
| 80 // [u4]0 // type |
| 81 // [u4]1 // flags |
| 82 // [u8]1234 // request_id |
| 83 // [anchr]message_header |
| 84 // |
| 85 // // payload |
| 86 // [dist4]foo // num_bytes |
| 87 // [u4]2 // num_fields |
| 88 // [dist8]bar_ptr // x |
| 89 // [u4]0xABCD // y |
| 90 // [u4]0 // padding |
| 91 // [anchr]foo |
| 92 // |
| 93 // [anchr]bar_ptr |
| 94 // [dist4]bar // num_bytes |
| 95 // [u4]3 // num_fields |
| 96 // [s4]-1 // a |
| 97 // [b]00000010 // b and c |
| 98 // 0 0 0 // padding |
| 99 // [anchr]bar |
| 100 |
| 101 // Parses validation test input. |
| 102 // On success, |parsed_input| stores the parsing result and |error_message| is |
| 103 // cleared; on failure, |error_message| is set to a message describing the error |
| 104 // and |parsed_input| is cleared. |
| 105 // Note: For now, this method only works on little-endian platforms. |
| 106 bool ParseValidationTestInput(const std::string& input, |
| 107 std::vector<uint8_t>* parsed_input, |
| 108 std::string* error_message); |
| 109 |
| 110 } // namespace test |
| 111 } // namespace mojo |
| 112 |
| 113 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_VALIDATION_TEST_INPUT_PARSER_H_ |
OLD | NEW |