Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: mojo/public/cpp/bindings/tests/validation_test_input_parser.h

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

Powered by Google App Engine
This is Rietveld 408576698