test_models2.mod 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. MODULE test_models2 ;
  2. (*
  3. m2-GTK4 test - multi-selection, bitsets and tree/directory/bookmark
  4. models. Requires GTK initialised (and so a display).
  5. *)
  6. FROM Gtk IMPORT gtk_init;
  7. FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append;
  8. FROM GtkMultiSelection IMPORT gtk_multi_selection_new,
  9. gtk_multi_selection_get_model;
  10. FROM GtkSelectionModel IMPORT gtk_selection_model_select_item,
  11. gtk_selection_model_is_selected;
  12. FROM GtkBitset IMPORT gtk_bitset_new_empty, gtk_bitset_add,
  13. gtk_bitset_contains, gtk_bitset_get_size, gtk_bitset_get_nth,
  14. gtk_bitset_unref;
  15. FROM GtkTreeListModel IMPORT gtk_tree_list_model_new,
  16. gtk_tree_list_model_get_model, gtk_tree_list_model_get_child_row,
  17. gtk_tree_list_row_get_item, gtk_tree_list_row_get_depth;
  18. FROM GtkDirectoryList IMPORT gtk_directory_list_new;
  19. FROM GtkBookmarkList IMPORT gtk_bookmark_list_new;
  20. FROM GObject IMPORT g_object_ref, g_object_unref;
  21. FROM GListModel IMPORT g_list_model_get_n_items;
  22. FROM SYSTEM IMPORT ADDRESS, ADR;
  23. FROM libc IMPORT printf;
  24. VAR
  25. failed: BOOLEAN;
  26. PROCEDURE Check (condition: BOOLEAN; what: ARRAY OF CHAR);
  27. BEGIN
  28. IF NOT condition THEN
  29. printf("FAIL: %s\n", what);
  30. failed := TRUE
  31. END
  32. END Check;
  33. (* GListModel *create(gpointer item, gpointer user_data): no children *)
  34. PROCEDURE CreateFunc (item: ADDRESS; user: ADDRESS) : ADDRESS;
  35. BEGIN
  36. RETURN NIL
  37. END CreateFunc;
  38. VAR
  39. list, ms, bs, tree, row, dir, book: ADDRESS;
  40. BEGIN
  41. failed := FALSE;
  42. gtk_init();
  43. list := gtk_string_list_new(NIL);
  44. gtk_string_list_append(list, "one");
  45. gtk_string_list_append(list, "two");
  46. gtk_string_list_append(list, "three");
  47. (* multi-selection: takes ownership of the model *)
  48. ms := gtk_multi_selection_new(g_object_ref(list));
  49. Check(gtk_multi_selection_get_model(ms) # NIL, "multi selection model");
  50. gtk_selection_model_select_item(ms, 1, 0);
  51. Check(gtk_selection_model_is_selected(ms, 1) # 0, "item 1 selected");
  52. Check(gtk_selection_model_is_selected(ms, 0) = 0, "item 0 not selected");
  53. (* bitset *)
  54. bs := gtk_bitset_new_empty();
  55. Check(gtk_bitset_add(bs, 3) # 0, "bitset add");
  56. Check(gtk_bitset_contains(bs, 3) # 0, "bitset contains");
  57. Check(gtk_bitset_get_size(bs) = 1, "bitset size");
  58. Check(gtk_bitset_get_nth(bs, 0) = 3, "bitset nth");
  59. gtk_bitset_unref(bs);
  60. (* tree list model over the same list *)
  61. tree := gtk_tree_list_model_new(g_object_ref(list), 0, 1,
  62. ADR(CreateFunc), NIL, NIL);
  63. Check(gtk_tree_list_model_get_model(tree) # NIL, "tree model");
  64. Check(g_list_model_get_n_items(gtk_tree_list_model_get_model(tree)) = 3,
  65. "tree count");
  66. row := gtk_tree_list_model_get_child_row(tree, 0);
  67. Check(row # NIL, "tree child row");
  68. IF row # NIL THEN
  69. Check(gtk_tree_list_row_get_item(row) # NIL, "tree row item");
  70. Check(gtk_tree_list_row_get_depth(row) = 0, "tree row depth")
  71. END;
  72. (* directory + bookmark lists construct *)
  73. dir := gtk_directory_list_new("standard::name", NIL);
  74. Check(dir # NIL, "directory list");
  75. book := gtk_bookmark_list_new("/nonexistent-bookmarks", "standard::name");
  76. Check(book # NIL, "bookmark list");
  77. IF failed THEN
  78. printf("test_models2: FAIL\n");
  79. HALT(1)
  80. ELSE
  81. printf("test_models2: PASS\n");
  82. HALT(0)
  83. END
  84. END test_models2.