From e81cead86ba7ec54f8ab9ccf2effc444859475eb Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Wed, 19 Jun 2024 16:50:47 -0700 Subject: [PATCH] fix: add missing out capabilities count assignment (#229) --- MODULE.bazel | 2 +- parse-resolver-runtime/assoc.cc | 4 ++ test/BUILD.bazel | 16 +++++++ test/MODULE.bazel | 2 +- test/assoc_capabilities.cc | 76 +++++++++++++++++++++++++++++++++ test/assoc_capabilities.ecsact | 19 +++++++++ 6 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 test/assoc_capabilities.cc create mode 100644 test/assoc_capabilities.ecsact diff --git a/MODULE.bazel b/MODULE.bazel index c29c458..980538a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,7 +7,7 @@ module( bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "magic_enum", version = "0.9.3") -bazel_dep(name = "ecsact_runtime", version = "0.6.5") +bazel_dep(name = "ecsact_runtime", version = "0.6.6") bazel_dep(name = "ecsact_parse", version = "0.5.1") bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True) diff --git a/parse-resolver-runtime/assoc.cc b/parse-resolver-runtime/assoc.cc index 8486b58..b1ed9f0 100644 --- a/parse-resolver-runtime/assoc.cc +++ b/parse-resolver-runtime/assoc.cc @@ -317,6 +317,10 @@ void ecsact_meta_system_assoc_capabilities( return; } + if(out_capabilities_count) { + *out_capabilities_count = static_cast(info->caps.size()); + } + for(int32_t i = 0; max_capabilities_count > i; ++i) { if(i >= info->caps.size()) { break; diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 5c1dda9..e0575fc 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -59,6 +59,22 @@ cc_test( ], ) +cc_test( + name = "assoc_capabilities", + srcs = ["assoc_capabilities.cc"], + copts = copts, + data = [ + "assoc_capabilities.ecsact", + ], + deps = [ + ":test_lib", + "@ecsact_interpret", + "@bazel_sundry//bazel_sundry:runfiles", + "@googletest//:gtest", + "@googletest//:gtest_main", + ], +) + cc_test( name = "field_indexing", srcs = ["field_indexing.cc"], diff --git a/test/MODULE.bazel b/test/MODULE.bazel index 326782c..828f758 100644 --- a/test/MODULE.bazel +++ b/test/MODULE.bazel @@ -4,7 +4,7 @@ bazel_dep(name = "rules_cc", version = "0.0.9") bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "googletest", version = "1.14.0") bazel_dep(name = "ecsact_parse", version = "0.5.1") -bazel_dep(name = "ecsact_runtime", version = "0.6.5") +bazel_dep(name = "ecsact_runtime", version = "0.6.6") bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True) bazel_dep(name = "hedron_compile_commands", dev_dependency = True) diff --git a/test/assoc_capabilities.cc b/test/assoc_capabilities.cc new file mode 100644 index 0000000..731ae32 --- /dev/null +++ b/test/assoc_capabilities.cc @@ -0,0 +1,76 @@ + +#include "gtest/gtest.h" + +#include "ecsact/runtime/meta.hh" +#include "ecsact/runtime/dynamic.h" +#include "test_lib.hh" + +using ecsact::meta::get_field_type; + +class AssocCapabilities : public testing::Test { +public: + ecsact_package_id pkg_id; + +protected: + void SetUp() override { + auto errs = ecsact_interpret_test_files({"assoc_capabilities.ecsact"}); + ASSERT_EQ(errs.size(), 0) // + << "Expected no errors. Instead got: " << errs[0].error_message << "\n"; + pkg_id = ecsact::meta::get_package_ids().at(0); + } + + void TearDown() override { + // ecsact_destroy_package(pkg_id); + } +}; + +TEST_F(AssocCapabilities, GeneralReads) { + auto example_comp = get_component_by_name(pkg_id, "Example"); + ASSERT_TRUE(example_comp); + + auto comp = get_component_by_name(pkg_id, "AssocComp"); + ASSERT_TRUE(comp); + + auto sys = get_system_by_name(pkg_id, "ReadwriteSystem"); + auto assoc_ids = ecsact::meta::system_assoc_ids(*sys); + ASSERT_EQ(assoc_ids.size(), 1); + + auto caps = ecsact::meta::system_assoc_capabilities(*sys, assoc_ids.at(0)); + ASSERT_EQ(caps.size(), 1); + + ASSERT_EQ( + caps.at(0).first, + ecsact_id_cast(*example_comp) + ); + ASSERT_EQ(caps.at(0).second, ECSACT_SYS_CAP_READWRITE); +} + +TEST_F(AssocCapabilities, RemovesExists) { + auto example_comp = get_component_by_name(pkg_id, "Example"); + ASSERT_TRUE(example_comp); + + auto tag_comp = get_component_by_name(pkg_id, "MyTag"); + ASSERT_TRUE(tag_comp); + + auto comp = get_component_by_name(pkg_id, "AssocComp"); + ASSERT_TRUE(comp); + + auto sys = get_system_by_name(pkg_id, "RemovesSystem"); + auto assoc_ids = ecsact::meta::system_assoc_ids(*sys); + ASSERT_EQ(assoc_ids.size(), 1); + + auto assoc_caps = + ecsact::meta::system_assoc_capabilities(*sys, assoc_ids.at(0)); + + // order isn't guaranteed + for(auto&& [comp_id, caps] : assoc_caps) { + if(comp_id == ecsact_id_cast(*tag_comp)) { + ASSERT_EQ(caps, ECSACT_SYS_CAP_INCLUDE); + } else if(comp_id == + ecsact_id_cast(*example_comp)) { + ASSERT_EQ(caps, ECSACT_SYS_CAP_REMOVES); + } else { + ASSERT_TRUE(false) << "unknown comp id"; + } + } +} diff --git a/test/assoc_capabilities.ecsact b/test/assoc_capabilities.ecsact new file mode 100644 index 0000000..ce8438f --- /dev/null +++ b/test/assoc_capabilities.ecsact @@ -0,0 +1,19 @@ +package eval.assoc_capabilities; + +component MyTag; +component Example { i32 num; } +component AssocComp { Example.num hello; } + +system ReadwriteSystem { + readwrite AssocComp with hello { + readwrite Example; + } +} + +system RemovesSystem { + readwrite AssocComp with hello { + include MyTag; + removes Example; + } +} +