MODULE test_models2 ; (* m2-GTK4 test - multi-selection, bitsets and tree/directory/bookmark models. Requires GTK initialised (and so a display). *) FROM Gtk IMPORT gtk_init; FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append; FROM GtkMultiSelection IMPORT gtk_multi_selection_new, gtk_multi_selection_get_model; FROM GtkSelectionModel IMPORT gtk_selection_model_select_item, gtk_selection_model_is_selected; FROM GtkBitset IMPORT gtk_bitset_new_empty, gtk_bitset_add, gtk_bitset_contains, gtk_bitset_get_size, gtk_bitset_get_nth, gtk_bitset_unref; FROM GtkTreeListModel IMPORT gtk_tree_list_model_new, gtk_tree_list_model_get_model, gtk_tree_list_model_get_child_row, gtk_tree_list_row_get_item, gtk_tree_list_row_get_depth; FROM GtkDirectoryList IMPORT gtk_directory_list_new; FROM GtkBookmarkList IMPORT gtk_bookmark_list_new; FROM GObject IMPORT g_object_ref, g_object_unref; FROM GListModel IMPORT g_list_model_get_n_items; FROM SYSTEM IMPORT ADDRESS, ADR; FROM libc IMPORT printf; VAR failed: BOOLEAN; PROCEDURE Check (condition: BOOLEAN; what: ARRAY OF CHAR); BEGIN IF NOT condition THEN printf("FAIL: %s\n", what); failed := TRUE END END Check; (* GListModel *create(gpointer item, gpointer user_data): no children *) PROCEDURE CreateFunc (item: ADDRESS; user: ADDRESS) : ADDRESS; BEGIN RETURN NIL END CreateFunc; VAR list, ms, bs, tree, row, dir, book: ADDRESS; BEGIN failed := FALSE; gtk_init(); list := gtk_string_list_new(NIL); gtk_string_list_append(list, "one"); gtk_string_list_append(list, "two"); gtk_string_list_append(list, "three"); (* multi-selection: takes ownership of the model *) ms := gtk_multi_selection_new(g_object_ref(list)); Check(gtk_multi_selection_get_model(ms) # NIL, "multi selection model"); gtk_selection_model_select_item(ms, 1, 0); Check(gtk_selection_model_is_selected(ms, 1) # 0, "item 1 selected"); Check(gtk_selection_model_is_selected(ms, 0) = 0, "item 0 not selected"); (* bitset *) bs := gtk_bitset_new_empty(); Check(gtk_bitset_add(bs, 3) # 0, "bitset add"); Check(gtk_bitset_contains(bs, 3) # 0, "bitset contains"); Check(gtk_bitset_get_size(bs) = 1, "bitset size"); Check(gtk_bitset_get_nth(bs, 0) = 3, "bitset nth"); gtk_bitset_unref(bs); (* tree list model over the same list *) tree := gtk_tree_list_model_new(g_object_ref(list), 0, 1, ADR(CreateFunc), NIL, NIL); Check(gtk_tree_list_model_get_model(tree) # NIL, "tree model"); Check(g_list_model_get_n_items(gtk_tree_list_model_get_model(tree)) = 3, "tree count"); row := gtk_tree_list_model_get_child_row(tree, 0); Check(row # NIL, "tree child row"); IF row # NIL THEN Check(gtk_tree_list_row_get_item(row) # NIL, "tree row item"); Check(gtk_tree_list_row_get_depth(row) = 0, "tree row depth") END; (* directory + bookmark lists construct *) dir := gtk_directory_list_new("standard::name", NIL); Check(dir # NIL, "directory list"); book := gtk_bookmark_list_new("/nonexistent-bookmarks", "standard::name"); Check(book # NIL, "bookmark list"); IF failed THEN printf("test_models2: FAIL\n"); HALT(1) ELSE printf("test_models2: PASS\n"); HALT(0) END END test_models2.