comparison test/testlibrary/OutputAnalyzerTest.java @ 7960:9be6cde7919d

8006413: Add utility classes for writing better multiprocess tests in jtreg Summary: Add a few utility classes to test/testlibrary to support multi process testing in jtreg tests. Added a test case for one of the utility classes. Also reviewed by Vitaly Davidovich Reviewed-by: brutisso, dholmes, vlivanov, nloodin, mgerdin
author ctornqvi
date Fri, 25 Jan 2013 10:14:22 +0100
parents
children 3b890cd4da64
comparison
equal deleted inserted replaced
7959:7885e162c30f 7960:9be6cde7919d
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Test the OutputAnalyzer utility class
27 * @library /testlibrary
28 */
29
30 import com.oracle.java.testlibrary.OutputAnalyzer;
31
32 public class OutputAnalyzerTest {
33
34 public static void main(String args[]) throws Exception {
35
36 String stdout = "aaaaaa";
37 String stderr = "bbbbbb";
38
39 OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);
40
41 if (!stdout.equals(output.getStdout())) {
42 throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'");
43 }
44
45 if (!stderr.equals(output.getStderr())) {
46 throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'");
47 }
48
49 try {
50 output.shouldContain(stdout);
51 output.stdoutShouldContain(stdout);
52 output.shouldContain(stderr);
53 output.stderrShouldContain(stderr);
54 } catch (RuntimeException e) {
55 throw new Exception("shouldContain() failed", e);
56 }
57
58 try {
59 output.shouldContain("cccc");
60 throw new Exception("shouldContain() failed to throw exception");
61 } catch (RuntimeException e) {
62 // expected
63 }
64
65 try {
66 output.stdoutShouldContain(stderr);
67 throw new Exception("stdoutShouldContain() failed to throw exception");
68 } catch (RuntimeException e) {
69 // expected
70 }
71
72 try {
73 output.stderrShouldContain(stdout);
74 throw new Exception("stdoutShouldContain() failed to throw exception");
75 } catch (RuntimeException e) {
76 // expected
77 }
78
79 try {
80 output.shouldNotContain("cccc");
81 output.stdoutShouldNotContain("cccc");
82 output.stderrShouldNotContain("cccc");
83 } catch (RuntimeException e) {
84 throw new Exception("shouldNotContain() failed", e);
85 }
86
87 try {
88 output.shouldNotContain(stdout);
89 throw new Exception("shouldContain() failed to throw exception");
90 } catch (RuntimeException e) {
91 // expected
92 }
93
94 try {
95 output.stdoutShouldNotContain(stdout);
96 throw new Exception("shouldContain() failed to throw exception");
97 } catch (RuntimeException e) {
98 // expected
99 }
100
101 try {
102 output.stderrShouldNotContain(stderr);
103 throw new Exception("shouldContain() failed to throw exception");
104 } catch (RuntimeException e) {
105 // expected
106 }
107 }
108 }