diff options
author | Sven Gothel <[email protected]> | 2011-06-08 05:45:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-06-08 05:50:17 +0200 |
commit | a87c56c95099de5b6cbc9bd8bf6f1924a3dd6387 (patch) | |
tree | 0e5c81a4b3a2b136d50d827729dc727cd99d615c | |
parent | 5de9de569622bc7baeee3a85b1ee5aa172830513 (diff) |
Merged Locator -> IOUtil; int Platform.getPageSize(); Added unit test for IOUtil and Platform's page size
-rwxr-xr-x | make/scripts/runtest.sh | 4 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 18 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 264 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/Locator.java | 178 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/TestIOUtil01.java | 111 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/TestPlatform01.java | 70 |
6 files changed, 420 insertions, 225 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh index 0f69fd0..8ab4b1b 100755 --- a/make/scripts/runtest.sh +++ b/make/scripts/runtest.sh @@ -50,4 +50,6 @@ function onetest() { #onetest com.jogamp.gluegen.PCPPTest 2>&1 | tee -a $LOG #onetest com.jogamp.gluegen.test.TestPointerBufferEndian 2>&1 | tee -a $LOG #onetest com.jogamp.gluegen.test.TestStructAccessorEndian 2>&1 | tee -a $LOG -onetest com.jogamp.gluegen.test.junit.generation.Test1p1JavaEmitter 2>&1 | tee -a $LOG +#onetest com.jogamp.gluegen.test.junit.generation.Test1p1JavaEmitter 2>&1 | tee -a $LOG +#onetest com.jogamp.common.util.TestPlatform01 2>&1 | tee -a $LOG +onetest com.jogamp.common.util.TestIOUtil01 2>&1 | tee -a $LOG diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index e31e123..0775f37 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -57,7 +57,7 @@ public class Platform { private static final boolean is32Bit; private static final int pointerSizeInBits; - private static final long pageSize; + private static final int pageSize; static { @@ -84,7 +84,11 @@ public class Platform { if(libsLoaded) { pointerSizeInBits = getPointerSizeInBitsImpl(); - pageSize = getPageSizeImpl(); + final long pageSizeL = getPageSizeImpl(); + if(Integer.MAX_VALUE < pageSizeL) { + throw new InternalError("PageSize exceeds integer value: " + pageSizeL); + } + pageSize = (int) pageSizeL ; }else{ pointerSizeInBits = -1; pageSize = -1; @@ -253,8 +257,16 @@ public class Platform { return pointerSizeInBits/8; } - public static long getPageSize() { + public static int getPageSize() { return pageSize; } + + public static int getPageNumber(int size) { + return ( size + ( pageSize - 1) ) / pageSize ; // integer arithmetic + } + + public static int getPageAlignedSize(int size) { + return getPageNumber(size) * pageSize; + } } diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 42ac0e5..b2d9ed4 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -35,55 +35,23 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.JarURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.ByteBuffer; import com.jogamp.common.nio.Buffers; +import com.jogamp.common.os.Platform; public class IOUtil { private IOUtil() {} - /** - * Returns the lowercase suffix of the given file name (the text - * after the last '.' in the file name). Returns null if the file - * name has no suffix. Only operates on the given file name; - * performs no I/O operations. - * - * @param file name of the file - * @return lowercase suffix of the file name - * @throws NullPointerException if file is null - */ - - public static String getFileSuffix(File file) { - return getFileSuffix(file.getName()); - } - - /** - * Returns the lowercase suffix of the given file name (the text - * after the last '.' in the file name). Returns null if the file - * name has no suffix. Only operates on the given file name; - * performs no I/O operations. - * - * @param filename name of the file - * @return lowercase suffix of the file name - * @throws NullPointerException if filename is null + /*** + * + * STREAM COPY STUFF + * */ - public static String getFileSuffix(String filename) { - int lastDot = filename.lastIndexOf('.'); - if (lastDot < 0) { - return null; - } - return toLowerCase(filename.substring(lastDot + 1)); - } - - private static String toLowerCase(String arg) { - if (arg == null) { - return null; - } - - return arg.toLowerCase(); - } /** * Copy the specified input stream to the specified output file. The total @@ -113,9 +81,8 @@ public class IOUtil { * number of bytes written is returned. */ public static int copyStream2Stream(InputStream in, OutputStream out, int totalNumBytes) throws IOException { + final byte[] buf = new byte[Platform.getPageSize()]; int numBytes = 0; - final int BUFFER_SIZE = 1000; - byte[] buf = new byte[BUFFER_SIZE]; while (true) { int count; if ((count = in.read(buf)) == -1) { @@ -166,8 +133,219 @@ public class IOUtil { * <p>The implementation creates the ByteBuffer w/ {@link #copyStream2ByteArray(InputStream)}'s returned byte array.</p> */ public static ByteBuffer copyStream2ByteBuffer(InputStream stream) throws IOException { - final byte[] data = copyStream2ByteArray(stream); - return Buffers.newDirectByteBuffer(data, 0, data.length); + // FIXME: Shall enforce a BufferedInputStream ? + if( !(stream instanceof BufferedInputStream) ) { + stream = new BufferedInputStream(stream); + } + int totalRead = 0; + int avail = stream.available(); + ByteBuffer data = Buffers.newDirectByteBuffer( Platform.getPageAlignedSize(avail) ); + byte[] chunk = new byte[Platform.getPageSize()]; + int chunk2Read = Math.min(Platform.getPageSize(), avail); + int numRead = 0; + do { + if (avail > data.remaining()) { + final ByteBuffer newData = Buffers.newDirectByteBuffer( + Platform.getPageAlignedSize(data.position() + avail) ); + newData.put(data); + data = newData; + } + + numRead = stream.read(chunk, 0, chunk2Read); + if (numRead >= 0) { + data.put(chunk, 0, numRead); + totalRead += numRead; + } + avail = stream.available(); + chunk2Read = Math.min(Platform.getPageSize(), avail); + } while (avail > 0 && numRead >= 0); + + data.flip(); + return data; } + /*** + * + * RESOURCE / FILE NAME STUFF + * + */ + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param file name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if file is null + */ + + public static String getFileSuffix(File file) { + return getFileSuffix(file.getName()); + } + + /** + * Returns the lowercase suffix of the given file name (the text + * after the last '.' in the file name). Returns null if the file + * name has no suffix. Only operates on the given file name; + * performs no I/O operations. + * + * @param filename name of the file + * @return lowercase suffix of the file name + * @throws NullPointerException if filename is null + */ + public static String getFileSuffix(String filename) { + int lastDot = filename.lastIndexOf('.'); + if (lastDot < 0) { + return null; + } + return toLowerCase(filename.substring(lastDot + 1)); + } + + private static String toLowerCase(String arg) { + if (arg == null) { + return null; + } + + return arg.toLowerCase(); + } + + /*** + * + * RESOURCE LOCATION STUFF + * + */ + + /** + * Locating a resource using 'getResource(String path, ClassLoader cl)', + * with the given context's ClassLoader and the resourcePath as is, + * as well with the context's package name-path plus the resourcePath. + * + * @see #getResource(String, ClassLoader) + */ + public static URL getResource(Class context, String resourcePath) { + if(null == resourcePath) { + return null; + } + ClassLoader contextCL = (null!=context)?context.getClassLoader():null; + URL url = getResource(resourcePath, contextCL); + if (url == null && null!=context) { + // Try again by scoping the path within the class's package + String className = context.getName().replace('.', '/'); + int lastSlash = className.lastIndexOf('/'); + if (lastSlash >= 0) { + String tmpPath = className.substring(0, lastSlash + 1) + resourcePath; + url = getResource(tmpPath, contextCL); + } + } + return url; + } + + /** + * Locating a resource using the ClassLoader's facility if not null, + * the absolute URL and absolute file. + * + * @see ClassLoader#getResource(String) + * @see ClassLoader#getSystemResource(String) + * @see URL#URL(String) + * @see File#File(String) + */ + public static URL getResource(String resourcePath, ClassLoader cl) { + if(null == resourcePath) { + return null; + } + URL url = null; + if (cl != null) { + url = cl.getResource(resourcePath); + if(!urlExists(url)) { + url = null; + } + } + if(null == url) { + url = ClassLoader.getSystemResource(resourcePath); + if(!urlExists(url)) { + url = null; + } + } + if(null == url) { + try { + url = new URL(resourcePath); + if(!urlExists(url)) { + url = null; + } + } catch (MalformedURLException e) { } + } + if(null == url) { + try { + File file = new File(resourcePath); + if(file.exists()) { + url = file.toURL(); + } else { + } + } catch (MalformedURLException e) {} + } + return url; + } + + /** + * Generates a path for the 'relativeFile' relative to the 'baseLocation'. + * + * @param baseLocation denotes a directory + * @param relativeFile denotes a relative file to the baseLocation + */ + public static String getRelativeOf(File baseLocation, String relativeFile) { + if(null == relativeFile) { + return null; + } + + while (baseLocation != null && relativeFile.startsWith("../")) { + baseLocation = baseLocation.getParentFile(); + relativeFile = relativeFile.substring(3); + } + if (baseLocation != null) { + final File file = new File(baseLocation, relativeFile); + // Handle things on Windows + return file.getPath().replace('\\', '/'); + } + return null; + } + + /** + * Generates a path for the 'relativeFile' relative to the 'baseLocation'. + * + * @param baseLocation denotes a URL to a file + * @param relativeFile denotes a relative file to the baseLocation's parent directory + */ + public static String getRelativeOf(URL baseLocation, String relativeFile) { + String urlPath = baseLocation.getPath(); + + if ( baseLocation.toString().startsWith("jar") ) { + JarURLConnection jarConnection; + try { + jarConnection = (JarURLConnection) baseLocation.openConnection(); + urlPath = jarConnection.getEntryName(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + // Try relative path first + return getRelativeOf(new File(urlPath).getParentFile(), relativeFile); + } + + /** + * Returns true, if the URL exists and a connection could be opened. + */ + public static boolean urlExists(URL url) { + boolean v = false; + if(null!=url) { + try { + URLConnection uc = url.openConnection(); + v = true; + } catch (IOException ioe) { } + } + return v; + } } diff --git a/src/java/com/jogamp/common/util/Locator.java b/src/java/com/jogamp/common/util/Locator.java deleted file mode 100644 index 8ecdc0e..0000000 --- a/src/java/com/jogamp/common/util/Locator.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.jogamp.common.util; - -import java.io.*; -import java.net.*; - -/** Utilities for dealing with resources. */ - -public class Locator { - private Locator() {} - - /** - * Locating a resource using 'getResource(String path, ClassLoader cl)', - * with the given context's ClassLoader and the resourcePath as is, - * as well with the context's package name-path plus the resourcePath. - * - * @see #getResource(String, ClassLoader) - */ - public static URL getResource(Class context, String resourcePath) { - if(null == resourcePath) { - return null; - } - ClassLoader contextCL = (null!=context)?context.getClassLoader():null; - URL url = getResource(resourcePath, contextCL); - if (url == null && null!=context) { - // Try again by scoping the path within the class's package - String className = context.getName().replace('.', '/'); - int lastSlash = className.lastIndexOf('/'); - if (lastSlash >= 0) { - String tmpPath = className.substring(0, lastSlash + 1) + resourcePath; - url = getResource(tmpPath, contextCL); - } - } - return url; - } - - /** - * Locating a resource using the ClassLoader's facility if not null, - * the absolute URL and absolute file. - * - * @see ClassLoader#getResource(String) - * @see ClassLoader#getSystemResource(String) - * @see URL#URL(String) - * @see File#File(String) - */ - public static URL getResource(String resourcePath, ClassLoader cl) { - if(null == resourcePath) { - return null; - } - URL url = null; - if (cl != null) { - url = cl.getResource(resourcePath); - if(!urlExists(url)) { - url = null; - } - } - if(null == url) { - url = ClassLoader.getSystemResource(resourcePath); - if(!urlExists(url)) { - url = null; - } - } - if(null == url) { - try { - url = new URL(resourcePath); - if(!urlExists(url)) { - url = null; - } - } catch (MalformedURLException e) { } - } - if(null == url) { - try { - File file = new File(resourcePath); - if(file.exists()) { - url = file.toURL(); - } else { - } - } catch (MalformedURLException e) {} - } - return url; - } - - /** - * Generates a path for the 'relativeFile' relative to the 'baseLocation'. - * - * @param baseLocation denotes a directory - * @param relativeFile denotes a relative file to the baseLocation - */ - public static String getRelativeOf(File baseLocation, String relativeFile) { - if(null == relativeFile) { - return null; - } - - while (baseLocation != null && relativeFile.startsWith("../")) { - baseLocation = baseLocation.getParentFile(); - relativeFile = relativeFile.substring(3); - } - if (baseLocation != null) { - final File file = new File(baseLocation, relativeFile); - // Handle things on Windows - return file.getPath().replace('\\', '/'); - } - return null; - } - - /** - * Generates a path for the 'relativeFile' relative to the 'baseLocation'. - * - * @param baseLocation denotes a URL to a file - * @param relativeFile denotes a relative file to the baseLocation's parent directory - */ - public static String getRelativeOf(URL baseLocation, String relativeFile) { - String urlPath = baseLocation.getPath(); - - if ( baseLocation.toString().startsWith("jar") ) { - JarURLConnection jarConnection; - try { - jarConnection = (JarURLConnection) baseLocation.openConnection(); - urlPath = jarConnection.getEntryName(); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - // Try relative path first - return getRelativeOf(new File(urlPath).getParentFile(), relativeFile); - } - - /** - * Returns true, if the url exists, - * trying to open a connection. - */ - public static boolean urlExists(URL url) { - boolean v = false; - if(null!=url) { - try { - URLConnection uc = url.openConnection(); - v = true; - } catch (IOException ioe) { } - } - return v; - } - -} - diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java new file mode 100644 index 0000000..ad95213 --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java @@ -0,0 +1,111 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.common.util; + +import java.util.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URL; +import java.nio.ByteBuffer; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +import com.jogamp.common.os.Platform; + +public class TestIOUtil01 { + + static final int tsz = Platform.getPageSize() + Platform.getPageSize() / 2 ; + static final byte[] orig = new byte[tsz]; + static final String tfilename = "./test.bin" ; + + @BeforeClass + public static void setup() throws IOException { + final File tfile = new File(tfilename); + final OutputStream tout = new BufferedOutputStream(new FileOutputStream(tfile)); + for(int i=0; i<tsz; i++) { + final byte b = (byte) (i%256); + orig[i] = b; + tout.write(b); + } + tout.close(); + } + + @Test + public void testCopyStream01Array() throws IOException { + URL url = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(url); + final byte[] bb = IOUtil.copyStream2ByteArray( new BufferedInputStream( url.openStream() ) ); + Assert.assertEquals("Byte number not equal orig vs array", orig.length, bb.length); + Assert.assertTrue("Bytes not equal orig vs array", Arrays.equals(orig, bb)); + + } + + @Test + public void testCopyStream02Buffer() throws IOException { + URL url = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(url); + final ByteBuffer bb = IOUtil.copyStream2ByteBuffer( new BufferedInputStream( url.openStream() ) ); + Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit()); + int i; + for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ; + Assert.assertTrue("Bytes not equal orig vs array", 0>i); + } + + @Test + public void testCopyStream03Buffer() throws IOException { + final String tfilename2 = "./test2.bin" ; + URL url1 = IOUtil.getResource(this.getClass(), tfilename); + Assert.assertNotNull(url1); + + File file2 = new File(tfilename2); + IOUtil.copyURL2File(url1, file2); + URL url2 = IOUtil.getResource(this.getClass(), tfilename2); + Assert.assertNotNull(url2); + + final ByteBuffer bb = IOUtil.copyStream2ByteBuffer( new BufferedInputStream( url2.openStream() ) ); + Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit()); + int i; + for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ; + Assert.assertTrue("Bytes not equal orig vs array", 0>i); + } + + public static void main(String args[]) throws IOException { + String tstname = TestIOUtil01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/junit/com/jogamp/common/util/TestPlatform01.java b/src/junit/com/jogamp/common/util/TestPlatform01.java new file mode 100644 index 0000000..544418a --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestPlatform01.java @@ -0,0 +1,70 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.common.util; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.os.Platform; + +public class TestPlatform01 { + + @Test + public void testPageSize01() { + final int ps = Platform.getPageSize(); + System.err.println("PageSize: "+ps); + Assert.assertTrue("PageSize is 0", 0 < ps ); + + final int ps_pages = Platform.getPageNumber(ps); + Assert.assertTrue("PageNumber of PageSize is not 1, but "+ps_pages, 1 == ps_pages); + + final int sz0 = ps - 10; + final int sz0_pages = Platform.getPageNumber(sz0); + Assert.assertTrue("PageNumber of PageSize-10 is not 1, but "+sz0_pages, 1 == sz0_pages); + + final int sz1 = ps + 10; + final int sz1_pages = Platform.getPageNumber(sz1); + Assert.assertTrue("PageNumber of PageSize+10 is not 2, but "+sz1_pages, 2 == sz1_pages); + + final int ps_psa = Platform.getPageAlignedSize(ps); + Assert.assertTrue("PageAlignedSize of PageSize is not PageSize, but "+ps_psa, ps == ps_psa); + + final int sz0_psa = Platform.getPageAlignedSize(sz0); + Assert.assertTrue("PageAlignedSize of PageSize-10 is not PageSize, but "+sz0_psa, ps == sz0_psa); + + final int sz1_psa = Platform.getPageAlignedSize(sz1); + Assert.assertTrue("PageAlignedSize of PageSize+10 is not 2*PageSize, but "+sz1_psa, ps*2 == sz1_psa); + } + + public static void main(String args[]) { + String tstname = TestPlatform01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} |