File: ValidateUniqueApplications.java

package info (click to toggle)
java-gnome 4.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,656 kB
  • ctags: 6,327
  • sloc: java: 24,414; ansic: 4,035; perl: 1,531; python: 1,186; makefile: 140
file content (111 lines) | stat: -rw-r--r-- 3,807 bytes parent folder | download
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
105
106
107
108
109
110
111
/*
 * java-gnome, a UI library for writing GTK and GNOME programs from Java!
 *
 * Copyright © 2009-2010 Operational Dynamics Consulting, Pty Ltd
 *
 * The code in this file, and the program it is a part of, is made available
 * to you by its authors as open source software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License version
 * 2 ("GPL") as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
 *
 * You should have received a copy of the GPL along with this program. If not,
 * see http://www.gnu.org/licenses/. The authors of this program may be
 * contacted through http://java-gnome.sourceforge.net/.
 */
package org.gnome.unique;

import org.gnome.gtk.GraphicalTestCase;

/**
 * Evaluate the behaviour of LibUnique
 */
public class ValidateUniqueApplications extends GraphicalTestCase
{
    public final void testNameValidation() {
        Application app;

        try {
            app = new Application("", null);
            fail("Should have thrown exception");
            return;
        } catch (IllegalArgumentException iae) {
            // good
        }

        try {
            app = new Application("MyApplication", null);
            fail("Should have thrown exception");
            return;
        } catch (IllegalArgumentException iae) {
            // good
        }

        try {
            app = new Application("org.gnome.Invalid$Application", null);
            fail("Should have thrown exception");
            return;
        } catch (IllegalArgumentException iae) {
            // good
        }

        if (false) {
            app.getClass(); // avoid warning
        }
    }

    /*
     * This is tricky. If we didn't ensure a unique name, and you've managed
     * to get another one of these test cases running, and wedged, then this
     * would fail. So we do some minimal effort to come up with a more-or-less
     * likely-to-be-unique name.
     */
    public final void testInstantiateApplicationObject() {
        final Application app;
        final String name;

        name = "test.java-gnome.InstantiateApplicationObject" + this.hashCode();
        app = new Application(name, null);

        assertEquals(name, app.getName());
        assertFalse(app.isRunning());
    }

    /*
     * Here's an interesting one. Since we've long said that GNOME is a
     * prerequisite for java-gnome, and in any event we encourage people
     * developing GNOME applications to be actually using GNOME, we "know"
     * Nautilus is running. :)
     * 
     * FUTURE This won't work in headless build environment, and really our
     * tests should pass in such. But it's this or we'd have to fire off
     * another process. This will do nicely for now.
     */
    public final void testIsNautilusRunning() {
        final Application app;

        app = new Application("org.gnome.Nautilus", null);
        assertTrue(app.isRunning());
    }

    /*
     * We, of course, know nothing of Nautilus's responses to internally
     * designated commands. They're "internal". But sending it Command.OPEN
     * results in your home directory coming up (so awesome), and CLOSE
     * results in it restarting (!). ACTIVATE seems harmless, and in testing
     * this I got an OK back.
     */
    public final void testSendToNautilus() {
        final Application app;
        final Response result;

        app = new Application("org.gnome.Nautilus", null);
        assertTrue(app.isRunning());

        result = app.sendMessage(Command.ACTIVATE, null);
        assertSame(Response.OK, result);
    }
}