-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
282 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ build | |
include/ | ||
api/math/ | ||
doc/ | ||
test | ||
version/* | ||
*.exe | ||
.idea/workspace.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters