File: YGConfigTest.cpp

package info (click to toggle)
yoga 3.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 984 kB
  • sloc: cpp: 12,985; python: 260; sh: 32; makefile: 6
file content (69 lines) | stat: -rw-r--r-- 1,630 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/config/Config.h>
#include <yoga/node/Node.h>

#include <functional>
#include <memory>

using namespace facebook;

struct ConfigCloningTest : public ::testing::Test {
  std::unique_ptr<yoga::Config, std::function<void(yoga::Config*)>> config;
  void SetUp() override;
  void TearDown() override;

  static yoga::Node clonedNode;
  static YGNodeRef cloneNode(
      YGNodeConstRef /*unused*/,
      YGNodeConstRef /*unused*/,
      size_t /*unused*/) {
    return &clonedNode;
  }
  static YGNodeRef doNotClone(
      YGNodeConstRef /*unused*/,
      YGNodeConstRef /*unused*/,
      size_t /*unused*/) {
    return nullptr;
  }
};

TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
  config->setCloneNodeCallback(cloneNode);

  yoga::Node node{};
  yoga::Node owner{};
  auto clone = config->cloneNode(&node, &owner, 0);

  ASSERT_EQ(clone, &clonedNode);
}

TEST_F(
    ConfigCloningTest,
    falls_back_to_regular_cloning_if_callback_returns_null) {
  config->setCloneNodeCallback(doNotClone);

  yoga::Node node{};
  yoga::Node owner{};
  auto clone = config->cloneNode(&node, &owner, 0);

  ASSERT_NE(clone, nullptr);
  YGNodeFree(clone);
}

void ConfigCloningTest::SetUp() {
  config = {static_cast<yoga::Config*>(YGConfigNew()), YGConfigFree};
}

void ConfigCloningTest::TearDown() {
  config.reset();
}

yoga::Node ConfigCloningTest::clonedNode = {};