Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d3aea9340db1e0a56960b1eca6bec81d566ce699 (plain) (blame)
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
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 *******************************************************************************/

package org.eclipse.linuxtools.systemtap.structures.runnable;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.eclipse.linuxtools.systemtap.structures.runnable.Command;
import org.eclipse.linuxtools.systemtap.ui.tests.SystemtapTest;
import org.junit.Before;
import org.junit.Test;


public class CommandTest extends SystemtapTest{

	@Before
	public void setUp() {
		tc = new Command(new String[] {"ls", "/home/"}, null);
	}

	@Test
	public void testCommand() {
		assertNotNull("Command not null", tc);

		tc = new Command(null, null);
		assertNotNull("Command not null", tc);

		tc = new Command(new String[] {}, null);
		assertNotNull("Command not null", tc);

		tc = new Command(new String[] {""}, null);
		assertNotNull("Command not null", tc);

		tc = new Command(new String[] {"a"}, null);
		assertNotNull("Command not null", tc);

		tc = new Command(new String[] {"ls", "/"}, null);
		assertNotNull("Command not null", tc);
	}

	@Test
	public void testIsFinished() {
		assumeTrue(stapInstalled);
		assertTrue("Not finished", tc.isRunning());
		tc.stop();
		assertFalse("Finished", tc.isRunning());
	}

	@Test
	public void testGetReturnValue() {
		assertEquals(Integer.MAX_VALUE, tc.getReturnValue());
	}

	@Test
	public void testIsDisposed() {
		assertFalse(tc.isDisposed());
		tc.dispose();
		assertTrue(tc.isDisposed());
	}

	@Test
	public void testLoggedCommand() {
		assumeTrue(stapInstalled);
		tc.dispose();

		tc = new Command(new String[] {"stap", "-v", "-p1", "-e", "probe nosuchfunc{}"}, null);
		tc.start();
		assertTrue(tc.isRunning());
		assertFalse(tc.isDisposed());
		tc.stop();
		assertFalse(tc.isRunning());
		assertFalse(tc.isDisposed());
		tc.dispose();

		tc = new Command(new String[] {"stap", "-v", "-p1", "-e", "probe nosuchfunc{}"}, null);
		tc.start();
		assertTrue(tc.isRunning());
		assertFalse(tc.isDisposed());
		tc.stop();
		assertFalse(tc.isRunning());
		assertFalse(tc.isDisposed());
		tc.dispose();
	}

	@Test
	public void testStop() {
		assumeTrue(stapInstalled);
		tc.start();
		assertTrue(tc.isRunning());
		tc.stop();
		assertFalse(tc.isRunning());
	}

	@Test
	public void testDispose() {
		assertFalse(tc.isDisposed());
		tc.dispose();
		assertTrue(tc.isDisposed());
	}

	Command tc;
}

Back to the top