Path: blob/master/test/jdk/javax/sound/sampled/AudioFormat/Properties.java
41153 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.HashMap;24import java.util.Map;25import java.util.Set;2627import javax.sound.sampled.AudioFormat;2829/**30* @test31* @bug 492576732* @summary RFE: Add Properties to AudioFormat33*/34public class Properties {3536static boolean g_failed = false;3738// all of p1 need to be in p239static boolean compare(Map p1, Map p2) {40boolean failed = false;41for(String key: (Set<String>) p1.keySet()) {42out(" testing key: "+key);43if (!p2.containsKey(key)) {44out(" missing property: '"+key+"'. Failed");45failed = true;46}47Object v1 = p1.get(key);48Object v2 = p2.get(key);49if (((v1 == null) && (v2 != null))50|| ((v1 != null) && (v2 == null))51|| !(v1.equals(v2))) {52out(" property '"+key+"' is different: "53+"expected='"+v1+"' "54+"actual='"+v2+"'. Failed");55failed = true;56}57}58// test if we can modify p259try {60int oldSize = p2.size();61p2.clear();62if (oldSize > 0 && p2.size() == 0) {63out(" could clear the properties! Failed.");64failed = true;65}66} catch (Exception e) {67// correct68}69return failed;70}717273public static void main(String argv[]) throws Exception {74// don't need to catch exceptions: any exception is a75// failure of this test7677Map<String, Object> p = new HashMap<String,Object>();78p.put("bitrate", new Integer(128));79p.put("quality", new Integer(10));80p.put("MyProp", "test");8182out("Testing AudioFileFormat properties:");83// create an AudioFileFormat with properties84AudioFormat format =85new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,8644100.0f, 16, 2, 4, 44100.0f, false, p);87// test that it has the properties88boolean failed = compare(p, format.properties());89// test getProperty()90Object o = format.getProperty("MyProp");91if (o == null || !o.equals("test")) {92out(" getProperty did not report an existing property!");93failed = true;94}95o = format.getProperty("does not exist");96if (o != null) {97out(" getProperty returned something for a non-existing property!");98failed = true;99}100if (!failed) {101out(" OK");102} else {103g_failed = true;104}105106if (g_failed) throw new Exception("Test FAILED!");107System.out.println("Test passed.");108}109110static void out(String s) {111System.out.println(s);112}113114}115116117