Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Feb 16, 2021
1 parent accf543 commit ff6885e
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 18 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ build
include/
api/math/
doc/
test
version/*
*.exe
.idea/workspace.xml
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ add_library(${MOD_NAME}
mod/eval/Eval.cpp
mod/dirtyLitematica/SelectRegion.cpp
mod/dirtyLitematica/SimpleLitematica.cpp
)
mod/test/TrapdoorTest.cpp)

target_include_directories(
${MOD_NAME}
Expand Down
12 changes: 6 additions & 6 deletions lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"command.tick.slow.desc": "放慢世界运行[num]倍数",
"command.tick.slow.error": "放慢倍数必须在 [2-64] 之间",
"command.tick.acc.desc": "加速世界数学[num]倍数(理论值)",
"command.tick.acc.error": "加放慢倍数必须在 [2-64] 之间",
"command.tick.acc.error": "加速倍数必须在 [2-10] 之间",
"command.tick.r.desc": "重置世界运行为正常状态",
"command.tick.fw.desc": "世界运行步进[num]gt",
"command.tick.q.desc": "查询tick状态",
Expand Down Expand Up @@ -69,11 +69,11 @@
"command.td?.desc": "打印帮助",
"command.self.desc": "玩家个人功能开关",
"command.self.chunk.desc": "开关区块显示",
"command.self.chunk.set": "设置区块显示为",
"command.self.chunk.set": "设置区块显示为%d",
"command.self.me.desc": "开关测量",
"command.self.me.set": "设置测量为",
"command.self.me.set": "设置测量为%d",
"command.self.rs.desc": "开关红石信号源显示",
"command.self.rs.set": "设置红石信号源为",
"command.self.rs.set": "设置红石信号源为%d",
"command.here.desc": "广播自己的坐标",
"command.l.desc": "显示所有在线玩家的坐标",
"command.os.desc": "显示服务器进程的CPU和内存占用",
Expand Down Expand Up @@ -108,8 +108,8 @@
"prof.start": "开始分析...",
"prof.warning" :"世界不在正常状态,性能分析可能不准确",

"village.error.notDweller": "该实体不是居民或不属于任何村庄",
"village.error.notVillage": "附近没有村庄",
"village.error.noDweller": "该实体不是居民或不属于任何村庄",
"village.error.noVillage": "附近没有村庄",
"village.info.allVillages": "下面是所有正在加载的村庄",
"backup.error.dictNotExist": "备份目录不存在",
"backup.info.start": "备份开始",
Expand Down
6 changes: 2 additions & 4 deletions mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
#include "trapdoor.h"
#include "block/BlockLegacy.h"
#include "VanillaBlockType.h"
#include "test/TrapdoorTest.h"

namespace mod {
bool test(const trapdoor::BlockLegacy &l) {
printf("qaq\n");
return true;
}

void TrapdoorMod::heavyTick() {
this->villageHelper.tick();
Expand Down Expand Up @@ -59,6 +56,7 @@ namespace mod {
BDSMod::registerCommands();
tick::registerTickCommand(this->commandManager);
tick::registerProfileCommand(this->commandManager);
mod::test::registerTestCommand(this->commandManager);
mod::registerBackupCommand(this->commandManager);
this->hsaManager.registerCommand(this->commandManager);
this->simpleBuilder.registerDrawCommand(this->commandManager);
Expand Down
10 changes: 5 additions & 5 deletions mod/function/BlockRotationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ namespace mod {
blockSource->setBlock(&pos, newBlock);
} else if (name.find("torch") != std::string::npos) {
auto newState = (variant + 1) % 5;
blockSource->setBlock(&pos, air);
auto newBlock = block->getLegacy()->tryGetStateBlock(newState);
blockSource->setBlock(&pos, air);
blockSource->setBlock(&pos, newBlock);
// blockSource->updateNeighbors(&pos);
} else if (name.find("cake") != std::string::npos) {
auto newState = (variant + 1) % 7;
auto newBlock = block->getLegacy()->tryGetStateBlock(newState);
Expand All @@ -68,17 +67,18 @@ namespace mod {
name.find("barrel") != std::string::npos ||
name.find("glazed_terracotta") != std::string::npos) {
auto newState = (variant % 8 + 1) % 6 + (variant / 8) * 8;
blockSource->setBlock(&pos, air);

auto newBlock = block->getLegacy()->tryGetStateBlock(newState);
blockSource->setBlock(&pos, air);
//blockSource->setBlock(&pos, blockSource->getBlock(pos + trapdoor::BlockPos(0, 1, 0)));
blockSource->setBlock(&pos, newBlock);
// blockSource->updateNeighbors(&pos);

} else if (name.find("rail") != std::string::npos) {
auto newState = (variant + 1) % 10;
auto newBlock = block->getLegacy()->tryGetStateBlock(newState);
blockSource->setBlock(&pos, air);
blockSource->setBlock(&pos, newBlock);
// blockSource->updateNeighbors(&pos);
// blockSource->updateNeighbors(&pos);
} else if ((name.find("log") != std::string::npos &&
name.find("stripped") != std::string::npos) ||
name.find("basalt") != std::string::npos ||
Expand Down
242 changes: 242 additions & 0 deletions mod/test/TrapdoorTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
//
// Created by xhy on 2021/2/16.
//

#include "TrapdoorTest.h"

#define TRAPDOOR_TEST
#define COMMAND_TEST(TEST_NAME) void commandTest_##TEST_NAME (trapdoor::CommandManager &manager, trapdoor::Actor *player)
#define TEST(TEST_NAME) commandTest_##TEST_NAME (manager,player);
#define RUN_CMD(cmd) { trapdoor::info(player,"TEST: [" cmd "]\n");manager.parse(player, cmd);}
namespace mod::test {
namespace {
std::map<std::string, bool> &getNeedMoreTestItems() {
static std::map<std::string, bool> testItems;
return testItems;
}

void printTestStatus(trapdoor::Actor *actor) {
const auto &items = getNeedMoreTestItems();
std::string stringBuilder;
for (const auto &i:items) {
if (i.second) {
stringBuilder += trapdoor::format("- %s " C_GREEN(%d) "\n", i.first.c_str(), i.second);
} else {
stringBuilder += trapdoor::format("- %s " C_RED(%d) "\n", i.first.c_str(), i.second);
}
}
trapdoor::info(actor, stringBuilder);
}

void markPassed(const std::string &item, trapdoor::Actor *actor) {
auto iter = getNeedMoreTestItems().find(item);
if (iter != getNeedMoreTestItems().end()) {
getNeedMoreTestItems()[item] = true;
trapdoor::info(actor, "mark %s passed", item.c_str());
} else {
trapdoor::warning(actor, "no items");
}
}

void markUnPassed(const std::string &item, trapdoor::Actor *actor) {
auto iter = getNeedMoreTestItems().find(item);
if (iter != getNeedMoreTestItems().end()) {
getNeedMoreTestItems()[item] = false;
trapdoor::info(actor, "mark %s unPassed", item.c_str());
} else {
trapdoor::warning(actor, "no items");
}
}

void addManualTestItem(const std::string &s) {
getNeedMoreTestItems()[s] = false;
}

}


COMMAND_TEST(apicfg) {
RUN_CMD("/apicfg ?")
RUN_CMD("/apicfg pm 1")
RUN_CMD("/apicfg pm 0")
RUN_CMD("/apicfg pvd 1")
RUN_CMD("/apicfg pvd 12")
RUN_CMD("/apicfg pvd -12")
}

COMMAND_TEST(td) {
RUN_CMD("/td?")
}

COMMAND_TEST(func) {
RUN_CMD("/func ?")
RUN_CMD("/func hopper 1")
RUN_CMD("/func hopper 0")
RUN_CMD("/func spawn true")
RUN_CMD("/func spawn false")
RUN_CMD("/func rotate 1")
RUN_CMD("/func rotate 0")
RUN_CMD("/func ncud 1")
RUN_CMD("/func ncud 0")
RUN_CMD("/func expl true")
RUN_CMD("/func expl false")
}

COMMAND_TEST(lang) {
RUN_CMD("/lang list")
RUN_CMD("/lang set zh_cn")
}

COMMAND_TEST(tick) {
RUN_CMD("/tick ?")
RUN_CMD("/tick fz")
RUN_CMD("/tick fw 20")
RUN_CMD("/tick fw 601")
RUN_CMD("/tick r")
RUN_CMD("/tick acc 30")
RUN_CMD("/tick acc -1")
RUN_CMD("/tick acc 3")
RUN_CMD("/tick r")
RUN_CMD("/tick slow 67")
RUN_CMD("/tick slow 1")
RUN_CMD("/tick slow 4")
RUN_CMD("/tick r")
}

COMMAND_TEST(counter) {
RUN_CMD("/counter p 15")
RUN_CMD("/counter p -1")
RUN_CMD("/counter p 16")
RUN_CMD("/counter p 7")
RUN_CMD("/counter r 7")
}

COMMAND_TEST(os) {
RUN_CMD("/os")
}

COMMAND_TEST(self) {
RUN_CMD("/self")
RUN_CMD("/self rs 1")
RUN_CMD("/self rs 0")
RUN_CMD("/self me true")
RUN_CMD("/self me false")
RUN_CMD("/self chunk true")
RUN_CMD("/self chunk 0");
}

COMMAND_TEST(gameMode) {
RUN_CMD("/o")
RUN_CMD("/s")
RUN_CMD("/c")
}

COMMAND_TEST(list) {
RUN_CMD("/l")
RUN_CMD("/here")
}

COMMAND_TEST(village) {
RUN_CMD("/village list")
RUN_CMD("/village b true")
RUN_CMD("/village b false")
RUN_CMD("/village s 1")
RUN_CMD("/village s 0")
RUN_CMD("/village p true")
RUN_CMD("/village p false")
RUN_CMD("/village v true")
RUN_CMD("/village v false")
RUN_CMD("/village n")
}

COMMAND_TEST(hsa) {
RUN_CMD("/hsa show 1")
RUN_CMD("/hsa show false")
RUN_CMD("/hsa clear")
RUN_CMD("/hsa draw")
RUN_CMD("/hsa list")
}

COMMAND_TEST(draw) {
RUN_CMD("/func draw false")
RUN_CMD("/func draw 1")
RUN_CMD("/draw sp 2")
RUN_CMD("/draw sp -3")
RUN_CMD("/draw ci 5")
RUN_CMD("/draw ci -10")
}

COMMAND_TEST(cl) {
RUN_CMD("/cl 12+sin(0.5+2*pi)-log2(12)")
RUN_CMD("/cl 1/0")
RUN_CMD("/cl log(-1)")
}

COMMAND_TEST(mspt) {
RUN_CMD("/mspt")
}

COMMAND_TEST(slime) {
RUN_CMD("/slime show 1")
RUN_CMD("/slime show 0")
RUN_CMD("/slime c")
RUN_CMD("/slime r -1")
RUN_CMD("/slime r 4")
}

void testAll(trapdoor::Actor *player, CommandManager &manager) {
trapdoor::info(player, "begin Test");
TEST(apicfg)
TEST(gameMode)
TEST(func)
TEST(tick)
TEST(lang)
TEST(list)
TEST(self)
TEST(os)
TEST(counter)
TEST(draw)
TEST(hsa)
TEST(village)
TEST(cl)
// TEST(td)
trapdoor::info(player, "end Test");
}


void addManualTest() {
addManualTestItem("backup");
addManualTestItem("village");
addManualTestItem("prof");
addManualTestItem("spawn");
addManualTestItem("rotate");
addManualTestItem("ncud");
addManualTestItem("chunk");
addManualTestItem("me");
addManualTestItem("rs");
addManualTestItem("counter");
addManualTestItem("draw");
addManualTestItem("slime");
addManualTestItem("hsa");

}

void registerTestCommand(CommandManager &manager) {
#ifdef TRAPDOOR_TEST
addManualTest();
manager.registerCmd("test")
->then(ARG("p", "通过某项测试", STR, {
markPassed(holder->getString(), player);
}))
->then(ARG("u", "通过某项测试", STR, {
markUnPassed(holder->getString(), player);
}))
->then(ARG("l", "列出所有手动测试项", NONE, {
printTestStatus(player);
}))
->execute([&](trapdoor::ArgHolder *holder, trapdoor::Actor *player) {
testAll(player, manager);
});
#endif
}
}
18 changes: 18 additions & 0 deletions mod/test/TrapdoorTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by xhy on 2021/2/16.
//

#ifndef MOD_TRAPDOORTEST_H
#define MOD_TRAPDOORTEST_H

#include "Actor.h"
#include "BDSMod.h"
#include "TrapdoorMod.h"
#include "CommandManager.h"

namespace mod::test {
void registerTestCommand(trapdoor::CommandManager &);
}


#endif //MOD_TRAPDOORTEST_H
2 changes: 1 addition & 1 deletion mod/village/Village.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace mod {
{
this->setShowGolemSpawnArea(
holder->getBool());
info(player, LANG("command.village.spawn.set"),
info(player, LANG("command.village.s.set"),
holder->getBool());
}))
->then(ARG(
Expand Down
7 changes: 7 additions & 0 deletions 更新日志.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.16.4-0.9.4
### 开发
- 增加测试
- 正事移除玩家行为统计
### bug修复
- 修复一堆文字错误

## 1.16.4-0.9.32
### BUG修复
- 修复`func stat`指令无效的的问题
Expand Down

0 comments on commit ff6885e

Please sign in to comment.