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

Side by Side Diff: mojo/public/cpp/bindings/tests/struct_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, 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
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 <string.h> 5 #include <string.h>
6 #include <type_traits> 6 #include <type_traits>
7 7
8 #include "mojo/public/cpp/bindings/formatting.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/validation_errors.h" 10 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
10 #include "mojo/public/cpp/environment/environment.h" 11 #include "mojo/public/cpp/environment/environment.h"
11 #include "mojo/public/cpp/system/message_pipe.h" 12 #include "mojo/public/cpp/system/message_pipe.h"
12 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" 13 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 namespace test { 17 namespace test {
17 namespace { 18 namespace {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 MultiVersionStructV0Ptr expected_output(MultiVersionStructV0::New()); 457 MultiVersionStructV0Ptr expected_output(MultiVersionStructV0::New());
457 expected_output->f_int32 = 123; 458 expected_output->f_int32 = 123;
458 459
459 MultiVersionStructV0Ptr output = 460 MultiVersionStructV0Ptr output =
460 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass()); 461 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass());
461 EXPECT_TRUE(output); 462 EXPECT_TRUE(output);
462 EXPECT_TRUE(output->Equals(*expected_output)); 463 EXPECT_TRUE(output->Equals(*expected_output));
463 } 464 }
464 } 465 }
465 466
467 static std::ostream& operator<<(std::ostream& os, const Rect& value) {
468 return os << "{x=" << value.x << ", y=" << value.y
469 << ", width=" << value.width << ", height=" << value.height << "}";
470 }
471
472 static std::ostream& operator<<(std::ostream& os, const RectPair& value) {
473 return os << "{first=" << value.first << ", second=" << value.second << "}";
474 }
475
476 TEST_F(StructTest, OutputFormatting) {
477 InlinedStructPtr<Rect> inlined_struct_ptr = MakeRect(1);
478 InlinedStructPtr<Rect> null_inlined_struct_ptr;
479 StructPtr<RectPair> struct_ptr = RectPair::New();
480 struct_ptr->first = MakeRect(2);
481 StructPtr<RectPair> null_struct_ptr;
482
483 std::ostringstream so;
484 so << "inlined_struct_ptr=" << inlined_struct_ptr
485 << ", null_inlined_struct_ptr=" << null_inlined_struct_ptr
486 << ", struct_ptr=" << struct_ptr
487 << ", null_struct_ptr=" << null_struct_ptr;
488 EXPECT_EQ(
489 "inlined_struct_ptr={x=1, y=2, width=10, height=20}, "
490 "null_inlined_struct_ptr=null, "
491 "struct_ptr={first={x=2, y=4, width=20, height=40}, second=null}, "
492 "null_struct_ptr=null",
493 so.str());
494 }
495
466 } // namespace test 496 } // namespace test
467 } // namespace mojo 497 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698