Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/sound/sampled/AudioFileFormat/Properties.java
41152 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.midi.MidiFileFormat;
29
import javax.sound.midi.Sequence;
30
import javax.sound.sampled.AudioFileFormat;
31
import javax.sound.sampled.AudioFormat;
32
33
/**
34
* @test
35
* @bug 4666845
36
* @summary RFE: Add properties to AudioFileFormat and MidiFileFormat
37
*/
38
public class Properties {
39
40
static boolean g_failed = false;
41
42
// all of p1 need to be in p2
43
static boolean compare(Map p1, Map p2) {
44
boolean failed = false;
45
for(String key: (Set<String>) p1.keySet()) {
46
out(" testing key: "+key);
47
if (!p2.containsKey(key)) {
48
out(" missing property: '"+key+"'. Failed");
49
failed = true;
50
}
51
Object v1 = p1.get(key);
52
Object v2 = p2.get(key);
53
if (((v1 == null) && (v2 != null))
54
|| ((v1 != null) && (v2 == null))
55
|| !(v1.equals(v2))) {
56
out(" property '"+key+"' is different: "
57
+"expected='"+v1+"' "
58
+"actual='"+v2+"'. Failed");
59
failed = true;
60
}
61
}
62
// test if we can modify p2
63
try {
64
int oldSize = p2.size();
65
p2.clear();
66
if (oldSize > 0 && p2.size() == 0) {
67
out(" could clear the properties! Failed.");
68
failed = true;
69
}
70
} catch (Exception e) {
71
// correct
72
}
73
return failed;
74
}
75
76
public static void main(String argv[]) throws Exception {
77
// don't need to catch exceptions: any exception is a
78
// failure of this test
79
80
Map<String, Object> p = new HashMap<String,Object>();
81
p.put("author", "Florian");
82
p.put("duration", new Long(1000));
83
p.put("MyProp", "test");
84
85
out("Testing AudioFileFormat properties:");
86
// create an AudioFileFormat with properties
87
AudioFormat format = new AudioFormat( 44100.0f, 16, 2, true, false);
88
AudioFileFormat aff =
89
new AudioFileFormat(AudioFileFormat.Type.WAVE,
90
format, 1000, p);
91
// test that it has the properties
92
boolean failed = compare(p, aff.properties());
93
// test getProperty()
94
Object o = aff.getProperty("author");
95
if (o == null || !o.equals("Florian")) {
96
out(" getProperty did not report an existing property!");
97
failed = true;
98
}
99
o = aff.getProperty("does not exist");
100
if (o != null) {
101
out(" getProperty returned something for a non-existing property!");
102
failed = true;
103
}
104
if (!failed) {
105
out(" OK");
106
} else {
107
g_failed = true;
108
}
109
110
111
112
out("Testing MidiFileFormat properties:");
113
// create a MidiFileFormat with properties
114
MidiFileFormat mff =
115
new MidiFileFormat(0, Sequence.PPQ, 240,
116
1000, 100, p);
117
// test that it has the properties
118
failed = compare(p, mff.properties());
119
// test getProperty()
120
o = mff.getProperty("author");
121
if (o == null || !o.equals("Florian")) {
122
out(" getProperty did not report an existing property!");
123
failed = true;
124
}
125
o = mff.getProperty("does not exist");
126
if (o != null) {
127
out(" getProperty returned something for a non-existing property!");
128
failed = true;
129
}
130
if (!failed) {
131
out(" OK");
132
} else {
133
g_failed = true;
134
}
135
136
137
if (g_failed) throw new Exception("Test FAILED!");
138
System.out.println("Test passed.");
139
}
140
141
static void out(String s) {
142
System.out.println(s);
143
}
144
}
145
146