Real test coverage dor SAVE_TAMPERING.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 12 Mar 2023 21:37:58 +0000 (17:37 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 12 Mar 2023 21:37:58 +0000 (17:37 -0400)
saveresume.c
tests/Makefile
tests/coverage_dungeon.py
tests/savetamper.chk [new file with mode: 0644]
tests/savetamper.log [new file with mode: 0644]

index afd04d37af00570a385e85b545bdad1fcced9352..c53ee4950ff9942868ec2ad4517497739030a421 100644 (file)
@@ -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;
     }
index fb03fdbe5317ea85335b983f24bdde43ae859f52..e33e684b1c4fcd0d855e5a24de630fb1c054d6ab 100644 (file)
@@ -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"
index 1f27838fbca6fcdd4c1cf10b25fcb4a6333d1f2b..e61523957c390ef7ed23fdd2c71fbb8f18c58bca 100755 (executable)
@@ -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 (file)
index 0000000..88f86f7
--- /dev/null
@@ -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 (file)
index 0000000..e62dfbe
--- /dev/null
@@ -0,0 +1,4 @@
+## Resume from artificial "corrupted" save
+n
+resume
+cheat_savetamper.adv