You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/01 08:55:24 UTC

svn commit: r809856 - /commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java

Author: mturk
Date: Tue Sep  1 06:55:23 2009
New Revision: 809856

URL: http://svn.apache.org/viewvc?rev=809856&view=rev
Log:
Test offset alignment

Modified:
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java?rev=809856&r1=809855&r2=809856&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java Tue Sep  1 06:55:23 2009
@@ -16,8 +16,9 @@
 
 package org.apache.commons.runtime;
 
-import java.lang.System;
 import junit.framework.*;
+import java.lang.System;
+import java.io.IOException;
 import java.util.EnumSet;
 import org.apache.commons.runtime.io.*;
 import org.apache.commons.runtime.exception.*;
@@ -53,5 +54,47 @@
         map.close();
     }
 
-}
+    public void testTestMemoryMapAlignment()
+        throws Throwable
+    {
+        File f = new File("org/apache/commons/runtime/TestMemoryMap.class");
+        MemoryMapProvider map = new MemoryMapProvider(f, EnumSet.of(FileOpenMode.READ));
+        Pointer p1 = map.map(0, 128);
+        Pointer p2 = map.map(0, 128);
+        Pointer pa = null;
+        System.out.println();
+        try {
+            pa = map.map(4, 128);
+            System.out.println("Map doesn't require offset alignment");
+        } catch (IOException e) {
+        }
+        if (pa == null) {
+            try {
+                pa = map.map(1024, 128);
+                System.out.println("Map requires 1k offset alignment");
+            } catch (IOException e) {
+            }
+        }
+        if (pa == null) {
+            try {
+                pa = map.map(4096, 128);
+                System.out.println("Map requires 4k offset alignment");
+            } catch (IOException e) {
+            }
+        }
+        if (pa == null) {
+            try {
+                pa = map.map(65536, 128);
+                System.out.println("Map requires 64k offset alignment");
+            } catch (IOException e) {
+            }
+        }
+        assertFalse("Unknown offset alignment", pa == null);
+        assertEquals("Class header [0]", (byte)0xCA, (byte)p1.peek(0));
+        assertEquals("Class header [1]", (byte)0xFE, (byte)p2.peek(1));
+        assertEquals("Class header [2]", (byte)0xBA, (byte)p1.peek(2));
+        assertEquals("Class header [3]", (byte)0xBE, (byte)p2.peek(3));
+        map.close();
+    }
 
+}