Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/UnixDomainSocketAddress/LengthTest.java
41149 views
1
/*
2
* Copyright (c) 2020, 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 UnixDomainSocketAddress constructor
27
* @library /test/lib
28
* @run testng/othervm LengthTest
29
*/
30
31
import org.testng.annotations.DataProvider;
32
import org.testng.annotations.Test;
33
34
import static java.lang.System.out;
35
import static java.net.StandardProtocolFamily.UNIX;
36
import static jdk.test.lib.Asserts.assertTrue;
37
38
import java.net.UnixDomainSocketAddress;
39
import java.io.IOException;
40
import java.nio.channels.SocketChannel;
41
import java.nio.file.Path;
42
43
public class LengthTest {
44
final int namelen = 100; // length close to max
45
46
@DataProvider(name = "strings")
47
public Object[][] strings() {
48
if (namelen == -1)
49
return new Object[][] {new String[]{""}};
50
51
return new Object[][]{
52
{""},
53
{new String(new char[100]).replaceAll("\0", "x")},
54
{new String(new char[namelen]).replaceAll("\0", "x")},
55
{new String(new char[namelen-1]).replaceAll("\0", "x")},
56
};
57
}
58
59
@Test(dataProvider = "strings")
60
public void expectPass(String s) {
61
var addr = UnixDomainSocketAddress.of(s);
62
assertTrue(addr.getPath().toString().equals(s), "getPathName.equals(s)");
63
var p = Path.of(s);
64
addr = UnixDomainSocketAddress.of(p);
65
assertTrue(addr.getPath().equals(p), "getPath.equals(p)");
66
}
67
68
@Test
69
public void expectNPE() {
70
try {
71
String s = null;
72
UnixDomainSocketAddress.of(s);
73
throw new RuntimeException("Expected NPE");
74
} catch (NullPointerException npe) {
75
out.println("\tCaught expected exception: " + npe);
76
}
77
try {
78
Path p = null;
79
UnixDomainSocketAddress.of(p);
80
throw new RuntimeException("Expected NPE");
81
} catch (NullPointerException npe) {
82
out.println("\tCaught expected exception: " + npe);
83
}
84
}
85
}
86
87