⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ife_bitmaptest.java

📁 this is the frame work for iso8583
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2009 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. */package org.jpos.iso;import java.util.BitSet;import junit.framework.TestCase;/** * @author ay */public class IFE_BITMAPTest extends TestCase{    	IFE_BITMAP oneByte ;    IFE_BITMAP twoBytes ;    IFE_BITMAP threeBytes ;    IFE_BITMAP fourBytes ;    IFE_BITMAP eightBytes ;    IFE_BITMAP sixteenBytes ;    IFE_BITMAP thirtytwoBytes;    IFE_BITMAP fortyeightBytes;    byte[] DataWith2ndBitMapBitOn, DataWith2ndBitMapBitOff, thirtytwoByteBitMapIn48Bytes, sixteenByteBitMapIn48Bytes, testbytes, outBytes;    String in;        public void setUp() {    	oneByte = new IFE_BITMAP(1,"1 byte bitmap");        twoBytes = new IFE_BITMAP(2,"2 byte bitmap");        threeBytes = new IFE_BITMAP(3,"3 byte bitmap");        fourBytes = new IFE_BITMAP(4,"4 byte bitmap");        eightBytes = new IFE_BITMAP(8,"8 byte bitmap");        sixteenBytes = new IFE_BITMAP(16,"16 byte bitmap");        thirtytwoBytes = new IFE_BITMAP(32,"32 byte bitmap");        fortyeightBytes = new IFE_BITMAP(48,"48 byte bitmap");                DataWith2ndBitMapBitOn        = ISOUtil.asciiToEbcdic("8F81431FF12458F17F91421FF12418F18F81421FF12418F1".getBytes());        DataWith2ndBitMapBitOff       = ISOUtil.asciiToEbcdic("7F81431FF12458F17F91421FF12418F18F81421FF12418F1".getBytes());        thirtytwoByteBitMapIn48Bytes  = ISOUtil.asciiToEbcdic("8F81431FF12458F18F91421FF12418F18F81421FF12418F1".getBytes());        sixteenByteBitMapIn48Bytes    = ISOUtil.asciiToEbcdic("7F81431FF12458F17F91421FF12418F18F81421FF12418F1".getBytes());        in = ISOUtil.hexdump(DataWith2ndBitMapBitOn);            }    public void test01ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception    {        ISOComponent c = new ISOBitMap(1);        int consumed = oneByte.unpack(c, DataWith2ndBitMapBitOn,0);        assertEquals("1 bytes bitmap: unpack of 1 byte bitmap should consume 2 bytes in characters",2,consumed);        assertEquals("1 bytes bitmap: 1 byte bitmap should result in a bitmap holding fields up to 8",8,((BitSet)c.getValue()).length() - 1);        outBytes = oneByte.pack(c);        assertEquals("1 bytes bitmap: pack of 1 byte bitmap must produce a result 2 bytes long",2,outBytes.length);        assertEquals("1 bytes bitmap: pack of unpacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,2),ISOUtil.hexString(outBytes));    }    public void test02ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception    {        ISOComponent c = new ISOBitMap(1);        int consumed = twoBytes.unpack(c, DataWith2ndBitMapBitOn,0);        assertEquals("2 bytes bitmap: unpack of 2 bytew bitmap should consume 4 bytes in characters",4,consumed);        assertEquals("2 bytes bitmap: 2 bytes bitmap should result in a bitmap holding fields up to 16",16,((BitSet)c.getValue()).length() - 1);        outBytes = twoBytes.pack(c);        assertEquals("2 bytes bitmap: pack of 2 byte bitmap must produce a result 4 bytes long",4,outBytes.length);        assertEquals("2 bytes bitmap: pack of unpacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,4),ISOUtil.hexString(outBytes));                try {            outBytes = oneByte.pack(c);            fail("2 bytes bitmap: pack of 16 bits bitmap by 1 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 8 in the 1 bytes available.",e.getMessage());        }    }    public void test03ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception    {        ISOComponent c = new ISOBitMap(1);        int consumed = threeBytes.unpack(c, DataWith2ndBitMapBitOn,0);        assertEquals("3 bytes bitmap: unpack of 3 bytew bitmap should consume 6 bytes in characters",6,consumed);        assertEquals("3 bytes bitmap: 3 bytes bitmap should result in a bitmap holding fields up to 24",24,((BitSet)c.getValue()).length() - 1);        outBytes = threeBytes.pack(c);        assertEquals("3 bytes bitmap:pack of 3 byte bitmap must produce a result 6 bytes long",6,outBytes.length);        assertEquals("3 bytes bitmap: pack of unpacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,6),ISOUtil.hexString(outBytes));                try {            outBytes = oneByte.pack(c);            fail("3 bytes bitmap: pack of 24 bits bitmap by 1 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 8 in the 1 bytes available.",e.getMessage());        }                try {            outBytes = twoBytes.pack(c);            fail("3 bytes bitmap: pack of 24 bits bitmap by 2 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 16 in the 2 bytes available.",e.getMessage());        }                    }        public void test04ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception    {        ISOComponent c = new ISOBitMap(1);        int consumed = fourBytes.unpack(c, DataWith2ndBitMapBitOn,0);        assertEquals("4 bytes bitmap: unpack of 4 bytes bitmap should consume 8 bytes in characters",8,consumed);        assertEquals("4 bytes bitmap: 4 bytes bitmap should result in a bitmap holding fields up to 32",32,((BitSet)c.getValue()).length() - 1);        outBytes = fourBytes.pack(c);        assertEquals("4 bytes bitmap: pack of 4 byte bitmap must produce a result 8 bytes long",8,outBytes.length);        assertEquals("4 bytes bitmap: pack of unpacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,8),ISOUtil.hexString(outBytes));                try {            outBytes = oneByte.pack(c);            fail("4 bytes bitmap: pack of 32 bits bitmap by 1 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 8 in the 1 bytes available.",e.getMessage());        }                try {            outBytes = twoBytes.pack(c);            fail("4 bytes bitmap: pack of 32 bits bitmap by 2 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 16 in the 2 bytes available.",e.getMessage());        }                try {            outBytes = threeBytes.pack(c);            fail("4 bytes bitmap: pack of 32 bits bitmap by 3 bytes packager should result in ISOException");        } catch (Exception e) {            // expected.            assertEquals("Bitmap can only hold bits numbered up to 24 in the 3 bytes available.",e.getMessage());        }    }     public void test08ByteBitmapWithDataWith2ndBitMapBitOn() throws Exception    {        ISOComponent c = new ISOBitMap(1);        int consumed = eightBytes.unpack(c, DataWith2ndBitMapBitOn,0);        assertEquals("8 bytes bitmap: unpack of 8 bytes bitmap should consume 16 bytes in characters", 16, consumed);        assertEquals("8 bytes bitmap: 8 bytes bitmap should result in a bitmap holding fields up to 64", 64 ,((BitSet)c.getValue()).length() - 1);        outBytes = eightBytes.pack(c);        assertEquals("8 bytes bitmap: pack of 8 bytes bitmap must produce a result 16 bytes long",16,outBytes.length);        assertEquals("8 bytes bitmap: pack of upacked value should be the same as original", ISOUtil.hexString(DataWith2ndBitMapBitOn,0,16),ISOUtil.hexString(outBytes));        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -