MODULE test_demos ; (* m2-GTK4 test - the m2 gtk-demo catalogue and registry (demos/). Checks that the full catalogue is present and that ported demos can be built and torn down. Requires a display. *) FROM GtkApplication IMPORT gtk_application_new; FROM Gio IMPORT g_application_run, g_application_quit; FROM GtkDemo IMPORT Count, NameOf, IsPorted, BuildByName; FROM DemoCatalog IMPORT DemoCatalogCount, DemoCatalogGet; FROM GtkUtils IMPORT Connect; FROM SYSTEM IMPORT ADDRESS, ADR; FROM libc IMPORT printf; CONST AppId = "org.example.m2gtk4.TestDemos"; VAR app: ADDRESS; failures: INTEGER; PROCEDURE StrEqual (a, b: ARRAY OF CHAR) : BOOLEAN; VAR i: CARDINAL; BEGIN i := 0; WHILE (a[i] # 0C) AND (b[i] # 0C) DO IF a[i] # b[i] THEN RETURN FALSE END; INC(i) END; RETURN a[i] = b[i] END StrEqual; PROCEDURE Check (cond: BOOLEAN; msg: ARRAY OF CHAR); BEGIN IF cond THEN printf(" ok - %s\n", msg) ELSE printf(" NOT OK - %s\n", msg); INC(failures) END END Check; (* build a demo once (creates + shows its window), then toggle it off. *) PROCEDURE BuildAndClose (name: ARRAY OF CHAR); VAR w: ADDRESS; BEGIN w := BuildByName(name, NIL); Check(w # NIL, name); IF w # NIL THEN w := BuildByName(name, NIL) END END BuildAndClose; PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS); VAR name, title, keywords, description: ARRAY [0..511] OF CHAR; BEGIN failures := 0; Check(DemoCatalogCount() >= 140, "catalogue has >= 140 demos"); DemoCatalogGet(0, name, title, keywords, description); Check(name[0] # 0C, "catalogue entry 0 has a name"); Check(Count() >= 5, "registry has >= 5 ported demos"); NameOf(0, name); Check(name[0] # 0C, "registry entry 0 has a name"); Check(IsPorted("links"), "links is ported"); Check(IsPorted("aspect_frame") = FALSE, "aspect_frame not ported yet"); Check(BuildByName("does_not_exist", NIL) = NIL, "unknown demo yields NIL"); BuildAndClose("links"); BuildAndClose("listbox"); BuildAndClose("flowbox"); BuildAndClose("expander"); BuildAndClose("css_basics"); BuildAndClose("spinner"); BuildAndClose("panes"); BuildAndClose("overlay"); BuildAndClose("sizegroup"); BuildAndClose("fixed2"); BuildAndClose("layoutmanager"); BuildAndClose("read_more"); BuildAndClose("rotated_text"); BuildAndClose("textmask"); BuildAndClose("textundo"); BuildAndClose("headerbar"); BuildAndClose("infobar"); BuildAndClose("tabs"); BuildAndClose("password_entry"); BuildAndClose("search_entry"); BuildAndClose("tagged_entry"); BuildAndClose("combobox"); BuildAndClose("entry_completion"); BuildAndClose("entry_undo"); BuildAndClose("drawingarea"); BuildAndClose("gestures"); IF failures = 0 THEN printf("test_demos: PASS\n") ELSE printf("test_demos: FAIL (%d)\n", failures) END; g_application_quit(application) END OnActivate; VAR rc: INTEGER; BEGIN failures := 1; app := gtk_application_new(AppId, 0); IF app = NIL THEN printf("test_demos: FAIL (no app)\n"); HALT(1) END; Connect(app, "activate", ADR(OnActivate), NIL); rc := g_application_run(app, 0, NIL); IF failures = 0 THEN HALT(0) ELSE HALT(1) END END test_demos.