|
1 /* |
|
2 * Copyright (c) 2017, 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 * @bug 8168444 |
|
27 * @summary Test of jdeprscan handling of primitives and primitive arrays. |
|
28 * @modules jdk.jdeps/com.sun.tools.jdeprscan |
|
29 * @run main jdk.jdeprscan.TestNotFound |
|
30 */ |
|
31 |
|
32 package jdk.jdeprscan; |
|
33 |
|
34 import com.sun.tools.jdeprscan.Main; |
|
35 import java.io.ByteArrayInputStream; |
|
36 import java.io.ByteArrayOutputStream; |
|
37 import java.io.File; |
|
38 import java.io.IOException; |
|
39 import java.io.PrintStream; |
|
40 import java.util.Scanner; |
|
41 |
|
42 public class TestNotFound { |
|
43 |
|
44 public static void main(String[] args) throws IOException { |
|
45 final String SEP = File.separator; |
|
46 final String TESTCLASSES = System.getProperty("test.classes"); |
|
47 final String THISCLASS = |
|
48 TESTCLASSES + SEP + "jdk" + SEP + "jdeprscan" + SEP + "TestNotFound.class"; |
|
49 |
|
50 ByteArrayOutputStream outBaos = new ByteArrayOutputStream(); |
|
51 ByteArrayOutputStream errBaos = new ByteArrayOutputStream(); |
|
52 boolean mainResult; |
|
53 |
|
54 // Causes 5 Methodrefs to be generated, thus 5 occurrences |
|
55 // of the Target class not being found. But only one message |
|
56 // should be emitted. |
|
57 |
|
58 Target.method1(); |
|
59 Target.method2(); |
|
60 Target.method3(); |
|
61 Target.method4(); |
|
62 Target.method5(); |
|
63 |
|
64 try (PrintStream out = new PrintStream(outBaos, false, "UTF-8"); |
|
65 PrintStream err = new PrintStream(errBaos, false, "UTF-8")) { |
|
66 // Call jdeprscan without the proper classpath, so Target isn't found. |
|
67 // Result is checked below after output is dumped. |
|
68 mainResult = Main.call(out, err, THISCLASS); |
|
69 } |
|
70 |
|
71 byte[] outBytes = outBaos.toByteArray(); |
|
72 byte[] errBytes = errBaos.toByteArray(); |
|
73 ByteArrayInputStream outbais = new ByteArrayInputStream(outBytes); |
|
74 ByteArrayInputStream errbais = new ByteArrayInputStream(errBytes); |
|
75 |
|
76 System.out.println("--- stdout ---"); |
|
77 outbais.transferTo(System.out); |
|
78 System.out.println("--- end stdout ---"); |
|
79 |
|
80 System.out.println("--- stderr ---"); |
|
81 errbais.transferTo(System.out); |
|
82 System.out.println("--- end stderr ---"); |
|
83 |
|
84 long errCount = new Scanner(new String(errBytes, "UTF-8")).findAll("error:").count(); |
|
85 |
|
86 System.out.println("mainResult = " + mainResult); |
|
87 System.out.println("errCount = " + errCount); |
|
88 |
|
89 if (!mainResult) { |
|
90 System.out.println("FAIL: mainResult should be true"); |
|
91 } |
|
92 |
|
93 if (errCount != 1L) { |
|
94 System.out.println("FAIL: errCount should equal 1"); |
|
95 } |
|
96 |
|
97 if (!mainResult || errCount != 1L) { |
|
98 throw new AssertionError("Test failed."); |
|
99 } else { |
|
100 System.out.println("Test passed."); |
|
101 } |
|
102 } |
|
103 |
|
104 static class Target { |
|
105 static void method1() { } |
|
106 static void method2() { } |
|
107 static void method3() { } |
|
108 static void method4() { } |
|
109 static void method5() { } |
|
110 } |
|
111 } |