Skip to content

Commit

Permalink
fix: add missing out capabilities count assignment
Browse files Browse the repository at this point in the history
* also added more assoc tests
  • Loading branch information
zaucy committed Jun 19, 2024
1 parent 79a94ec commit f135bc7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parse-resolver-runtime/assoc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ void ecsact_meta_system_assoc_capabilities(
return;
}

if(out_capabilities_count) {
*out_capabilities_count = static_cast<int32_t>(info->caps.size());
}

for(int32_t i = 0; max_capabilities_count > i; ++i) {
if(i >= info->caps.size()) {
break;
Expand Down
16 changes: 16 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
76 changes: 76 additions & 0 deletions test/assoc_capabilities.cc
Original file line number Diff line number Diff line change
@@ -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<ecsact_component_like_id>(*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<ecsact_component_like_id>(*tag_comp)) {
ASSERT_EQ(caps, ECSACT_SYS_CAP_INCLUDE);
} else if(comp_id ==
ecsact_id_cast<ecsact_component_like_id>(*example_comp)) {
ASSERT_EQ(caps, ECSACT_SYS_CAP_REMOVES);
} else {
ASSERT_TRUE(false) << "unknown comp id";
}
}
}
19 changes: 19 additions & 0 deletions test/assoc_capabilities.ecsact
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit f135bc7

Please sign in to comment.