KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > LogUtilsTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: LogUtilsTest.java,v 1.19 2006/10/30 21:14:47 bostic Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.nio.ByteBuffer JavaDoc;
12 import java.sql.Timestamp JavaDoc;
13 import java.util.Arrays JavaDoc;
14 import java.util.Calendar JavaDoc;
15
16 import junit.framework.TestCase;
17
18 /**
19  * Test basic marshalling utilities
20  */

21 public class LogUtilsTest extends TestCase {
22
23     public void testMarshalling() {
24         ByteBuffer JavaDoc dest = ByteBuffer.allocate(100);
25
26         // unsigned ints
27
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         // ints
40
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         // longs
53
long longData = -1021;
54         dest.clear();
55         LogUtils.writeLong(dest, longData);
56         dest.flip();
57         assertEquals(longData, LogUtils.readLong(dest));
58
59         // byte arrays
60
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         // Strings
67
String JavaDoc stringData = "Hello world!";
68         dest.clear();
69         LogUtils.writeString(dest, stringData);
70         dest.flip();
71         assertEquals(stringData, LogUtils.readString(dest));
72
73         // Timestamps
74
Timestamp JavaDoc timestampData =
75             new Timestamp JavaDoc(Calendar.getInstance().getTimeInMillis());
76         dest.clear();
77         LogUtils.writeTimestamp(dest, timestampData);
78         dest.flip();
79         assertEquals(timestampData, LogUtils.readTimestamp(dest));
80
81         // Booleans
82
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