shithub: puzzles

Download patch

ref: ffe2fa169f9fdc411d00e1c75cf3cdc5f3099727
parent: a2bf0508c7256a62d973446fce841504580e2591
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sun Feb 12 17:57:51 EST 2023

Extend fuzzpuzz to test more code

Now if the input save file loads correctly, fuzzpuzz asks the back-end
to draw the puzzle.  All the drawing operations are no-ops, but this
tests the drawing code in the back-end.

--- a/fuzzpuzz.c
+++ b/fuzzpuzz.c
@@ -39,6 +39,8 @@
     fwrite(buf, 1, len, fp);
 }
 
+static drawing_api drapi = { NULL };
+
 int main(int argc, char **argv)
 {
     const char *err;
@@ -47,6 +49,7 @@
     const game *ourgame = NULL;
     midend *me;
     FILE *in = NULL;
+    int w, h;
 
     if (argc != 1) {
         fprintf(stderr, "usage: %s\n", argv[0]);
@@ -93,7 +96,7 @@
             continue;
         }
 
-        me = midend_new(NULL, ourgame, NULL, NULL);
+        me = midend_new(NULL, ourgame, &drapi, NULL);
 
         rewind(in);
         err = midend_deserialise(me, savefile_read, in);
@@ -103,6 +106,9 @@
             midend_free(me);
             continue;
         }
+        w = h = INT_MAX;
+        midend_size(me, &w, &h, false, 1);
+        midend_redraw(me);
         midend_serialise(me, savefile_write, stdout);
         midend_free(me);
         ret = 0;
--- a/nullfe.c
+++ b/nullfe.c
@@ -13,9 +13,10 @@
 { char *c = snewn(1, char); *c = 0; *randseed = c; *randseedsize = 1; }
 void deactivate_timer(frontend *fe) {}
 void activate_timer(frontend *fe) {}
+struct drawing { char dummy; };
 drawing *drawing_new(const drawing_api *api, midend *me, void *handle)
-{ return NULL; }
-void drawing_free(drawing *dr) {}
+{ return snew(drawing); }
+void drawing_free(drawing *dr) { sfree(dr); }
 void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
                int align, int colour, const char *text) {}
 void draw_rect(drawing *dr, int x, int y, int w, int h, int colour) {}
@@ -33,8 +34,9 @@
 void start_draw(drawing *dr) {}
 void draw_update(drawing *dr, int x, int y, int w, int h) {}
 void end_draw(drawing *dr) {}
-blitter *blitter_new(drawing *dr, int w, int h) {return NULL;}
-void blitter_free(drawing *dr, blitter *bl) {}
+struct blitter { char dummy; };
+blitter *blitter_new(drawing *dr, int w, int h) { return snew(blitter); }
+void blitter_free(drawing *dr, blitter *bl) { sfree(bl); }
 void blitter_save(drawing *dr, blitter *bl, int x, int y) {}
 void blitter_load(drawing *dr, blitter *bl, int x, int y) {}
 int print_mono_colour(drawing *dr, int grey) { return 0; }