OLD | NEW |
---|---|
(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 <sstream> | |
6 | |
7 #include "mojo/public/cpp/bindings/array.h" | |
8 #include "mojo/public/cpp/bindings/formatting.h" | |
viettrungluu
2016/01/26 23:19:40
nit: The convention is to include the particular f
jeffbrown
2016/01/26 23:40:46
Yeah, none of the other unit tests in this directo
| |
9 #include "mojo/public/cpp/bindings/map.h" | |
10 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace mojo { | |
14 namespace test { | |
15 namespace { | |
viettrungluu
2016/01/26 23:19:40
Note: You can probably put everything in an anonym
jeffbrown
2016/01/26 23:40:46
Acknowledged.
| |
16 RectPtr MakeRect(int32_t factor = 1) { | |
17 RectPtr rect(Rect::New()); | |
18 rect->x = 1 * factor; | |
19 rect->y = 2 * factor; | |
20 rect->width = 10 * factor; | |
21 rect->height = 20 * factor; | |
22 return rect; | |
23 } | |
24 } // namespace | |
25 | |
26 std::ostream& operator<<(std::ostream& os, const Rect& value) { | |
27 return os << "{x=" << value.x << ", y=" << value.y | |
28 << ", width=" << value.width << ", height=" << value.height << "}"; | |
29 } | |
30 | |
31 std::ostream& operator<<(std::ostream& os, const RectPair& value) { | |
32 return os << "{first=" << value.first << ", second=" << value.second << "}"; | |
33 } | |
34 | |
35 TEST(FormattingTest, Arrays) { | |
36 Array<int32_t> null_array; | |
37 Array<int32_t> empty_array; | |
38 empty_array.resize(0); | |
39 Array<int32_t> one_element_array; | |
40 one_element_array.push_back(123); | |
41 Array<int32_t> three_element_array; | |
42 three_element_array.push_back(4); | |
43 three_element_array.push_back(5); | |
44 three_element_array.push_back(6); | |
45 | |
46 std::ostringstream so; | |
47 so << "null_array=" << null_array << ", empty_array=" << empty_array | |
48 << ", one_element_array=" << one_element_array | |
49 << ", three_element_array=" << three_element_array; | |
50 | |
51 EXPECT_EQ( | |
52 "null_array=null, " | |
53 "empty_array=[], " | |
54 "one_element_array=[123], " | |
55 "three_element_array=[4, 5, 6]", | |
56 so.str()); | |
57 } | |
58 | |
59 TEST(FormattingTest, Maps) { | |
60 Map<int32_t, std::string> null_map; | |
61 Map<int32_t, std::string> empty_map; | |
62 empty_map.mark_non_null(); | |
63 Map<int32_t, std::string> one_element_map; | |
64 one_element_map.insert(123, "abc"); | |
65 Map<int32_t, std::string> three_element_map; | |
66 three_element_map.insert(4, "d"); | |
67 three_element_map.insert(5, "e"); | |
68 three_element_map.insert(6, "f"); | |
69 | |
70 std::ostringstream so; | |
71 so << "null_map=" << null_map << ", empty_map=" << empty_map | |
72 << ", one_element_map=" << one_element_map | |
73 << ", three_element_map=" << three_element_map; | |
74 | |
75 EXPECT_EQ( | |
76 "null_map=null, " | |
77 "empty_map={}, " | |
78 "one_element_map={123: abc}, " | |
viettrungluu
2016/01/26 23:19:40
Side comment (not for this CL -- for future refere
jeffbrown
2016/01/26 23:40:46
Starting to think you may be right, but the lack o
| |
79 "three_element_map={4: d, 5: e, 6: f}", | |
80 so.str()); | |
81 } | |
82 | |
83 TEST(FormattingTest, Structs) { | |
84 InlinedStructPtr<Rect> inlined_struct_ptr = MakeRect(1); | |
85 InlinedStructPtr<Rect> null_inlined_struct_ptr; | |
86 StructPtr<RectPair> struct_ptr = RectPair::New(); | |
87 struct_ptr->first = MakeRect(2); | |
88 StructPtr<RectPair> null_struct_ptr; | |
89 | |
90 std::ostringstream so; | |
91 so << "inlined_struct_ptr=" << inlined_struct_ptr | |
92 << ", null_inlined_struct_ptr=" << null_inlined_struct_ptr | |
93 << ", struct_ptr=" << struct_ptr | |
94 << ", null_struct_ptr=" << null_struct_ptr; | |
95 EXPECT_EQ( | |
96 "inlined_struct_ptr={x=1, y=2, width=10, height=20}, " | |
97 "null_inlined_struct_ptr=null, " | |
98 "struct_ptr={first={x=2, y=4, width=20, height=40}, second=null}, " | |
99 "null_struct_ptr=null", | |
100 so.str()); | |
101 } | |
102 | |
103 } // namespace test | |
104 } // namespace mojo | |
OLD | NEW |