chromium/mojo/public/cpp/bindings/tests/equals_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <utility>

#include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace test {

namespace {

RectPtr CreateRect() {}

EqualsTest;

}  // namespace

TEST_F() {
  RectPtr r1;
  RectPtr r2;
  EXPECT_TRUE();
  EXPECT_TRUE();

  r1 = CreateRect();
  EXPECT_FALSE();
  EXPECT_FALSE();
}

TEST_F() {
  RectPtr r1(CreateRect());
  RectPtr r2(r1.Clone());
  EXPECT_TRUE();
  r2->y = 1;
  EXPECT_FALSE();
  r2.reset();
  EXPECT_FALSE();
}

TEST_F() {
  RectPairPtr p1(RectPair::New(CreateRect(), CreateRect()));
  RectPairPtr p2(p1.Clone());
  EXPECT_TRUE();
  p2->second->width = 0;
  EXPECT_FALSE();
  p2->second.reset();
  EXPECT_FALSE();
}

TEST_F() {
  std::vector<RectPtr> rects;
  rects.push_back(CreateRect());
  NamedRegionPtr n1(NamedRegion::New(std::string("n1"), std::move(rects)));
  NamedRegionPtr n2(n1.Clone());
  EXPECT_TRUE();

  n2->rects = std::nullopt;
  EXPECT_FALSE();
  n2->rects.emplace();
  EXPECT_FALSE();

  n2->rects->push_back(CreateRect());
  n2->rects->push_back(CreateRect());
  EXPECT_FALSE();

  n2->rects->resize(1);
  (*n2->rects)[0]->width = 0;
  EXPECT_FALSE();

  (*n2->rects)[0] = CreateRect();
  EXPECT_TRUE();
}

}  // test
}  // mojo