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..0dd0e95 100644 --- a/test/MODULE.bazel +++ b/test/MODULE.bazel @@ -14,6 +14,11 @@ git_override( remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git", ) +local_path_override( + module_name = "ecsact_runtime", + path = "../../ecsact_runtime", +) + llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True) llvm.toolchain(llvm_version = "17.0.6") use_repo(llvm, "llvm_toolchain") 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; + } +} +