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

Unified Diff: mojo/public/cpp/bindings/tests/struct_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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/struct_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/struct_unittest.cc b/mojo/public/cpp/bindings/tests/struct_unittest.cc
deleted file mode 100644
index 52d1313a489f3ce660df677aa1b08667df8e5e4a..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/tests/struct_unittest.cc
+++ /dev/null
@@ -1,201 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
-#include "mojo/public/cpp/environment/environment.h"
-#include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace test {
-namespace {
-
-RectPtr MakeRect(int32_t factor = 1) {
- RectPtr rect(Rect::New());
- rect->x = 1 * factor;
- rect->y = 2 * factor;
- rect->width = 10 * factor;
- rect->height = 20 * factor;
- return rect.Pass();
-}
-
-void CheckRect(const Rect& rect, int32_t factor = 1) {
- EXPECT_EQ(1 * factor, rect.x);
- EXPECT_EQ(2 * factor, rect.y);
- EXPECT_EQ(10 * factor, rect.width);
- EXPECT_EQ(20 * factor, rect.height);
-}
-
-class StructTest : public testing::Test {
- public:
- ~StructTest() override {}
-
- private:
- Environment env_;
-};
-
-} // namespace
-
-TEST_F(StructTest, Rect) {
- RectPtr rect;
- EXPECT_TRUE(rect.is_null());
- EXPECT_TRUE(!rect);
- EXPECT_FALSE(rect);
-
- rect = nullptr;
- EXPECT_TRUE(rect.is_null());
- EXPECT_TRUE(!rect);
- EXPECT_FALSE(rect);
-
- rect = MakeRect();
- EXPECT_FALSE(rect.is_null());
- EXPECT_FALSE(!rect);
- EXPECT_TRUE(rect);
-
- RectPtr null_rect = nullptr;
- EXPECT_TRUE(null_rect.is_null());
- EXPECT_TRUE(!null_rect);
- EXPECT_FALSE(null_rect);
-
- CheckRect(*rect);
-}
-
-TEST_F(StructTest, Clone) {
- NamedRegionPtr region;
-
- NamedRegionPtr clone_region = region.Clone();
- EXPECT_TRUE(clone_region.is_null());
-
- region = NamedRegion::New();
- clone_region = region.Clone();
- EXPECT_TRUE(clone_region->name.is_null());
- EXPECT_TRUE(clone_region->rects.is_null());
-
- region->name = "hello world";
- clone_region = region.Clone();
- EXPECT_EQ(region->name, clone_region->name);
-
- region->rects = Array<RectPtr>(2);
- region->rects[1] = MakeRect();
- clone_region = region.Clone();
- EXPECT_EQ(2u, clone_region->rects.size());
- EXPECT_TRUE(clone_region->rects[0].is_null());
- CheckRect(*clone_region->rects[1]);
-
- // NoDefaultFieldValues contains handles, so Clone() is not available, but
- // NoDefaultFieldValuesPtr should still compile.
- NoDefaultFieldValuesPtr no_default_field_values(NoDefaultFieldValues::New());
- EXPECT_FALSE(no_default_field_values->f13.is_valid());
-}
-
-// Serialization test of a struct with no pointer or handle members.
-TEST_F(StructTest, Serialization_Basic) {
- RectPtr rect(MakeRect());
-
- size_t size = GetSerializedSize_(rect);
- EXPECT_EQ(8U + 16U, size);
-
- mojo::internal::FixedBuffer buf(size);
- internal::Rect_Data* data;
- Serialize_(rect.Pass(), &buf, &data);
-
- RectPtr rect2;
- Deserialize_(data, &rect2);
-
- CheckRect(*rect2);
-}
-
-// Construction of a struct with struct pointers from null.
-TEST_F(StructTest, Construction_StructPointers) {
- RectPairPtr pair;
- EXPECT_TRUE(pair.is_null());
-
- pair = RectPair::New();
- EXPECT_FALSE(pair.is_null());
- EXPECT_TRUE(pair->first.is_null());
- EXPECT_TRUE(pair->first.is_null());
-
- pair = nullptr;
- EXPECT_TRUE(pair.is_null());
-}
-
-// Serialization test of a struct with struct pointers.
-TEST_F(StructTest, Serialization_StructPointers) {
- RectPairPtr pair(RectPair::New());
- pair->first = MakeRect();
- pair->second = MakeRect();
-
- size_t size = GetSerializedSize_(pair);
- EXPECT_EQ(8U + 16U + 2 * (8U + 16U), size);
-
- mojo::internal::FixedBuffer buf(size);
- internal::RectPair_Data* data;
- Serialize_(pair.Pass(), &buf, &data);
-
- RectPairPtr pair2;
- Deserialize_(data, &pair2);
-
- CheckRect(*pair2->first);
- CheckRect(*pair2->second);
-}
-
-// Serialization test of a struct with an array member.
-TEST_F(StructTest, Serialization_ArrayPointers) {
- NamedRegionPtr region(NamedRegion::New());
- region->name = "region";
- region->rects = Array<RectPtr>::New(4);
- for (size_t i = 0; i < region->rects.size(); ++i)
- region->rects[i] = MakeRect(static_cast<int32_t>(i) + 1);
-
- size_t size = GetSerializedSize_(region);
- EXPECT_EQ(8U + // header
- 8U + // name pointer
- 8U + // rects pointer
- 8U + // name header
- 8U + // name payload (rounded up)
- 8U + // rects header
- 4 * 8U + // rects payload (four pointers)
- 4 * (8U + // rect header
- 16U), // rect payload (four ints)
- size);
-
- mojo::internal::FixedBuffer buf(size);
- internal::NamedRegion_Data* data;
- Serialize_(region.Pass(), &buf, &data);
-
- NamedRegionPtr region2;
- Deserialize_(data, &region2);
-
- EXPECT_EQ(String("region"), region2->name);
-
- EXPECT_EQ(4U, region2->rects.size());
- for (size_t i = 0; i < region2->rects.size(); ++i)
- CheckRect(*region2->rects[i], static_cast<int32_t>(i) + 1);
-}
-
-// Serialization test of a struct with null array pointers.
-TEST_F(StructTest, Serialization_NullArrayPointers) {
- NamedRegionPtr region(NamedRegion::New());
- EXPECT_TRUE(region->name.is_null());
- EXPECT_TRUE(region->rects.is_null());
-
- size_t size = GetSerializedSize_(region);
- EXPECT_EQ(8U + // header
- 8U + // name pointer
- 8U, // rects pointer
- size);
-
- mojo::internal::FixedBuffer buf(size);
- internal::NamedRegion_Data* data;
- Serialize_(region.Pass(), &buf, &data);
-
- NamedRegionPtr region2;
- Deserialize_(data, &region2);
-
- EXPECT_TRUE(region2->name.is_null());
- EXPECT_TRUE(region2->rects.is_null());
-}
-
-} // namespace test
-} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/tests/string_unittest.cc ('k') | mojo/public/cpp/bindings/tests/type_conversion_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698