diff --git a/fx92/drawing.py b/fx92/drawing.py index 55ef608..e2d79a2 100644 --- a/fx92/drawing.py +++ b/fx92/drawing.py @@ -33,6 +33,8 @@ class Window: # Create the window mode = SDL_WINDOW_HIDDEN if self.quiet else SDL_WINDOW_SHOWN + # TODO: If the window is hidden, nothing is rendered + mode = SDL_WINDOW_SHOWN self.w = SDL_CreateWindow("fx-92 Scientifique Collège+".encode(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, self.width*self.scale, self.height*self.scale, mode) diff --git a/tests.py b/tests.py new file mode 100755 index 0000000..c5ce8aa --- /dev/null +++ b/tests.py @@ -0,0 +1,72 @@ +#! /usr/bin/python3 + +import sys +import glob +import os.path +import subprocess + +from PIL import Image +from PIL import ImageChops + +def imgequal(ref, out): + ref = Image.open(ref) + out = Image.open(out) + + diff = ImageChops.difference(ref, out) + return diff.getbbox() is None + +def runtest(program, refout=None, refimg=None): + st = subprocess.run("./fx92.py --quiet --save=/tmp/fx92-test.bmp".split() + + [program], stdout=subprocess.PIPE) + + if st.returncode != 0: + print(" -> Execution FAILED!") + return 0 + + print(" Execution completed.") + success = True + + if refout is not None: + with open(refout, "r") as fp: + refout = fp.read() + if st.stdout == refout: + print(" Output is correct.") + else: + print(" -> Output is incorrect!") + success = False + + if refimg is not None: + if imgequal(refimg, "/tmp/fx92-test.bmp"): + print(" Image is correct.") + else: + print(" -> Image is incorrect!") + success = False + + return success + +def main(): + paths = glob.glob("tests/*.txt") + print("Found {} tests.".format(len(paths))) + + total = 0 + passed = 0 + + for t in paths: + print("\n{}:".format(t)) + + refout = t[:-4] + ".out" + refout = refout if os.path.isfile(refout) else None + + refimg = t[:-4] + ".png" + refimg = refimg if os.path.isfile(refimg) else None + + passed += runtest(t, refout=refout, refimg=refimg) + total += 1 + + if passed < total: + print("\nWarning, some tests failed!") + return 1 + return 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/corners.png b/tests/corners.png new file mode 100644 index 0000000..8fd17ce Binary files /dev/null and b/tests/corners.png differ diff --git a/tests/corners.txt b/tests/corners.txt new file mode 100644 index 0000000..ddbbc7c --- /dev/null +++ b/tests/corners.txt @@ -0,0 +1,4 @@ +goto -90, 23; pendown; goto x-5, y; goto x, y-5; penup +goto -90, -23; pendown; goto x-5, y; goto x, y+5; penup +goto 91, 23; pendown; goto x+5, y; goto x, y-5; penup +goto 91, -23; pendown; goto x+5, y; goto x, y+5; penup