2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-05-09 04:14:08 -07:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2019-05-09 04:14:08 -07:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2022-12-28 01:21:52 -08:00
|
|
|
#include "TestUtil.h"
|
2019-05-09 04:14:08 -07:00
|
|
|
|
|
|
|
#include <yoga/YGNode.h>
|
2019-05-09 07:42:34 -07:00
|
|
|
#include <yoga/event/event.h>
|
2019-05-09 04:14:08 -07:00
|
|
|
|
2023-07-12 09:38:40 -07:00
|
|
|
namespace facebook::yoga::test {
|
2019-05-09 04:14:08 -07:00
|
|
|
|
|
|
|
int nodeInstanceCount = 0;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void yogaEventSubscriber(
|
2023-05-11 09:43:36 -07:00
|
|
|
const YGNode& /*node*/,
|
2019-05-09 04:14:08 -07:00
|
|
|
Event::Type eventType,
|
2023-05-11 09:43:36 -07:00
|
|
|
const Event::Data& /*eventData*/) {
|
2019-05-09 04:14:08 -07:00
|
|
|
|
|
|
|
switch (eventType) {
|
|
|
|
case Event::NodeAllocation:
|
|
|
|
nodeInstanceCount++;
|
|
|
|
break;
|
|
|
|
case Event::NodeDeallocation:
|
|
|
|
nodeInstanceCount--;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void TestUtil::startCountingNodes() {
|
|
|
|
nodeInstanceCount = 0;
|
|
|
|
Event::subscribe(yogaEventSubscriber);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestUtil::nodeCount() {
|
|
|
|
return nodeInstanceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestUtil::stopCountingNodes() {
|
|
|
|
Event::reset();
|
2019-05-14 07:42:40 -07:00
|
|
|
auto prev = nodeInstanceCount;
|
|
|
|
nodeInstanceCount = 0;
|
|
|
|
return prev;
|
2019-05-09 04:14:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedEventSubscription::ScopedEventSubscription(
|
|
|
|
std::function<Event::Subscriber>&& s) {
|
|
|
|
Event::subscribe(std::move(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedEventSubscription::~ScopedEventSubscription() {
|
|
|
|
Event::reset();
|
|
|
|
}
|
|
|
|
|
2023-07-12 09:38:40 -07:00
|
|
|
} // namespace facebook::yoga::test
|