File: components-validator-test.vala

package info (click to toggle)
geary 46.0-12
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 15,092 kB
  • sloc: javascript: 972; ansic: 722; sql: 247; xml: 183; python: 30; makefile: 28; sh: 24
file content (104 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (5)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright 2019 Michael Gratton <mike@vee.net>
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later). See the COPYING file in this distribution.
 */


public class Components.ValidatorTest : TestCase {


    private Gtk.Entry? entry = null;


    public ValidatorTest() {
        base("Components.ValidatorTest");
        add_test("manual_empty", manual_empty);
        add_test("manual_valid", manual_valid);
        add_test("manual_not_required", manual_not_required);
    }

    public override void set_up() {
        this.entry = new Gtk.Entry();
    }

    public override void tear_down() {
        this.entry = null;
    }

    public void manual_empty() throws GLib.Error {
        Validator test_article = new Validator(this.entry);

        bool finished = false;
        Validator.Trigger?  reason = null;
        Validator.Validity? prev_state = null;
        test_article.state_changed.connect((r, p) => {
                finished = true;
                reason = r;
                prev_state = p;
            });

        test_article.validate();

        while (!finished) {
            this.main_loop.iteration(true);
        }

        assert_false(test_article.is_valid);
        assert_true(test_article.state == EMPTY);
        assert_true(reason == MANUAL);
        assert_true(prev_state == INDETERMINATE);
    }

    public void manual_valid() throws GLib.Error {
        this.entry.text = "OHHAI";
        Validator test_article = new Validator(this.entry);

        bool finished = false;
        Validator.Trigger?  reason = null;
        Validator.Validity? prev_state = null;
        test_article.state_changed.connect((r, p) => {
                finished = true;
                reason = r;
                prev_state = p;
            });

        test_article.validate();

        while (!finished) {
            this.main_loop.iteration(true);
        }

        assert_true(test_article.is_valid);
        assert_true(test_article.state == VALID);
        assert_true(reason == MANUAL);
        assert_true(prev_state == INDETERMINATE);
    }

    public void manual_not_required() throws GLib.Error {
        Validator test_article = new Validator(this.entry);
        test_article.is_required = false;

        bool finished = false;
        Validator.Trigger?  reason = null;
        Validator.Validity? prev_state = null;
        test_article.state_changed.connect((r, p) => {
                finished = true;
                reason = r;
                prev_state = p;
            });

        test_article.validate();

        while (!finished) {
            this.main_loop.iteration(true);
        }

        assert_true(test_article.is_valid);
        assert_true(test_article.state == VALID);
        assert_true(reason == MANUAL);
        assert_true(prev_state == INDETERMINATE);
    }

}