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

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

Issue 1532993002: Add output formatters for more mojom types. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-9
Patch Set: rebase Created 4 years, 10 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/bindings/array.h" 5 #include "mojo/public/cpp/bindings/array.h"
6 #include "mojo/public/cpp/bindings/formatting.h"
6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
7 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" 8 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 9 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
9 #include "mojo/public/cpp/bindings/lib/map_serialization.h" 10 #include "mojo/public/cpp/bindings/lib/map_serialization.h"
10 #include "mojo/public/cpp/bindings/lib/validate_params.h" 11 #include "mojo/public/cpp/bindings/lib/validate_params.h"
11 #include "mojo/public/cpp/bindings/map.h" 12 #include "mojo/public/cpp/bindings/map.h"
12 #include "mojo/public/cpp/bindings/string.h" 13 #include "mojo/public/cpp/bindings/string.h"
13 #include "mojo/public/cpp/bindings/tests/container_test_util.h" 14 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
14 #include "mojo/public/cpp/environment/environment.h" 15 #include "mojo/public/cpp/environment/environment.h"
15 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h" 16 #include "mojo/public/interfaces/bindings/tests/rect.mojom.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace mojo { 19 namespace mojo {
19 namespace test { 20 namespace test {
20 21
21 namespace { 22 namespace {
22 23
23 using mojo::internal::Array_Data; 24 using mojo::internal::Array_Data;
24 using mojo::internal::ArrayValidateParams; 25 using mojo::internal::ArrayValidateParams;
25 using mojo::internal::FixedBufferForTesting; 26 using mojo::internal::FixedBufferForTesting;
26 using mojo::internal::Map_Data; 27 using mojo::internal::Map_Data;
27 using mojo::internal::String_Data; 28 using mojo::internal::String_Data;
28 using mojo::internal::ValidationError; 29 using mojo::internal::ValidationError;
29 30
30 struct StringIntData { 31 struct StringIntData {
31 const char* string_data; 32 const char* string_data;
32 int int_data; 33 int int_data;
33 } kStringIntData[] = { 34 } kStringIntData[] = {
34 {"one", 1}, 35 {"one", 1},
35 {"two", 2}, 36 {"two", 2},
36 {"three", 3}, 37 {"three", 3},
37 {"four", 4}, 38 {"four", 4},
38 }; 39 };
39 40
40 const size_t kStringIntDataSize = 4; 41 const size_t kStringIntDataSize = 4;
41 42
42 class MapTest : public testing::Test { 43 class MapTest : public testing::Test {
43 public: 44 public:
44 ~MapTest() override {} 45 ~MapTest() override {}
45 46
46 private: 47 private:
47 Environment env_; 48 Environment env_;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 EXPECT_EQ(2u, map2.size()); 427 EXPECT_EQ(2u, map2.size());
427 EXPECT_FALSE(map2.is_null()); 428 EXPECT_FALSE(map2.is_null());
428 EXPECT_TRUE(map2[0].is_null()); 429 EXPECT_TRUE(map2[0].is_null());
429 EXPECT_FALSE(map2[1].is_null()); 430 EXPECT_FALSE(map2[1].is_null());
430 EXPECT_EQ(1, map2[1]->x); 431 EXPECT_EQ(1, map2[1]->x);
431 EXPECT_EQ(2, map2[1]->y); 432 EXPECT_EQ(2, map2[1]->y);
432 EXPECT_EQ(3, map2[1]->width); 433 EXPECT_EQ(3, map2[1]->width);
433 EXPECT_EQ(4, map2[1]->height); 434 EXPECT_EQ(4, map2[1]->height);
434 } 435 }
435 436
437 TEST_F(MapTest, OutputFormatting) {
438 Map<int32_t, std::string> null_map;
439 Map<int32_t, std::string> empty_map;
440 empty_map.mark_non_null();
441 Map<int32_t, std::string> one_element_map;
442 one_element_map.insert(123, "abc");
443 Map<int32_t, std::string> three_element_map;
444 three_element_map.insert(4, "d");
445 three_element_map.insert(5, "e");
446 three_element_map.insert(6, "f");
447
448 std::ostringstream so;
449 so << "null_map=" << null_map << ", empty_map=" << empty_map
450 << ", one_element_map=" << one_element_map
451 << ", three_element_map=" << three_element_map;
452
453 EXPECT_EQ(
454 "null_map=null, "
455 "empty_map=[], "
456 "one_element_map=[{123: abc}], "
457 "three_element_map=[{4: d}, {5: e}, {6: f}]",
458 so.str());
459 }
460
436 } // namespace 461 } // namespace
437 } // namespace test 462 } // namespace test
438 } // namespace mojo 463 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698