From 5929a68b88ee9a244f5b12d08ead6a6692deb32d Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 12 Mar 2023 17:37:58 -0400 Subject: [PATCH] Real test coverage dor SAVE_TAMPERING. --- saveresume.c | 4 ++-- tests/Makefile | 2 ++ tests/coverage_dungeon.py | 2 +- tests/savetamper.chk | 17 +++++++++++++++++ tests/savetamper.log | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/savetamper.chk create mode 100644 tests/savetamper.log diff --git a/saveresume.c b/saveresume.c index afd04d3..c53ee49 100644 --- a/saveresume.c +++ b/saveresume.c @@ -161,8 +161,8 @@ int restore(FILE* fp) if (save.version != VRSION) { rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), VRSION / 10, MOD(VRSION, 10)); } else if (!is_valid(save.game)) { - rspeak(SAVE_TAMPERING); // LCOV_EXCL_LINE - exit(EXIT_SUCCESS); // LCOV_EXCL_LINE + rspeak(SAVE_TAMPERING); + exit(EXIT_SUCCESS); } else { game = save.game; } diff --git a/tests/Makefile b/tests/Makefile index fb03fdb..e33e684 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -52,6 +52,8 @@ savegames: @$(PARDIR)/cheat -d -900 -o cheat_numdie.adv > /tmp/cheat_numdie @$(ECHO) "cheat: Generate save file with -1000 deaths" @$(PARDIR)/cheat -d -1000 -o cheat_numdie1000.adv > /tmp/cheat_numdie1000 + @$(ECHO) "cheat: Generate tamper-detection test" + @$(PARDIR)/cheat -d 2000 -o cheat_savetamper.adv > /tmp/cheat_savetamper @$(ECHO) "cheat: Generate save file with version -1337" @$(PARDIR)/cheat -v -1337 -o resume_badversion.adv > /tmp/cheat_badversion @$(ECHO) "cheat: Generate save file 1000 saves" diff --git a/tests/coverage_dungeon.py b/tests/coverage_dungeon.py index 1f27838..e615239 100755 --- a/tests/coverage_dungeon.py +++ b/tests/coverage_dungeon.py @@ -25,7 +25,7 @@ YAML_PATH = "../adventure.yaml" HTML_TEMPLATE_PATH = "../templates/coverage_dungeon.html.tpl" DEFAULT_HTML_OUTPUT_PATH = "../coverage/adventure.yaml.html" DANGLING_ACTIONS = ["ACT_VERSION"] -DANGLING_MESSAGES = ["SAVERESUME_DISABLED", "SAVE_TAMPERING"] +DANGLING_MESSAGES = ["SAVERESUME_DISABLED"] STDOUT_REPORT_CATEGORY = " {name:.<19}: {percent:5.1f}% covered ({covered} of {total})\n" diff --git a/tests/savetamper.chk b/tests/savetamper.chk new file mode 100644 index 0000000..88f86f7 --- /dev/null +++ b/tests/savetamper.chk @@ -0,0 +1,17 @@ + +Welcome to Adventure!! Would you like instructions? + +> n + +You are standing at the end of a road before a small brick building. +Around you is a forest. A small stream flows out of the building and +down a gully. + +> resume + +A dark fog creeps in to surround you. From somewhere in the fog you +hear a stern voice. "This Adventure has been tampered with! You have +been dabbling in magic, knowing not the havoc you might cause thereby. +Leave at once, before you do irrevocable harm!" The fog thickens, +until at last you can see nothing at all. Your vision then clears, +and you find yourself back in The Real World. diff --git a/tests/savetamper.log b/tests/savetamper.log new file mode 100644 index 0000000..e62dfbe --- /dev/null +++ b/tests/savetamper.log @@ -0,0 +1,4 @@ +## Resume from artificial "corrupted" save +n +resume +cheat_savetamper.adv -- 2.31.1