Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,21 @@ def _prepend_path(directory: Path) -> None:
parts = current.split(sep) if current else []
# Case-insensitive comparison on Windows; exact match elsewhere.
norm = (lambda s: s.lower()) if os.name == "nt" else (lambda s: s)
if any(norm(x) == norm(p) for x in parts if x):
return
os.environ["PATH"] = p + (sep + current if current else "")
already_on_path = any(norm(x) == norm(p) for x in parts if x)
# GitHub Actions: persist the new entry across subsequent steps so that
# tools installed by `make.py setup` are visible to later `run:` commands.
# This must run even when `directory` is already on the in-process PATH:
# being present on *this* process's PATH (e.g. because an earlier setup
# call already prepended it) says nothing about whether subsequent GitHub
# Actions steps — which are fresh processes — will see it. So append to
# GITHUB_PATH before the early-return that skips the in-process update.
gha_path = os.environ.get("GITHUB_PATH")
if gha_path:
with open(gha_path, "a", encoding="utf-8") as fh:
fh.write(p + "\n")
if already_on_path:
return
os.environ["PATH"] = p + (sep + current if current else "")


def cmd_setup(args, ctx: "Context") -> int:
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hero_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: hero_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hero_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: hero_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hub.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hub.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hub_shard0.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/hub_shard1.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/index_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: index_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/index_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: index_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/item_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: item_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/item_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: item_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/load.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/load.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/logger.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/logger.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/patch_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: patch_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/patch_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: patch_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/scheduler.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/scheduler.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/test_conf.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: test_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/test_conf.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off
// source: test_conf.proto
Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/util.pc.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
2 changes: 1 addition & 1 deletion test/cpp-tableau-loader/src/protoconf/util.pc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-cpp-tableau-loader. DO NOT EDIT.
// versions:
// - protoc-gen-cpp-tableau-loader v0.11.0
// - protoc-gen-cpp-tableau-loader v0.12.0
// - protoc (unknown)
// clang-format off

Expand Down
100 changes: 100 additions & 0 deletions test/cpp-tableau-loader/tests/get_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Get block: point-lookup getters (map getters). Mirrors the same scenarios in:
// - Go: test/go-tableau-loader/get_test.go
// - C#: test/csharp-tableau-loader/tests/GetTests.cs
// - TS: test/ts-tableau-loader/tests/get.test.ts

#include <gtest/gtest.h>

#include "protoconf/hero_conf.pc.h"
#include "protoconf/index_conf.pc.h"
#include "protoconf/item_conf.pc.h"
#include "tests/hub_fixture.h"

namespace {

// ---- ItemConf: 1st-level int-keyed map getter ----

TEST_F(HubFixture, ItemConf_Get) {
auto item = Hub::Instance().Get<protoconf::ItemConfMgr>();
ASSERT_NE(item, nullptr);

// found
auto apple = item->Get(1);
ASSERT_NE(apple, nullptr);
EXPECT_EQ(apple->name(), "apple");
auto coin = item->Get(0);
ASSERT_NE(coin, nullptr);
EXPECT_EQ(coin->name(), "coin1");

// not found
EXPECT_EQ(item->Get(12345), nullptr);
}

// ---- ActivityConf: nested map getters with a 64-bit outer key ----

TEST_F(HubFixture, ActivityConf_Get) {
auto conf = Hub::Instance().Get<tableau::ActivityConf>();
ASSERT_NE(conf, nullptr);

auto activity = conf->Get(100001);
ASSERT_NE(activity, nullptr);
EXPECT_EQ(activity->activity_name(), "活动1");

auto chapter = conf->Get(100001, 1);
ASSERT_NE(chapter, nullptr);
EXPECT_EQ(chapter->chapter_name(), "签到活动章1");

auto section = conf->Get(100001, 1, 2);
ASSERT_NE(section, nullptr);
EXPECT_EQ(section->section_id(), 2u);

// sectionRankMap["2001"] === 2
auto rank = conf->Get(100001, 1, 2, 2001);
ASSERT_NE(rank, nullptr);
EXPECT_EQ(*rank, 2);
}

TEST_F(HubFixture, ActivityConf_Get3_NotFound) {
auto conf = Hub::Instance().Get<tableau::ActivityConf>();
ASSERT_NE(conf, nullptr);
EXPECT_EQ(conf->Get(100001, 1, 999), nullptr);
}

// ---- ThemeConf: string-keyed map getter ----

TEST_F(HubFixture, ThemeConf_Get) {
auto theme = Hub::Instance().Get<tableau::ThemeConf>();
ASSERT_NE(theme, nullptr);
EXPECT_GT(theme->Data().theme_map_size(), 0);
}

// ---- HeroBaseConf ----

TEST_F(HubFixture, HeroBaseConf_Get) {
auto conf = Hub::Instance().Get<tableau::HeroBaseConf>();
ASSERT_NE(conf, nullptr);
EXPECT_GT(conf->Data().hero_map_size(), 0);
}

// ---- FruitConf: leveled point getters ----

TEST_F(HubFixture, FruitConf_Get) {
auto fruit = Hub::Instance().Get<tableau::FruitConf>();
ASSERT_NE(fruit, nullptr);

// Get1: found / not found
ASSERT_NE(fruit->Get(kFruitTypeApple), nullptr);
EXPECT_EQ(fruit->Get(999), nullptr);

// Get2: APPLE -> item 1001, price 10
auto apple_item = fruit->Get(kFruitTypeApple, 1001);
ASSERT_NE(apple_item, nullptr);
EXPECT_EQ(apple_item->id(), 1001);
EXPECT_EQ(apple_item->price(), 10);

// not found: wrong item id / wrong fruitType
EXPECT_EQ(fruit->Get(kFruitTypeApple, 9999), nullptr);
EXPECT_EQ(fruit->Get(999, 1001), nullptr);
}

} // namespace
41 changes: 41 additions & 0 deletions test/cpp-tableau-loader/tests/hub_fixture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Shared test fixture and constants for the C++ tableau loader tests.
//
// The unit tests are split into four blocks, one file each, mirroring the
// Go / C# / TS test layout:
// - load_test.cpp (Load, CustomConf, Bin, Patch)
// - get_test.cpp (point-lookup getters)
// - ordered_map_test.cpp (GetOrderedMap traversal)
// - index_test.cpp (Find* index finders)
#pragma once

#include <gtest/gtest.h>

#include <memory>

#include "hub/hub.h"
#include "protoconf/hub.pc.h"
#include "protoconf/test_conf.pc.h"
#include "tests/test_paths.h"

// fruitType values match FruitConf.json (== protoconf::FruitType enum values).
constexpr int kFruitTypeApple = protoconf::FRUIT_TYPE_APPLE;
constexpr int kFruitTypeOrange = protoconf::FRUIT_TYPE_ORANGE;
constexpr int kFruitTypeBanana = protoconf::FRUIT_TYPE_BANANA;

// HubFixture loads the whole hub once per test, so test order doesn't matter
// (Hub::Instance() is a process-wide singleton). Mirrors the shared prepareHub
// helper in Go and the HubFixture in C#.
class HubFixture : public ::testing::Test {
protected:
void SetUp() override {
Hub::Instance().InitOnce();
auto options = std::make_shared<tableau::load::Options>();
options->ignore_unknown_fields = true;
auto mopts = std::make_shared<tableau::load::MessagerOptions>();
mopts->path = (test::TestPaths::Conf() / "ItemConf.json").string();
options->messager_options["ItemConf"] = mopts;

bool ok = Hub::Instance().Load(test::TestPaths::Conf().string() + "/", tableau::Format::kJSON, options);
ASSERT_TRUE(ok) << "hub load failed: " << tableau::GetErrMsg();
}
};
Loading
Loading