OLD | NEW |
| (Empty) |
1 // Copyright 2013 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/public/libs/message/message.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "mojo/public/libs/message/message_builder.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace mojo { | |
13 | |
14 TEST(Message, Empty) { | |
15 Message message; | |
16 EXPECT_EQ(0U, message.data().size()); | |
17 } | |
18 | |
19 TEST(Message, Builder_Empty) { | |
20 MessageBuilder builder; | |
21 EXPECT_TRUE(builder.Initialize(1)); | |
22 | |
23 Message message; | |
24 EXPECT_TRUE(builder.Finish(&message)); | |
25 | |
26 EXPECT_EQ(message.data().size(), 8U); | |
27 } | |
28 | |
29 TEST(Message, Builder_Basic) { | |
30 MessageBuilder builder; | |
31 EXPECT_TRUE(builder.Initialize(1)); | |
32 | |
33 EXPECT_TRUE(builder.Append(1, 2U)); | |
34 | |
35 Message message; | |
36 EXPECT_TRUE(builder.Finish(&message)); | |
37 | |
38 EXPECT_EQ(message.data().size(), 8U + 8U); | |
39 } | |
40 | |
41 TEST(Message, Builder_BasicPair) { | |
42 MessageBuilder builder; | |
43 EXPECT_TRUE(builder.Initialize(1)); | |
44 | |
45 EXPECT_TRUE(builder.Append(1, 100)); | |
46 EXPECT_TRUE(builder.Append(2, 200)); | |
47 | |
48 Message message; | |
49 EXPECT_TRUE(builder.Finish(&message)); | |
50 | |
51 EXPECT_EQ(message.data().size(), 8U + 8U + 8U); | |
52 } | |
53 | |
54 TEST(Message, Builder_BasicString) { | |
55 MessageBuilder builder; | |
56 EXPECT_TRUE(builder.Initialize(1)); | |
57 | |
58 EXPECT_TRUE(builder.Append(1, 100)); | |
59 EXPECT_TRUE(builder.Append(2, 200)); | |
60 EXPECT_TRUE(builder.Append(3, std::string("hello world"))); | |
61 | |
62 Message message; | |
63 EXPECT_TRUE(builder.Finish(&message)); | |
64 | |
65 EXPECT_EQ(message.data().size(), 8U + 8U + 8U + 8U + 16U); | |
66 } | |
67 | |
68 TEST(Message, Builder_BasicHandle) { | |
69 MessageBuilder builder; | |
70 EXPECT_TRUE(builder.Initialize(1)); | |
71 | |
72 mojo::Handle handle = { 1 }; | |
73 | |
74 EXPECT_TRUE(builder.Append(1, handle)); | |
75 | |
76 Message message; | |
77 EXPECT_TRUE(builder.Finish(&message)); | |
78 | |
79 EXPECT_EQ(message.data().size(), 8U + 8U); | |
80 EXPECT_EQ(message.handles().size(), 1U); | |
81 } | |
82 | |
83 } // namespace mojo | |
OLD | NEW |