Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/sampled/AudioFormat/Properties.java
41153 views
1
/*
2
* Copyright (c) 2003, 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
import java.util.HashMap;
25
import java.util.Map;
26
import java.util.Set;
27
28
import javax.sound.sampled.AudioFormat;
29
30
/**
31
* @test
32
* @bug 4925767
33
* @summary RFE: Add Properties to AudioFormat
34
*/
35
public class Properties {
36
37
static boolean g_failed = false;
38
39
// all of p1 need to be in p2
40
static boolean compare(Map p1, Map p2) {
41
boolean failed = false;
42
for(String key: (Set<String>) p1.keySet()) {
43
out(" testing key: "+key);
44
if (!p2.containsKey(key)) {
45
out(" missing property: '"+key+"'. Failed");
46
failed = true;
47
}
48
Object v1 = p1.get(key);
49
Object v2 = p2.get(key);
50
if (((v1 == null) && (v2 != null))
51
|| ((v1 != null) && (v2 == null))
52
|| !(v1.equals(v2))) {
53
out(" property '"+key+"' is different: "
54
+"expected='"+v1+"' "
55
+"actual='"+v2+"'. Failed");
56
failed = true;
57
}
58
}
59
// test if we can modify p2
60
try {
61
int oldSize = p2.size();
62
p2.clear();
63
if (oldSize > 0 && p2.size() == 0) {
64
out(" could clear the properties! Failed.");
65
failed = true;
66
}
67
} catch (Exception e) {
68
// correct
69
}
70
return failed;
71
}
72
73
74
public static void main(String argv[]) throws Exception {
75
// don't need to catch exceptions: any exception is a
76
// failure of this test
77
78
Map<String, Object> p = new HashMap<String,Object>();
79
p.put("bitrate", new Integer(128));
80
p.put("quality", new Integer(10));
81
p.put("MyProp", "test");
82
83
out("Testing AudioFileFormat properties:");
84
// create an AudioFileFormat with properties
85
AudioFormat format =
86
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
87
44100.0f, 16, 2, 4, 44100.0f, false, p);
88
// test that it has the properties
89
boolean failed = compare(p, format.properties());
90
// test getProperty()
91
Object o = format.getProperty("MyProp");
92
if (o == null || !o.equals("test")) {
93
out(" getProperty did not report an existing property!");
94
failed = true;
95
}
96
o = format.getProperty("does not exist");
97
if (o != null) {
98
out(" getProperty returned something for a non-existing property!");
99
failed = true;
100
}
101
if (!failed) {
102
out(" OK");
103
} else {
104
g_failed = true;
105
}
106
107
if (g_failed) throw new Exception("Test FAILED!");
108
System.out.println("Test passed.");
109
}
110
111
static void out(String s) {
112
System.out.println(s);
113
}
114
115
}
116
117