Skip to content

Commit

Permalink
PathVisitor: add typed test for annotated mapOfI32ToStruct
Browse files Browse the repository at this point in the history
Summary: title

Differential Revision: D65846850

fbshipit-source-id: 5bc37e8e7bbae6332b1aaa0fb6c8282fd444397e
  • Loading branch information
Wei-Cheng Lin authored and facebook-github-bot committed Nov 13, 2024
1 parent a218022 commit f31c272
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions fboss/thrift_cow/visitors/tests/PathVisitorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,34 @@ struct GetVisitedPathsOperator : public BasePathVisitorOperator {
std::set<std::string> visited;
};

TEST(PathVisitorTests, AccessField) {
template <bool EnableHybridStorage>
struct TestParams {
static constexpr auto hybridStorage = EnableHybridStorage;
};

using StorageTestTypes = ::testing::Types<TestParams<false>, TestParams<true>>;

template <typename TestParams>
class PathVisitorTests : public ::testing::Test {
public:
auto initNode(auto val) {
using RootType = std::remove_cvref_t<decltype(val)>;
return std::make_shared<ThriftStructNode<
RootType,
ThriftStructResolver<RootType, TestParams::hybridStorage>,
TestParams::hybridStorage>>(val);
}
bool isHybridStorage() {
return TestParams::hybridStorage;
}
};

TYPED_TEST_SUITE(PathVisitorTests, StorageTestTypes);

TYPED_TEST(PathVisitorTests, AccessField) {
auto structA = createSimpleTestStruct();

auto nodeA = std::make_shared<ThriftStructNode<TestStruct>>(structA);
auto nodeA = this->initNode(structA);
folly::dynamic dyn;
auto processPath = pvlambda([&dyn](auto& node, auto begin, auto end) {
EXPECT_EQ(begin, end);
Expand All @@ -54,7 +78,8 @@ TEST(PathVisitorTests, AccessField) {
std::remove_cvref_t<decltype(node)>>) {
dyn = node.toFollyDynamic();
} else {
FAIL() << "unexpected non-cow visit";
facebook::thrift::to_dynamic(
dyn, node, facebook::thrift::dynamic_format::JSON_1);
}
});
std::vector<std::string> path{"inlineInt"};
Expand Down Expand Up @@ -83,6 +108,13 @@ TEST(PathVisitorTests, AccessField) {
*nodeA, path.begin(), path.end(), PathVisitMode::LEAF, processPath);
EXPECT_EQ(result, ThriftTraverseResult::OK);
EXPECT_TRUE(dyn.asBool());

// mapOfI32ToStruct/20/min
path = {"mapOfI32ToStruct", "20", "min"};
result = RootPathVisitor::visit(
*nodeA, path.begin(), path.end(), PathVisitMode::LEAF, processPath);
EXPECT_EQ(result, ThriftTraverseResult::OK);
EXPECT_EQ(400, dyn.asInt());
}

TEST(PathVisitorTests, HybridMapPrimitiveAccess) {
Expand Down Expand Up @@ -375,30 +407,6 @@ TEST(PathVisitorTests, AccessOptional) {
EXPECT_TRUE(got.empty());
}

template <bool EnableHybridStorage>
struct TestParams {
static constexpr auto hybridStorage = EnableHybridStorage;
};

using StorageTestTypes = ::testing::Types<TestParams<false>, TestParams<true>>;

template <typename TestParams>
class PathVisitorTests : public ::testing::Test {
public:
auto initNode(auto val) {
using RootType = std::remove_cvref_t<decltype(val)>;
return std::make_shared<ThriftStructNode<
RootType,
ThriftStructResolver<RootType, TestParams::hybridStorage>,
TestParams::hybridStorage>>(val);
}
bool isHybridStorage() {
return TestParams::hybridStorage;
}
};

TYPED_TEST_SUITE(PathVisitorTests, StorageTestTypes);

TYPED_TEST(PathVisitorTests, VisitWithOperators) {
auto structA = createSimpleTestStruct();
structA.setOfI32() = {1};
Expand Down

0 comments on commit f31c272

Please sign in to comment.