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

Side by Side Diff: mojo/public/cpp/bindings/tests/union_unittest.cc

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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 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 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
6 #include "mojo/public/cpp/bindings/string.h"
7 #include "mojo/public/cpp/environment/environment.h"
8 #include "mojo/public/interfaces/bindings/tests/test_unions.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mojo {
12 namespace test {
13
14 TEST(UnionTest, PlainOldDataGetterSetter) {
15 PodUnionPtr pod(PodUnion::New());
16
17 pod->set_f_int8(10);
18 EXPECT_EQ(10, pod->get_f_int8());
19 EXPECT_TRUE(pod->is_f_int8());
20 EXPECT_FALSE(pod->is_f_int8_other());
21 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT8);
22
23 pod->set_f_uint8(11);
24 EXPECT_EQ(11, pod->get_f_uint8());
25 EXPECT_TRUE(pod->is_f_uint8());
26 EXPECT_FALSE(pod->is_f_int8());
27 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT8);
28
29 pod->set_f_int16(12);
30 EXPECT_EQ(12, pod->get_f_int16());
31 EXPECT_TRUE(pod->is_f_int16());
32 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT16);
33
34 pod->set_f_uint16(13);
35 EXPECT_EQ(13, pod->get_f_uint16());
36 EXPECT_TRUE(pod->is_f_uint16());
37 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT16);
38
39 pod->set_f_int32(14);
40 EXPECT_EQ(14, pod->get_f_int32());
41 EXPECT_TRUE(pod->is_f_int32());
42 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT32);
43
44 pod->set_f_uint32(static_cast<uint32_t>(15));
45 EXPECT_EQ(static_cast<uint32_t>(15), pod->get_f_uint32());
46 EXPECT_TRUE(pod->is_f_uint32());
47 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT32);
48
49 pod->set_f_int64(16);
50 EXPECT_EQ(16, pod->get_f_int64());
51 EXPECT_TRUE(pod->is_f_int64());
52 EXPECT_EQ(pod->which(), PodUnion::Tag::F_INT64);
53
54 pod->set_f_uint64(static_cast<uint64_t>(17));
55 EXPECT_EQ(static_cast<uint64_t>(17), pod->get_f_uint64());
56 EXPECT_TRUE(pod->is_f_uint64());
57 EXPECT_EQ(pod->which(), PodUnion::Tag::F_UINT64);
58
59 pod->set_f_float(1.5);
60 EXPECT_EQ(1.5, pod->get_f_float());
61 EXPECT_TRUE(pod->is_f_float());
62 EXPECT_EQ(pod->which(), PodUnion::Tag::F_FLOAT);
63
64 pod->set_f_double(1.9);
65 EXPECT_EQ(1.9, pod->get_f_double());
66 EXPECT_TRUE(pod->is_f_double());
67 EXPECT_EQ(pod->which(), PodUnion::Tag::F_DOUBLE);
68
69 pod->set_f_bool(true);
70 EXPECT_TRUE(pod->get_f_bool());
71 pod->set_f_bool(false);
72 EXPECT_FALSE(pod->get_f_bool());
73 EXPECT_TRUE(pod->is_f_bool());
74 EXPECT_EQ(pod->which(), PodUnion::Tag::F_BOOL);
75 }
76
77 TEST(UnionTest, PodEquals) {
78 PodUnionPtr pod1(PodUnion::New());
79 PodUnionPtr pod2(PodUnion::New());
80
81 pod1->set_f_int8(10);
82 pod2->set_f_int8(10);
83 EXPECT_TRUE(pod1.Equals(pod2));
84
85 pod2->set_f_int8(11);
86 EXPECT_FALSE(pod1.Equals(pod2));
87
88 pod2->set_f_int8_other(10);
89 EXPECT_FALSE(pod1.Equals(pod2));
90 }
91
92 TEST(UnionTest, PodClone) {
93 PodUnionPtr pod(PodUnion::New());
94 pod->set_f_int8(10);
95
96 PodUnionPtr pod_clone = pod.Clone();
97 EXPECT_EQ(10, pod_clone->get_f_int8());
98 EXPECT_TRUE(pod_clone->is_f_int8());
99 EXPECT_EQ(pod_clone->which(), PodUnion::Tag::F_INT8);
100 }
101
102 TEST(UnionTest, SerializationPod) {
103 PodUnionPtr pod1(PodUnion::New());
104 pod1->set_f_int8(10);
105
106 size_t size = GetSerializedSize_(pod1);
107 EXPECT_EQ(16U, size);
108
109 mojo::internal::FixedBuffer buf(size);
110 internal::PodUnion_Data* data;
111 Serialize_(pod1.Pass(), &buf, &data);
112
113 PodUnionPtr pod2;
114 Deserialize_(data, &pod2);
115
116 EXPECT_EQ(10, pod2->get_f_int8());
117 EXPECT_TRUE(pod2->is_f_int8());
118 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_INT8);
119 }
120
121 TEST(UnionTest, StringGetterSetter) {
122 PodUnionPtr pod(PodUnion::New());
123
124 String hello("hello world");
125 pod->set_f_string(hello);
126 EXPECT_EQ(hello, pod->get_f_string());
127 EXPECT_TRUE(pod->is_f_string());
128 EXPECT_EQ(pod->which(), PodUnion::Tag::F_STRING);
129 }
130
131 TEST(UnionTest, StringEquals) {
132 PodUnionPtr pod1(PodUnion::New());
133 PodUnionPtr pod2(PodUnion::New());
134
135 pod1->set_f_string("hello world");
136 pod2->set_f_string("hello world");
137 EXPECT_TRUE(pod1.Equals(pod2));
138
139 pod2->set_f_string("hello universe");
140 EXPECT_FALSE(pod1.Equals(pod2));
141 }
142
143 TEST(UnionTest, StringClone) {
144 PodUnionPtr pod(PodUnion::New());
145
146 String hello("hello world");
147 pod->set_f_string(hello);
148 PodUnionPtr pod_clone = pod.Clone();
149 EXPECT_EQ(hello, pod_clone->get_f_string());
150 EXPECT_TRUE(pod_clone->is_f_string());
151 EXPECT_EQ(pod_clone->which(), PodUnion::Tag::F_STRING);
152 }
153
154 TEST(UnionTest, StringSerialization) {
155 PodUnionPtr pod1(PodUnion::New());
156
157 String hello("hello world");
158 pod1->set_f_string(hello);
159
160 size_t size = GetSerializedSize_(pod1);
161 mojo::internal::FixedBuffer buf(size);
162 internal::PodUnion_Data* data;
163 Serialize_(pod1.Pass(), &buf, &data);
164
165 PodUnionPtr pod2;
166 Deserialize_(data, &pod2);
167 EXPECT_EQ(hello, pod2->get_f_string());
168 EXPECT_TRUE(pod2->is_f_string());
169 EXPECT_EQ(pod2->which(), PodUnion::Tag::F_STRING);
170 }
171 } // namespace test
172 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698