You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/08/01 06:46:25 UTC

svn commit: r427443 - in /incubator/harmony/enhanced/classlib/trunk/modules/sound/src: main/java/javax/sound/midi/MidiFileFormat.java test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java

Author: smishura
Date: Mon Jul 31 21:46:25 2006
New Revision: 427443

URL: http://svn.apache.org/viewvc?rev=427443&view=rev
Log:
Apply patch for HARMONY-1020 ([classlib][sound] Class MidiFileFormat and test MidiFileFormatTest from package javax.sound.midi)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java   (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiFileFormat.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiFileFormat.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiFileFormat.java?rev=427443&r1=427442&r2=427443&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiFileFormat.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiFileFormat.java Mon Jul 31 21:46:25 2006
@@ -16,6 +16,8 @@
 
 package javax.sound.midi;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 public class MidiFileFormat {
@@ -30,49 +32,57 @@
     protected int resolution;
 
     protected int type;
+    
+    private HashMap<String, Object> properties;
 
     public MidiFileFormat(int type, float divisionType, int resolution, int bytes,
             long microseconds) {
-        //TODO
+        this.type = type;
+        this.divisionType = divisionType;
+        this.resolution = resolution;
+        this.byteLength = bytes;
+        this.microsecondLength = microseconds;
+        this.properties = new HashMap<String, Object>();
     }
 
     public MidiFileFormat(int type, float divisionType, int resolution, int bytes,
             long microseconds, Map<String, Object> properties) {
-        //TODO
+        this.type = type;
+        this.divisionType = divisionType;
+        this.resolution = resolution;
+        this.byteLength = bytes;
+        this.microsecondLength = microseconds;
+        
+        this.properties = new HashMap<String, Object>();
+        this.properties.putAll(properties);
     }
 
     public int getByteLength() {
-        //TODO
-        return 1;
+        return byteLength;
     }
 
     public float getDivisionType() {
-        //TODO
-        return 1.0F;
+        return divisionType;
     }
 
     public long getMicrosecondLength() {
-        //TODO
-        return 1L;
+        return microsecondLength;
     }
 
     public Object getProperty(String key) {
-        //TODO
-        return null;
+        return properties.get(key);
     }
 
     public int getResolution() {
-        //TODO
-        return 1;
+        return resolution;
     }
 
     public int getType() {
-        //TODO
-        return 1;
+        return type;
     }
 
     public Map<String, Object> properties() {
-        //TODO
-        return null;
+        return Collections.unmodifiableMap(properties);
+        
     }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java?rev=427443&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java Mon Jul 31 21:46:25 2006
@@ -0,0 +1,119 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.sound.tests.javax.sound.midi;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.sound.midi.MidiFileFormat;
+
+import junit.framework.TestCase;
+
+public class MidiFileFormatTest extends TestCase {
+    /**
+     * test constructor(int, float, int, int, long, Map<String, Object>)
+     */
+    public void test_constructor() {
+        Map<String, Object> table = new Hashtable<String, Object>();
+        table.put("name", "harmony");
+        table.put("organization", "apache");
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, -4, 5L, table);
+        assertNull(format.getProperty("unknown"));
+        assertEquals("harmony", format.getProperty("name"));
+        assertEquals("apache", format.getProperty("organization"));
+        
+        try {
+            format = new MidiFileFormat(1, 2.0f, 3, 4, 5L, null);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+    }
+    
+    /**
+     * test method getByteLength()
+     * 
+     */
+    public void test_getByteLength() {
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, 4, 5L);
+        assertEquals(4, format.getByteLength());
+    }
+    
+    /**
+     * test method getType()
+     *
+     */
+    public void test_getType() {
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, 4, 5L);
+        assertEquals(1, format.getType());
+        
+        format = new MidiFileFormat(10, 2.0f, 3, 4, 5L);
+        assertEquals(10, format.getType());
+    }
+    
+    /**
+     * test method getMicrosecondLength()
+     *
+     */
+    public void test_getMicrosecondLength() {
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, 4, 5L);
+        assertEquals(5L, format.getMicrosecondLength());
+    }
+    
+    /**
+     * test method getProperty(String)
+     *
+     */
+    public void test_getProperty() {
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, 4, 5L);
+        assertNull(format.getProperty("name"));
+        
+        Map<String, Object> table = new Hashtable<String, Object>();
+        table.put("first", "one");
+        table.put("second", "two");
+        format = new MidiFileFormat(1, 2.0f, 3, 4, 5L, table);
+        assertNull(format.getProperty(null));
+        assertNull(format.getProperty("third"));
+        assertEquals("one", format.getProperty("first"));
+        assertEquals("two", format.getProperty("second"));
+        table.put("first", "not one");
+        table.put("second", "not two");
+        /*
+         * values don't change!!!
+         */
+        assertEquals("one", format.getProperty("first"));
+        assertEquals("two", format.getProperty("second"));
+    }
+    
+    /**
+     * test method properties()
+     *
+     */
+    public void test_properties() {
+        Map<String, Object> table = new Hashtable<String, Object>();
+        table.put("first", "one");
+        table.put("second", "two");
+        MidiFileFormat format = new MidiFileFormat(1, 2.0f, 3, 4, 5L, table);
+        
+        table = format.properties();
+        assertEquals("one", table.get("first"));
+        
+        try {
+            table.put("first", "not one");
+            fail("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException e) {}
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiFileFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native