Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Provider/ProviderInfoCheck.java
41149 views
1
/*
2
* Copyright (c) 2006, 2016, 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 6455351 8130181
27
* @summary Make sure the Provider.info entries have the correct values
28
* after going through serialization/deserialization.
29
* @author Valerie Peng
30
*/
31
32
import java.io.*;
33
import java.security.*;
34
import java.util.*;
35
36
public class ProviderInfoCheck {
37
38
public static void main(String[] args) throws Exception {
39
Provider p = new SampleProvider();
40
41
// Serialize and deserialize the above Provider object
42
ByteArrayOutputStream baos = new ByteArrayOutputStream();
43
ObjectOutputStream oos = new ObjectOutputStream(baos);
44
oos.writeObject(p);
45
oos.close();
46
ByteArrayInputStream bais =
47
new ByteArrayInputStream(baos.toByteArray());
48
ObjectInputStream ois = new ObjectInputStream(bais);
49
Provider p2 = (Provider) ois.readObject();
50
ois.close();
51
52
checkProviderInfoEntries(p2);
53
}
54
55
private static void checkProviderInfoEntries(Provider p)
56
throws Exception {
57
String value = (String) p.get("Provider.id name");
58
if (!SampleProvider.NAME.equalsIgnoreCase(value) ||
59
!p.getName().equalsIgnoreCase(value)) {
60
throw new Exception("Test Failed: incorrect name!");
61
}
62
value = (String) p.get("Provider.id info");
63
if (!SampleProvider.INFO.equalsIgnoreCase(value) ||
64
!p.getInfo().equalsIgnoreCase(value)) {
65
throw new Exception("Test Failed: incorrect info!");
66
}
67
value = (String) p.get("Provider.id className");
68
if (!p.getClass().getName().equalsIgnoreCase(value)) {
69
throw new Exception("Test Failed: incorrect className!");
70
}
71
value = (String) p.get("Provider.id version");
72
if (!SampleProvider.VERSION.equalsIgnoreCase(value) ||
73
p.getVersionStr() != value) {
74
throw new Exception("Test Failed: incorrect versionStr!");
75
}
76
System.out.println("Test Passed");
77
}
78
79
private static class SampleProvider extends Provider {
80
static String NAME = "Sample";
81
static String VERSION = "1.1";
82
static String INFO = "Good for nothing";
83
SampleProvider() {
84
super(NAME, VERSION, INFO);
85
}
86
}
87
}
88
89