You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2007/01/29 17:05:07 UTC

svn commit: r501086 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/org/apache/harmony/awt/nativebridge/ test/api/java/common/org/apache/harmony/awt/tests/nativebridge/

Author: ayza
Date: Mon Jan 29 08:05:06 2007
New Revision: 501086

URL: http://svn.apache.org/viewvc?view=rev&rev=501086
Log:
Fix and unit test for org.apache.harmony.awt.nativebridge.PointerPointer class. Taken from HARMONY-2547 ([classlib][awt] PointerPointer's methods set/get, set/getAddress don't use pointer size)

Added:
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/nativebridge/PointerPointer.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/nativebridge/PointerPointer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/nativebridge/PointerPointer.java?view=diff&rev=501086&r1=501085&r2=501086
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/nativebridge/PointerPointer.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/nativebridge/PointerPointer.java Mon Jan 29 08:05:06 2007
@@ -14,10 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Sergey V. Kuksenko
- * @version $Revision$
- */
 package org.apache.harmony.awt.nativebridge;
 
 public class PointerPointer extends VoidPointer {
@@ -36,7 +32,7 @@
      * Creates Pointer based on native pointer to pointer
      */
     PointerPointer(long ptrPtr) {
-    super(ptrPtr);
+        super(ptrPtr);
     }
     
     /**
@@ -60,24 +56,24 @@
 
     /** returns the element at the specified position. */
     public VoidPointer get(int index) {
-        long addr = byteBase.getAddress(index);
+        long addr = byteBase.getAddress(index * PP_SIZE_FACTOR);
         return (addr != 0) ? new Int8Pointer(addr) : null;
     }
 
     /** returns the element at the specified position. */
     public long getAddress(int index) {
-        return byteBase.getAddress(index);
+        return byteBase.getAddress(index * PP_SIZE_FACTOR);
     }
 
     /** sets the element at the specified position. */
     public void set(int index, VoidPointer value) {
-        byteBase.setAddress(index, value.lock());
+        byteBase.setAddress(index * PP_SIZE_FACTOR, value.lock());
         value.release();
     }
 
     /** sets the element at the specified position. */
     public void setAddress(int index, long value) {
-        byteBase.setAddress(index, value);
+        byteBase.setAddress(index * PP_SIZE_FACTOR, value);
     }
 
     /**

Added: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java?view=auto&rev=501086
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java Mon Jan 29 08:05:06 2007
@@ -0,0 +1,73 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.awt.tests.nativebridge;
+
+import junit.framework.TestCase;
+import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.PointerPointer;
+import org.apache.harmony.awt.nativebridge.ByteBase;
+
+public class PointerPointerTest extends TestCase {
+    private PointerPointer p;
+    private PointerPointer p1;
+
+    
+    // Regression tests for HARMONY-2547    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        p = NativeBridge.getInstance().createPointerPointer(2, false);
+        p.setAddress(1, 0xFFFFFFFFL);
+        p1 = NativeBridge.getInstance().createPointerPointer(2, false);
+        p1.setAddress(0, 0xFFFFFFFFL);
+    }
+
+    public void test_get() {
+        assertNull("*p != 0", p.get(0));
+        assertNull("*(p+1) != 0", p1.get(1));
+    }
+
+    public void test_getAddress() {
+        assertEquals("*p != 0", 0, p.getAddress(0));
+        assertEquals("*(p+1) != 0", 0, p1.getAddress(1));
+    }
+
+    public void test_set() {
+        byte dst[] = new byte[8];
+
+        p.set(1, NativeBridge.getInstance().createInt32Pointer(0x04030201L));
+        p.byteBase.get(dst, 0, ByteBase.POINTER_SIZE*2);	
+
+        for(int i = ByteBase.POINTER_SIZE; i < ByteBase.POINTER_SIZE + 4; i++) {
+            assertEquals(i - ByteBase.POINTER_SIZE + 1, dst[i]);
+        }
+    }
+
+    public void test_setAddress() {
+        byte dst[] = new byte[8];
+
+        p.setAddress(1, 0x04030201L);
+        p.byteBase.get(dst, 0, ByteBase.POINTER_SIZE*2);
+
+        for(int i = ByteBase.POINTER_SIZE; i < ByteBase.POINTER_SIZE + 4; i++) {
+            assertEquals(i - ByteBase.POINTER_SIZE + 1, dst[i]);
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/org/apache/harmony/awt/tests/nativebridge/PointerPointerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native