summaryrefslogtreecommitdiff
path: root/installed-tests/js/testGTypeClass.js
blob: e15b9ec9dbe2fdbe3c523fc18640070fbb6a007f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2012 Red Hat, Inc.
// SPDX-FileCopyrightText: 2013 Giovanni Campagna <gcampagna@src.gnome.org>

// We use Gio to have some objects that we know exist
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;

describe('Looking up param specs', function () {
    let p1, p2;
    beforeEach(function () {
        let findProperty = GObject.Object.find_property;
        p1 = findProperty.call(Gio.ThemedIcon, 'name');
        p2 = findProperty.call(Gio.SimpleAction, 'enabled');
    });

    it('works', function () {
        expect(p1 instanceof GObject.ParamSpec).toBeTruthy();
        expect(p2 instanceof GObject.ParamSpec).toBeTruthy();
    });

    it('gives the correct name', function () {
        expect(p1.name).toEqual('name');
        expect(p2.name).toEqual('enabled');
    });

    it('gives the default value if present', function () {
        expect(p2.default_value).toBeTruthy();
    });
});

describe('GType object', function () {
    it('has a name', function () {
        expect(GObject.TYPE_NONE.name).toEqual('void');
        expect(GObject.TYPE_STRING.name).toEqual('gchararray');
    });

    it('has a read-only name', function () {
        try {
            GObject.TYPE_STRING.name = 'foo';
        } catch (e) {
        }
        expect(GObject.TYPE_STRING.name).toEqual('gchararray');
    });

    it('has an undeletable name', function () {
        try {
            delete GObject.TYPE_STRING.name;
        } catch (e) {
        }
        expect(GObject.TYPE_STRING.name).toEqual('gchararray');
    });

    it('has a string representation', function () {
        expect(GObject.TYPE_NONE.toString()).toEqual("[object GType for 'void']");
        expect(GObject.TYPE_STRING.toString()).toEqual("[object GType for 'gchararray']");
    });
});

describe('GType marshalling', function () {
    it('marshals the invalid GType object into JS null', function () {
        expect(GObject.type_from_name('NonexistentType')).toBeNull();
        expect(GObject.type_parent(GObject.TYPE_STRING)).toBeNull();
    });
});