1 8 9 package com.sleepycat.je.log; 10 11 import java.nio.ByteBuffer ; 12 import java.sql.Timestamp ; 13 import java.util.Arrays ; 14 import java.util.Calendar ; 15 16 import junit.framework.TestCase; 17 18 21 public class LogUtilsTest extends TestCase { 22 23 public void testMarshalling() { 24 ByteBuffer dest = ByteBuffer.allocate(100); 25 26 long unsignedData = 10; 28 dest.clear(); 29 LogUtils.writeUnsignedInt(dest, unsignedData); 30 dest.flip(); 31 assertEquals(unsignedData, LogUtils.getUnsignedInt(dest)); 32 33 unsignedData = 49249249L; 34 dest.clear(); 35 LogUtils.writeUnsignedInt(dest, unsignedData); 36 dest.flip(); 37 assertEquals(unsignedData, LogUtils.getUnsignedInt(dest)); 38 39 int intData = -1021; 41 dest.clear(); 42 LogUtils.writeInt(dest, intData); 43 dest.flip(); 44 assertEquals(intData, LogUtils.readInt(dest)); 45 46 intData = 257; 47 dest.clear(); 48 LogUtils.writeInt(dest, intData); 49 dest.flip(); 50 assertEquals(intData, LogUtils.readInt(dest)); 51 52 long longData = -1021; 54 dest.clear(); 55 LogUtils.writeLong(dest, longData); 56 dest.flip(); 57 assertEquals(longData, LogUtils.readLong(dest)); 58 59 byte [] byteData = new byte [] {1,2,3,4,5,6,7,8,9,10,11,12}; 61 dest.clear(); 62 LogUtils.writeByteArray(dest, byteData); 63 dest.flip(); 64 assertTrue(Arrays.equals(byteData, LogUtils.readByteArray(dest))); 65 66 String stringData = "Hello world!"; 68 dest.clear(); 69 LogUtils.writeString(dest, stringData); 70 dest.flip(); 71 assertEquals(stringData, LogUtils.readString(dest)); 72 73 Timestamp timestampData = 75 new Timestamp (Calendar.getInstance().getTimeInMillis()); 76 dest.clear(); 77 LogUtils.writeTimestamp(dest, timestampData); 78 dest.flip(); 79 assertEquals(timestampData, LogUtils.readTimestamp(dest)); 80 81 boolean boolData = true; 83 dest.clear(); 84 LogUtils.writeBoolean(dest, boolData); 85 dest.flip(); 86 assertEquals(boolData, LogUtils.readBoolean(dest)); 87 } 88 } 89 | Popular Tags |