# Testcase for implementing GListModel interface in Python

from gi.repository import Gio, GObject

def test_list_model():
    data = ["Foo", "Bar", "Bazunga"]

    class MyListItem(GObject.Object):
        def __init__(self, value):
            super(MyListItem, self).__init__()
            self.value = value


    class MyListModel(GObject.Object, Gio.ListModel):
        def __init__(self):
            super(MyListModel, self).__init__()
            self.items = [MyListItem(s) for s in data]

        def do_get_n_items(self):
            return len(self.items)

        def do_get_item(self, position):
            print ("Returning %s for %i" % (self.items[position], position))
            return self.items[position]


    mylist = MyListModel()
    for i in range(0, mylist.get_n_items()):
        item = mylist.get_item(i)
        print(item)
        assert item.value == data[i]


test_list_model()
print("Everything is OK!")