test_demos.mod 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. MODULE test_demos ;
  2. (*
  3. m2-GTK4 test - the m2 gtk-demo catalogue and registry (demos/).
  4. Checks that the full catalogue is present and that ported demos can be
  5. built and torn down. Requires a display.
  6. *)
  7. FROM GtkApplication IMPORT gtk_application_new;
  8. FROM Gio IMPORT g_application_run, g_application_quit;
  9. FROM GtkDemo IMPORT Count, NameOf, IsPorted, BuildByName;
  10. FROM DemoCatalog IMPORT DemoCatalogCount, DemoCatalogGet;
  11. FROM GtkUtils IMPORT Connect;
  12. FROM SYSTEM IMPORT ADDRESS, ADR;
  13. FROM libc IMPORT printf;
  14. CONST
  15. AppId = "org.example.m2gtk4.TestDemos";
  16. VAR
  17. app: ADDRESS;
  18. failures: INTEGER;
  19. PROCEDURE StrEqual (a, b: ARRAY OF CHAR) : BOOLEAN;
  20. VAR
  21. i: CARDINAL;
  22. BEGIN
  23. i := 0;
  24. WHILE (a[i] # 0C) AND (b[i] # 0C) DO
  25. IF a[i] # b[i] THEN RETURN FALSE END;
  26. INC(i)
  27. END;
  28. RETURN a[i] = b[i]
  29. END StrEqual;
  30. PROCEDURE Check (cond: BOOLEAN; msg: ARRAY OF CHAR);
  31. BEGIN
  32. IF cond THEN
  33. printf(" ok - %s\n", msg)
  34. ELSE
  35. printf(" NOT OK - %s\n", msg);
  36. INC(failures)
  37. END
  38. END Check;
  39. (* build a demo once (creates + shows its window), then toggle it off. *)
  40. PROCEDURE BuildAndClose (name: ARRAY OF CHAR);
  41. VAR
  42. w: ADDRESS;
  43. BEGIN
  44. w := BuildByName(name, NIL);
  45. Check(w # NIL, name);
  46. IF w # NIL THEN w := BuildByName(name, NIL) END
  47. END BuildAndClose;
  48. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  49. VAR
  50. name, title, keywords, description: ARRAY [0..511] OF CHAR;
  51. BEGIN
  52. failures := 0;
  53. Check(DemoCatalogCount() >= 140, "catalogue has >= 140 demos");
  54. DemoCatalogGet(0, name, title, keywords, description);
  55. Check(name[0] # 0C, "catalogue entry 0 has a name");
  56. Check(Count() >= 5, "registry has >= 5 ported demos");
  57. NameOf(0, name);
  58. Check(name[0] # 0C, "registry entry 0 has a name");
  59. Check(IsPorted("links"), "links is ported");
  60. Check(IsPorted("aspect_frame") = FALSE, "aspect_frame not ported yet");
  61. Check(BuildByName("does_not_exist", NIL) = NIL, "unknown demo yields NIL");
  62. BuildAndClose("links");
  63. BuildAndClose("listbox");
  64. BuildAndClose("flowbox");
  65. BuildAndClose("expander");
  66. BuildAndClose("css_basics");
  67. BuildAndClose("spinner");
  68. BuildAndClose("panes");
  69. BuildAndClose("overlay");
  70. BuildAndClose("sizegroup");
  71. BuildAndClose("fixed2");
  72. BuildAndClose("layoutmanager");
  73. BuildAndClose("read_more");
  74. BuildAndClose("rotated_text");
  75. BuildAndClose("textmask");
  76. BuildAndClose("textundo");
  77. BuildAndClose("headerbar");
  78. BuildAndClose("infobar");
  79. BuildAndClose("tabs");
  80. BuildAndClose("password_entry");
  81. BuildAndClose("search_entry");
  82. BuildAndClose("tagged_entry");
  83. BuildAndClose("combobox");
  84. BuildAndClose("entry_completion");
  85. BuildAndClose("entry_undo");
  86. BuildAndClose("drawingarea");
  87. BuildAndClose("gestures");
  88. IF failures = 0 THEN
  89. printf("test_demos: PASS\n")
  90. ELSE
  91. printf("test_demos: FAIL (%d)\n", failures)
  92. END;
  93. g_application_quit(application)
  94. END OnActivate;
  95. VAR
  96. rc: INTEGER;
  97. BEGIN
  98. failures := 1;
  99. app := gtk_application_new(AppId, 0);
  100. IF app = NIL THEN
  101. printf("test_demos: FAIL (no app)\n");
  102. HALT(1)
  103. END;
  104. Connect(app, "activate", ADR(OnActivate), NIL);
  105. rc := g_application_run(app, 0, NIL);
  106. IF failures = 0 THEN HALT(0) ELSE HALT(1) END
  107. END test_demos.