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

Side by Side Diff: mojo/public/c/bindings/tests/message_unittest.cc

Issue 2234063002: Move the C bindings tests to the new location. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_mojo_bindings
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #include <mojo/bindings/message.h>
6
7 #include <stdint.h>
8
9 #include <string>
10 #include <vector>
11
12 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h"
13 #include "mojo/public/cpp/system/macros.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 TEST(MessageValidationTest, InvalidMessageHeader) {
19 struct TestCase {
20 const char* test_case;
21 uint32_t size;
22 const char* name;
23 MojomValidationResult validation_result;
24 };
25
26 TestCase cases[] = {
27 {"[u4]8 // num_bytes\n"
28 "[u4]0 // version",
29 16u, "num_bytes too small", MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER},
30 {"[u4]24 // num_bytes\n"
31 "[u4]0 // version\n"
32 "[u4]0 // name\n"
33 "[u4]0 // flags\n"
34 "[u8]0 // request id",
35 24u, "version 0 header with version 1 size",
36 MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER},
37 {"[u4]16 // num_bytes\n"
38 "[u4]1 // version\n"
39 "[u4]0 // name\n"
40 "[u4]0 // flags",
41 20u, "version 1 header with version 0 size",
42 MOJOM_VALIDATION_UNEXPECTED_STRUCT_HEADER},
43 {"[u4]16 // num_bytes\n"
44 "[u4]0 // version\n"
45 "[u4]0 // name\n"
46 "[u4]1 // flags",
47 16u, "version 0 header with expect response flag",
48 MOJOM_VALIDATION_MESSAGE_HEADER_MISSING_REQUEST_ID},
49 {"[u4]16 // num_bytes\n"
50 "[u4]0 // version\n"
51 "[u4]0 // name\n"
52 "[u4]2 // flags",
53 16u, "version 0 header with is response flag",
54 MOJOM_VALIDATION_MESSAGE_HEADER_MISSING_REQUEST_ID},
55 {"[u4]16 // num_bytes\n"
56 "[u4]0 // version\n"
57 "[u4]0 // name\n"
58 "[u4]3 // flags",
59 16u, "version 0 header with both is/expects response flags",
60 MOJOM_VALIDATION_MESSAGE_HEADER_MISSING_REQUEST_ID},
61 {"[u4]24 // num_bytes\n"
62 "[u4]1 // version\n"
63 "[u4]0 // name\n"
64 "[u4]3 // flags\n"
65 "[u8]0 // request id",
66 24u, "version 1 header with both is/expects response flags",
67 MOJOM_VALIDATION_MESSAGE_HEADER_INVALID_FLAGS},
68 };
69 for (size_t i = 0u; i < MOJO_ARRAYSIZE(cases); ++i) {
70 std::vector<uint8_t> data;
71 std::string parser_error_message;
72 size_t num_handles = 0u;
73 ASSERT_TRUE(mojo::test::ParseValidationTestInput(
74 cases[i].test_case, &data, &num_handles, &parser_error_message))
75 << parser_error_message << " case " << i;
76 EXPECT_EQ(cases[i].validation_result,
77 MojomMessage_ValidateHeader(data.data(), cases[i].size))
78 << cases[i].name << " case " << i;
79 }
80 }
81
82 TEST(MessageValidationTest, ValidMessageHeader) {
83 struct TestCase {
84 const char* test_case;
85 size_t size;
86 };
87
88 TestCase cases[] = {
89 {"[u4]16 // num_bytes\n"
90 "[u4]0 // version\n"
91 "[u4]0 // name\n"
92 "[u4]0 // flags",
93 16u}, // version 0 header
94 {"[u4]24 // num_bytes\n"
95 "[u4]1 // version\n"
96 "[u4]0 // name\n"
97 "[u4]1 // flags\n"
98 "[u8]0 // request_id",
99 24u}, // version 1 request
100 {"[u4]24 // num_bytes\n"
101 "[u4]1 // version\n"
102 "[u4]0 // name\n"
103 "[u4]2 // flags\n"
104 "[u8]0 // request_id",
105 24u}, // version 1 response
106 {"[u4]24 // num_bytes\n"
107 "[u4]1 // version\n"
108 "[u4]0 // name\n"
109 "[u4]0 // flags\n"
110 "[u8]0 // request id",
111 24u}, // version 1 header without is/expects response flags
112 };
113
114 for (size_t i = 0u; i < MOJO_ARRAYSIZE(cases); ++i) {
115 std::vector<uint8_t> data;
116 std::string parser_error_message;
117 size_t num_handles = 0u;
118 ASSERT_TRUE(mojo::test::ParseValidationTestInput(
119 cases[i].test_case, &data, &num_handles, &parser_error_message))
120 << parser_error_message << " case " << i;
121 EXPECT_EQ(MOJOM_VALIDATION_ERROR_NONE,
122 MojomMessage_ValidateHeader(data.data(), cases[i].size))
123 << " case " << i;
124 }
125 }
126
127 } // namespace
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/tests/buffer_unittest.cc ('k') | mojo/public/c/bindings/tests/struct_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698