modules/graphics/src/test/java/test/com/sun/javafx/iio/bmp/BMPImageLoaderTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.iio.bmp;
  27 
  28 import com.sun.javafx.iio.ImageFrame;
  29 import com.sun.javafx.iio.ImageLoader;
  30 import com.sun.javafx.iio.ImageLoaderFactory;
  31 import com.sun.javafx.iio.ImageTestHelper;
  32 import static com.sun.javafx.iio.bmp.BMPImageLoader.checkDisjointMasks;
  33 import static com.sun.javafx.iio.bmp.BMPImageLoader.isPow2Minus1;
  34 import com.sun.prism.Image;
  35 import java.awt.image.BufferedImage;
  36 import java.awt.image.DataBuffer;
  37 import java.awt.image.IndexColorModel;
  38 import java.io.ByteArrayInputStream;
  39 import java.io.IOException;
  40 import java.io.InputStream;
  41 import javax.imageio.ImageIO;
  42 import javax.imageio.stream.MemoryCacheImageInputStream;
  43 import static org.junit.Assert.*;
  44 import org.junit.Test;
  45 
  46 public class BMPImageLoaderTest {
  47     // if true, the test will write BMP files generated by JDK to the current directory
  48     static final boolean writeFiles = false;
  49     static final int testWidth = 509, testHeight = 157;
  50 
  51     int getByte(int dword, int shift) {
  52         return (dword >> shift) & 0xff;
  53     }


 204     }
 205 
 206     @Test
 207     public void test16Bit() throws IOException {
 208         testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit.bmp");
 209     }
 210 
 211     @Test
 212     public void test24Bit() throws IOException {
 213         testImageType(BufferedImage.TYPE_INT_RGB, "out24bit.bmp");
 214     }
 215 
 216     @Test
 217     public void testBitfields() throws IOException {
 218         testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit555.bmp", "BI_BITFIELDS");
 219         testImageType(BufferedImage.TYPE_USHORT_565_RGB, "out16bit565.bmp", "BI_BITFIELDS");
 220     }
 221 
 222     @Test
 223     public void testMasks() {
 224         assertTrue(checkDisjointMasks(1, 2, 4));
 225         assertTrue(checkDisjointMasks(0x00F, 0x0F0, 0xF00));
 226         assertFalse(checkDisjointMasks(1, 2, 5));
 227         assertFalse(checkDisjointMasks(2, 1, 6));
 228 
 229         assertTrue(isPow2Minus1(1));
 230         assertTrue(isPow2Minus1(3));
 231         assertTrue(isPow2Minus1(7));
 232         assertFalse(isPow2Minus1(2));
 233         assertFalse(isPow2Minus1(11));
 234     }
 235 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.com.sun.javafx.iio.bmp;
  27 
  28 import com.sun.javafx.iio.ImageFrame;
  29 import com.sun.javafx.iio.ImageLoader;
  30 import com.sun.javafx.iio.ImageLoaderFactory;
  31 import com.sun.javafx.iio.bmp.BMPImageLoaderFactory;
  32 import com.sun.javafx.iio.bmp.BMPImageLoaderShim;
  33 import test.com.sun.javafx.iio.ImageTestHelper;
  34 import com.sun.prism.Image;
  35 import java.awt.image.BufferedImage;
  36 import java.awt.image.DataBuffer;
  37 import java.awt.image.IndexColorModel;
  38 import java.io.ByteArrayInputStream;
  39 import java.io.IOException;
  40 import java.io.InputStream;
  41 import javax.imageio.ImageIO;
  42 import javax.imageio.stream.MemoryCacheImageInputStream;
  43 import static org.junit.Assert.*;
  44 import org.junit.Test;
  45 
  46 public class BMPImageLoaderTest {
  47     // if true, the test will write BMP files generated by JDK to the current directory
  48     static final boolean writeFiles = false;
  49     static final int testWidth = 509, testHeight = 157;
  50 
  51     int getByte(int dword, int shift) {
  52         return (dword >> shift) & 0xff;
  53     }


 204     }
 205 
 206     @Test
 207     public void test16Bit() throws IOException {
 208         testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit.bmp");
 209     }
 210 
 211     @Test
 212     public void test24Bit() throws IOException {
 213         testImageType(BufferedImage.TYPE_INT_RGB, "out24bit.bmp");
 214     }
 215 
 216     @Test
 217     public void testBitfields() throws IOException {
 218         testImageType(BufferedImage.TYPE_USHORT_555_RGB, "out16bit555.bmp", "BI_BITFIELDS");
 219         testImageType(BufferedImage.TYPE_USHORT_565_RGB, "out16bit565.bmp", "BI_BITFIELDS");
 220     }
 221 
 222     @Test
 223     public void testMasks() {
 224         assertTrue(BMPImageLoaderShim.checkDisjointMasks(1, 2, 4));
 225         assertTrue(BMPImageLoaderShim.checkDisjointMasks(0x00F, 0x0F0, 0xF00));
 226         assertFalse(BMPImageLoaderShim.checkDisjointMasks(1, 2, 5));
 227         assertFalse(BMPImageLoaderShim.checkDisjointMasks(2, 1, 6));
 228 
 229         assertTrue(BMPImageLoaderShim.isPow2Minus1(1));
 230         assertTrue(BMPImageLoaderShim.isPow2Minus1(3));
 231         assertTrue(BMPImageLoaderShim.isPow2Minus1(7));
 232         assertFalse(BMPImageLoaderShim.isPow2Minus1(2));
 233         assertFalse(BMPImageLoaderShim.isPow2Minus1(11));
 234     }
 235 }