OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 <memory> | |
6 | |
7 #include "gtest/gtest.h" | |
8 #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" | |
9 | |
10 using sample::SampleInterface; | |
11 using sample::SampleInterface_SampleMethod1_Params; | |
12 using sample::SampleInterface_SampleMethod1_ResponseParams; | |
13 | |
14 namespace mojo { | |
15 namespace test { | |
16 namespace { | |
17 | |
18 // Test the validity of the generated ordinals for interface methods. | |
19 TEST(SampleInterfaceOrdinals, CheckGeneratedOrdinals) { | |
20 EXPECT_EQ(0U, static_cast<uint32_t>( | |
21 SampleInterface::MessageOrdinals::SampleMethod0)); | |
22 EXPECT_EQ(1U, static_cast<uint32_t>( | |
23 SampleInterface::MessageOrdinals::SampleMethod1)); | |
24 EXPECT_EQ(2U, static_cast<uint32_t>( | |
25 SampleInterface::MessageOrdinals::SampleMethod2)); | |
26 } | |
27 | |
28 // Test that a request params struct is generated for interface methods, and | |
29 // test that it is serializable. | |
30 TEST(SampleInterfaceGeneratedStructs, RequestStruct) { | |
31 SampleInterface_SampleMethod1_Params params; | |
32 params.in1 = 123; | |
33 params.in2.reset(); | |
34 | |
35 size_t size = params.GetSerializedSize(); | |
36 EXPECT_EQ(8U // Struct header | |
37 + (4U // |in1| field | |
38 + 8U) // |in2| offset to string (which is null) | |
39 + 4U, // padding to make the struct 8-byte aligned | |
40 size); | |
41 | |
42 std::unique_ptr<char[]> bytes(new char[size]); | |
43 EXPECT_TRUE(params.Serialize(bytes.get(), size)); | |
44 | |
45 auto* params_data = reinterpret_cast< | |
46 sample::internal::SampleInterface_SampleMethod1_Params_Data*>( | |
47 bytes.get()); | |
48 EXPECT_EQ(123, params_data->in1); | |
49 EXPECT_EQ(0UL, params_data->in2.offset); | |
50 } | |
51 | |
52 // Test that a response params struct is generated for interface methods, and | |
53 // test that it is serializable. | |
54 TEST(SampleInterfaceGeneratedStructs, ResponseStruct) { | |
55 SampleInterface_SampleMethod1_ResponseParams params; | |
56 params.out1.reset(); | |
57 params.out2 = sample::Enum::VALUE; | |
58 | |
59 size_t size = params.GetSerializedSize(); | |
60 EXPECT_EQ(8U // Struct header | |
61 + (8U // |out1| offset to string (which is null) | |
62 + 4U) // |out2| enum | |
63 + 4U, // padding to make the struct 8-byte aligned | |
64 size); | |
65 | |
66 std::unique_ptr<char[]> bytes(new char[size]); | |
67 EXPECT_TRUE(params.Serialize(bytes.get(), size)); | |
68 | |
69 auto* params_data = reinterpret_cast< | |
70 sample::internal::SampleInterface_SampleMethod1_ResponseParams_Data*>( | |
71 bytes.get()); | |
72 EXPECT_EQ(0UL, params_data->out1.offset); | |
73 EXPECT_EQ(sample::Enum::VALUE, static_cast<sample::Enum>(params_data->out2)); | |
74 } | |
75 | |
76 } // namespace | |
77 } // namespace test | |
78 } // namespace mojo | |
OLD | NEW |