Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

TupleFormatTest.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: TupleFormatTest.java,v 12.2 2005/08/01 20:25:26 mark Exp $
00008  */
00009 
00010 package com.sleepycat.bind.tuple.test;
00011 
00012 import java.util.Arrays;
00013 
00014 import junit.framework.Test;
00015 import junit.framework.TestCase;
00016 import junit.framework.TestSuite;
00017 
00018 import com.sleepycat.bind.tuple.TupleBinding;
00019 import com.sleepycat.bind.tuple.TupleInput;
00020 import com.sleepycat.bind.tuple.TupleOutput;
00021 import com.sleepycat.collections.test.DbTestUtil;
00022 import com.sleepycat.db.DatabaseEntry;
00023 
00027 public class TupleFormatTest extends TestCase {
00028 
00029     private TupleInput in;
00030     private TupleOutput out;
00031     private DatabaseEntry buffer;
00032 
00033     public static void main(String[] args)
00034         throws Exception {
00035 
00036         junit.framework.TestResult tr =
00037             junit.textui.TestRunner.run(suite());
00038         if (tr.errorCount() > 0 ||
00039             tr.failureCount() > 0) {
00040             System.exit(1);
00041         } else {
00042             System.exit(0);
00043         }
00044     }
00045 
00046     public static Test suite()
00047         throws Exception {
00048 
00049         TestSuite suite = new TestSuite(TupleFormatTest.class);
00050         return suite;
00051     }
00052 
00053     public TupleFormatTest(String name) {
00054 
00055         super(name);
00056     }
00057 
00058     public void setUp() {
00059 
00060         DbTestUtil.printTestName("TupleFormatTest." + getName());
00061         buffer = new DatabaseEntry();
00062         out = new TupleOutput();
00063     }
00064 
00065     public void tearDown() {
00066 
00067         /* Ensure that GC can cleanup. */
00068         in = null;
00069         out = null;
00070         buffer = null;
00071     }
00072 
00073     private void copyOutputToInput() {
00074 
00075         TupleBinding.outputToEntry(out, buffer);
00076         assertEquals(out.size(), buffer.getSize());
00077         in = TupleBinding.entryToInput(buffer);
00078         assertEquals(in.available(), buffer.getSize());
00079         assertEquals(in.getBufferLength(), buffer.getSize());
00080     }
00081 
00082     private void stringTest(String val) {
00083 
00084         out.reset();
00085         out.writeString(val);
00086         assertEquals(val.length() + 1, out.size()); // assume 1-byte chars
00087         copyOutputToInput();
00088         assertEquals(val, in.readString());
00089         assertEquals(0, in.available());
00090     }
00091 
00092     public void testString() {
00093 
00094         stringTest("");
00095         stringTest("a");
00096         stringTest("abc");
00097 
00098         out.reset();
00099         out.writeString("abc");
00100         out.writeString("defg");
00101         assertEquals(9, out.size());
00102         copyOutputToInput();
00103         assertEquals("abc", in.readString());
00104         assertEquals("defg", in.readString());
00105         assertEquals(0, in.available());
00106 
00107         out.reset();
00108         out.writeString("abc");
00109         out.writeString("defg");
00110         out.writeString("hijkl");
00111         assertEquals(15, out.size());
00112         copyOutputToInput();
00113         assertEquals("abc", in.readString());
00114         assertEquals("defg", in.readString());
00115         assertEquals("hijkl", in.readString());
00116         assertEquals(0, in.available());
00117     }
00118 
00119     private void fixedStringTest(char[] val) {
00120 
00121         out.reset();
00122         out.writeString(val);
00123         assertEquals(val.length, out.size()); // assume 1 byte chars
00124         copyOutputToInput();
00125         char[] val2 = new char[val.length];
00126         in.readString(val2);
00127         assertTrue(Arrays.equals(val, val2));
00128         assertEquals(0, in.available());
00129         in.reset();
00130         String val3 = in.readString(val.length);
00131         assertTrue(Arrays.equals(val, val3.toCharArray()));
00132         assertEquals(0, in.available());
00133     }
00134 
00135     public void testFixedString() {
00136 
00137         fixedStringTest(new char[0]);
00138         fixedStringTest(new char[] {'a'});
00139         fixedStringTest(new char[] {'a', 'b', 'c'});
00140 
00141         out.reset();
00142         out.writeString(new char[] {'a', 'b', 'c'});
00143         out.writeString(new char[] {'d', 'e', 'f', 'g'});
00144         assertEquals(7, out.size());
00145         copyOutputToInput();
00146         assertEquals("abc", in.readString(3));
00147         assertEquals("defg", in.readString(4));
00148         assertEquals(0, in.available());
00149 
00150         out.reset();
00151         out.writeString(new char[] {'a', 'b', 'c'});
00152         out.writeString(new char[] {'d', 'e', 'f', 'g'});
00153         out.writeString(new char[] {'h', 'i', 'j', 'k', 'l'});
00154         assertEquals(12, out.size());
00155         copyOutputToInput();
00156         assertEquals("abc", in.readString(3));
00157         assertEquals("defg", in.readString(4));
00158         assertEquals("hijkl", in.readString(5));
00159         assertEquals(0, in.available());
00160     }
00161 
00162     public void testNullString() {
00163 
00164         out.reset();
00165         out.writeString((String) null);
00166         assertEquals(2, out.size());
00167         copyOutputToInput();
00168         assertEquals(null, in.readString());
00169         assertEquals(0, in.available());
00170 
00171         out.reset();
00172         out.writeString((String) null);
00173         out.writeString("x");
00174         assertEquals(4, out.size());
00175         copyOutputToInput();
00176         assertEquals(null, in.readString());
00177         assertEquals(2, in.available());
00178         assertEquals("x", in.readString());
00179         assertEquals(0, in.available());
00180 
00181         out.reset();
00182         out.writeString("x");
00183         out.writeString((String) null);
00184         assertEquals(4, out.size());
00185         copyOutputToInput();
00186         assertEquals("x", in.readString());
00187         assertEquals(2, in.available());
00188         assertEquals(null, in.readString());
00189         assertEquals(0, in.available());
00190 
00191         out.reset();
00192         out.writeString((String) null);
00193         out.writeInt(123);
00194         assertEquals(6, out.size());
00195         copyOutputToInput();
00196         assertEquals(null, in.readString());
00197         assertEquals(4, in.available());
00198         assertEquals(123, in.readInt());
00199         assertEquals(0, in.available());
00200 
00201         out.reset();
00202         out.writeInt(123);
00203         out.writeString((String) null);
00204         assertEquals(6, out.size());
00205         copyOutputToInput();
00206         assertEquals(123, in.readInt());
00207         assertEquals(2, in.available());
00208         assertEquals(null, in.readString());
00209         assertEquals(0, in.available());
00210     }
00211 
00212     private void charsTest(char[] val) {
00213 
00214         for (int mode = 0; mode < 2; mode += 1) {
00215             out.reset();
00216             switch (mode) {
00217                 case 0: out.writeChars(val); break;
00218                 case 1: out.writeChars(new String(val)); break;
00219                 default: throw new IllegalStateException();
00220             }
00221             assertEquals(val.length * 2, out.size());
00222             copyOutputToInput();
00223             char[] val2 = new char[val.length];
00224             in.readChars(val2);
00225             assertTrue(Arrays.equals(val, val2));
00226             assertEquals(0, in.available());
00227             in.reset();
00228             String val3 = in.readChars(val.length);
00229             assertTrue(Arrays.equals(val, val3.toCharArray()));
00230             assertEquals(0, in.available());
00231         }
00232     }
00233 
00234     public void testChars() {
00235 
00236         charsTest(new char[0]);
00237         charsTest(new char[] {'a'});
00238         charsTest(new char[] {'a', 'b', 'c'});
00239 
00240         out.reset();
00241         out.writeChars("abc");
00242         out.writeChars("defg");
00243         assertEquals(7 * 2, out.size());
00244         copyOutputToInput();
00245         assertEquals("abc", in.readChars(3));
00246         assertEquals("defg", in.readChars(4));
00247         assertEquals(0, in.available());
00248 
00249         out.reset();
00250         out.writeChars("abc");
00251         out.writeChars("defg");
00252         out.writeChars("hijkl");
00253         assertEquals(12 * 2, out.size());
00254         copyOutputToInput();
00255         assertEquals("abc", in.readChars(3));
00256         assertEquals("defg", in.readChars(4));
00257         assertEquals("hijkl", in.readChars(5));
00258         assertEquals(0, in.available());
00259     }
00260 
00261     private void bytesTest(char[] val) {
00262 
00263         char[] valBytes = new char[val.length];
00264         for (int i = 0; i < val.length; i += 1)
00265             valBytes[i] = (char) (val[i] & 0xFF);
00266 
00267         for (int mode = 0; mode < 2; mode += 1) {
00268             out.reset();
00269             switch (mode) {
00270                 case 0: out.writeBytes(val); break;
00271                 case 1: out.writeBytes(new String(val)); break;
00272                 default: throw new IllegalStateException();
00273             }
00274             assertEquals(val.length, out.size());
00275             copyOutputToInput();
00276             char[] val2 = new char[val.length];
00277             in.readBytes(val2);
00278             assertTrue(Arrays.equals(valBytes, val2));
00279             assertEquals(0, in.available());
00280             in.reset();
00281             String val3 = in.readBytes(val.length);
00282             assertTrue(Arrays.equals(valBytes, val3.toCharArray()));
00283             assertEquals(0, in.available());
00284         }
00285     }
00286 
00287     public void testBytes() {
00288 
00289         bytesTest(new char[0]);
00290         bytesTest(new char[] {'a'});
00291         bytesTest(new char[] {'a', 'b', 'c'});
00292         bytesTest(new char[] {0x7F00, 0x7FFF, 0xFF00, 0xFFFF});
00293 
00294         out.reset();
00295         out.writeBytes("abc");
00296         out.writeBytes("defg");
00297         assertEquals(7, out.size());
00298         copyOutputToInput();
00299         assertEquals("abc", in.readBytes(3));
00300         assertEquals("defg", in.readBytes(4));
00301         assertEquals(0, in.available());
00302 
00303         out.reset();
00304         out.writeBytes("abc");
00305         out.writeBytes("defg");
00306         out.writeBytes("hijkl");
00307         assertEquals(12, out.size());
00308         copyOutputToInput();
00309         assertEquals("abc", in.readBytes(3));
00310         assertEquals("defg", in.readBytes(4));
00311         assertEquals("hijkl", in.readBytes(5));
00312         assertEquals(0, in.available());
00313     }
00314 
00315     private void booleanTest(boolean val) {
00316 
00317         out.reset();
00318         out.writeBoolean(val);
00319         assertEquals(1, out.size());
00320         copyOutputToInput();
00321         assertEquals(val, in.readBoolean());
00322         assertEquals(0, in.available());
00323     }
00324 
00325     public void testBoolean() {
00326 
00327         booleanTest(true);
00328         booleanTest(false);
00329 
00330         out.reset();
00331         out.writeBoolean(true);
00332         out.writeBoolean(false);
00333         assertEquals(2, out.size());
00334         copyOutputToInput();
00335         assertEquals(true, in.readBoolean());
00336         assertEquals(false, in.readBoolean());
00337         assertEquals(0, in.available());
00338 
00339         out.reset();
00340         out.writeBoolean(true);
00341         out.writeBoolean(false);
00342         out.writeBoolean(true);
00343         assertEquals(3, out.size());
00344         copyOutputToInput();
00345         assertEquals(true, in.readBoolean());
00346         assertEquals(false, in.readBoolean());
00347         assertEquals(true, in.readBoolean());
00348         assertEquals(0, in.available());
00349     }
00350 
00351     private void unsignedByteTest(int val) {
00352 
00353         unsignedByteTest(val, val);
00354     }
00355 
00356     private void unsignedByteTest(int val, int expected) {
00357 
00358         out.reset();
00359         out.writeUnsignedByte(val);
00360         assertEquals(1, out.size());
00361         copyOutputToInput();
00362         assertEquals(expected, in.readUnsignedByte());
00363     }
00364 
00365     public void testUnsignedByte() {
00366 
00367         unsignedByteTest(0);
00368         unsignedByteTest(1);
00369         unsignedByteTest(254);
00370         unsignedByteTest(255);
00371         unsignedByteTest(256, 0);
00372         unsignedByteTest(-1, 255);
00373         unsignedByteTest(-2, 254);
00374         unsignedByteTest(-255, 1);
00375 
00376         out.reset();
00377         out.writeUnsignedByte(0);
00378         out.writeUnsignedByte(1);
00379         out.writeUnsignedByte(255);
00380         assertEquals(3, out.size());
00381         copyOutputToInput();
00382         assertEquals(0, in.readUnsignedByte());
00383         assertEquals(1, in.readUnsignedByte());
00384         assertEquals(255, in.readUnsignedByte());
00385         assertEquals(0, in.available());
00386     }
00387 
00388     private void unsignedShortTest(int val) {
00389 
00390         unsignedShortTest(val, val);
00391     }
00392 
00393     private void unsignedShortTest(int val, int expected) {
00394 
00395         out.reset();
00396         out.writeUnsignedShort(val);
00397         assertEquals(2, out.size());
00398         copyOutputToInput();
00399         assertEquals(expected, in.readUnsignedShort());
00400     }
00401 
00402     public void testUnsignedShort() {
00403 
00404         unsignedShortTest(0);
00405         unsignedShortTest(1);
00406         unsignedShortTest(255);
00407         unsignedShortTest(256);
00408         unsignedShortTest(257);
00409         unsignedShortTest(Short.MAX_VALUE - 1);
00410         unsignedShortTest(Short.MAX_VALUE);
00411         unsignedShortTest(Short.MAX_VALUE + 1);
00412         unsignedShortTest(0xFFFF - 1);
00413         unsignedShortTest(0xFFFF);
00414         unsignedShortTest(0xFFFF + 1, 0);
00415         unsignedShortTest(0x7FFF0000, 0);
00416         unsignedShortTest(0xFFFF0000, 0);
00417         unsignedShortTest(-1, 0xFFFF);
00418         unsignedShortTest(-2, 0xFFFF - 1);
00419         unsignedShortTest(-0xFFFF, 1);
00420 
00421         out.reset();
00422         out.writeUnsignedShort(0);
00423         out.writeUnsignedShort(1);
00424         out.writeUnsignedShort(0xFFFF);
00425         assertEquals(6, out.size());
00426         copyOutputToInput();
00427         assertEquals(0, in.readUnsignedShort());
00428         assertEquals(1, in.readUnsignedShort());
00429         assertEquals(0xFFFF, in.readUnsignedShort());
00430         assertEquals(0, in.available());
00431     }
00432 
00433     private void unsignedIntTest(long val) {
00434 
00435         unsignedIntTest(val, val);
00436     }
00437 
00438     private void unsignedIntTest(long val, long expected) {
00439 
00440         out.reset();
00441         out.writeUnsignedInt(val);
00442         assertEquals(4, out.size());
00443         copyOutputToInput();
00444         assertEquals(expected, in.readUnsignedInt());
00445     }
00446 
00447     public void testUnsignedInt() {
00448 
00449         unsignedIntTest(0L);
00450         unsignedIntTest(1L);
00451         unsignedIntTest(255L);
00452         unsignedIntTest(256L);
00453         unsignedIntTest(257L);
00454         unsignedIntTest(Short.MAX_VALUE - 1L);
00455         unsignedIntTest(Short.MAX_VALUE);
00456         unsignedIntTest(Short.MAX_VALUE + 1L);
00457         unsignedIntTest(Integer.MAX_VALUE - 1L);
00458         unsignedIntTest(Integer.MAX_VALUE);
00459         unsignedIntTest(Integer.MAX_VALUE + 1L);
00460         unsignedIntTest(0xFFFFFFFFL - 1L);
00461         unsignedIntTest(0xFFFFFFFFL);
00462         unsignedIntTest(0xFFFFFFFFL + 1L, 0L);
00463         unsignedIntTest(0x7FFFFFFF00000000L, 0L);
00464         unsignedIntTest(0xFFFFFFFF00000000L, 0L);
00465         unsignedIntTest(-1, 0xFFFFFFFFL);
00466         unsignedIntTest(-2, 0xFFFFFFFFL - 1L);
00467         unsignedIntTest(-0xFFFFFFFFL, 1L);
00468 
00469         out.reset();
00470         out.writeUnsignedInt(0L);
00471         out.writeUnsignedInt(1L);
00472         out.writeUnsignedInt(0xFFFFFFFFL);
00473         assertEquals(12, out.size());
00474         copyOutputToInput();
00475         assertEquals(0L, in.readUnsignedInt());
00476         assertEquals(1L, in.readUnsignedInt());
00477         assertEquals(0xFFFFFFFFL, in.readUnsignedInt());
00478         assertEquals(0L, in.available());
00479     }
00480 
00481     private void byteTest(int val) {
00482 
00483         out.reset();
00484         out.writeByte(val);
00485         assertEquals(1, out.size());
00486         copyOutputToInput();
00487         assertEquals((byte) val, in.readByte());
00488     }
00489 
00490     public void testByte() {
00491 
00492         byteTest(0);
00493         byteTest(1);
00494         byteTest(-1);
00495         byteTest(Byte.MAX_VALUE - 1);
00496         byteTest(Byte.MAX_VALUE);
00497         byteTest(Byte.MAX_VALUE + 1);
00498         byteTest(Byte.MIN_VALUE + 1);
00499         byteTest(Byte.MIN_VALUE);
00500         byteTest(Byte.MIN_VALUE - 1);
00501         byteTest(0x7F);
00502         byteTest(0xFF);
00503         byteTest(0x7FFF);
00504         byteTest(0xFFFF);
00505         byteTest(0x7FFFFFFF);
00506         byteTest(0xFFFFFFFF);
00507 
00508         out.reset();
00509         out.writeByte(0);
00510         out.writeByte(1);
00511         out.writeByte(-1);
00512         assertEquals(3, out.size());
00513         copyOutputToInput();
00514         assertEquals(0, in.readByte());
00515         assertEquals(1, in.readByte());
00516         assertEquals(-1, in.readByte());
00517         assertEquals(0, in.available());
00518     }
00519 
00520     private void shortTest(int val) {
00521 
00522         out.reset();
00523         out.writeShort(val);
00524         assertEquals(2, out.size());
00525         copyOutputToInput();
00526         assertEquals((short) val, in.readShort());
00527     }
00528 
00529     public void testShort() {
00530 
00531         shortTest(0);
00532         shortTest(1);
00533         shortTest(-1);
00534         shortTest(Short.MAX_VALUE - 1);
00535         shortTest(Short.MAX_VALUE);
00536         shortTest(Short.MAX_VALUE + 1);
00537         shortTest(Short.MIN_VALUE + 1);
00538         shortTest(Short.MIN_VALUE);
00539         shortTest(Short.MIN_VALUE - 1);
00540         shortTest(0x7F);
00541         shortTest(0xFF);
00542         shortTest(0x7FFF);
00543         shortTest(0xFFFF);
00544         shortTest(0x7FFFFFFF);
00545         shortTest(0xFFFFFFFF);
00546 
00547         out.reset();
00548         out.writeShort(0);
00549         out.writeShort(1);
00550         out.writeShort(-1);
00551         assertEquals(3 * 2, out.size());
00552         copyOutputToInput();
00553         assertEquals(0, in.readShort());
00554         assertEquals(1, in.readShort());
00555         assertEquals(-1, in.readShort());
00556         assertEquals(0, in.available());
00557     }
00558 
00559     private void intTest(int val) {
00560 
00561         out.reset();
00562         out.writeInt(val);
00563         assertEquals(4, out.size());
00564         copyOutputToInput();
00565         assertEquals((int) val, in.readInt());
00566     }
00567 
00568     public void testInt() {
00569 
00570         intTest(0);
00571         intTest(1);
00572         intTest(-1);
00573         intTest(Integer.MAX_VALUE - 1);
00574         intTest(Integer.MAX_VALUE);
00575         intTest(Integer.MAX_VALUE + 1);
00576         intTest(Integer.MIN_VALUE + 1);
00577         intTest(Integer.MIN_VALUE);
00578         intTest(Integer.MIN_VALUE - 1);
00579         intTest(0x7F);
00580         intTest(0xFF);
00581         intTest(0x7FFF);
00582         intTest(0xFFFF);
00583         intTest(0x7FFFFFFF);
00584         intTest(0xFFFFFFFF);
00585 
00586         out.reset();
00587         out.writeInt(0);
00588         out.writeInt(1);
00589         out.writeInt(-1);
00590         assertEquals(3 * 4, out.size());
00591         copyOutputToInput();
00592         assertEquals(0, in.readInt());
00593         assertEquals(1, in.readInt());
00594         assertEquals(-1, in.readInt());
00595         assertEquals(0, in.available());
00596     }
00597 
00598     private void longTest(long val) {
00599 
00600         out.reset();
00601         out.writeLong(val);
00602         assertEquals(8, out.size());
00603         copyOutputToInput();
00604         assertEquals((long) val, in.readLong());
00605     }
00606 
00607     public void testLong() {
00608 
00609         longTest(0);
00610         longTest(1);
00611         longTest(-1);
00612         longTest(Long.MAX_VALUE - 1);
00613         longTest(Long.MAX_VALUE);
00614         longTest(Long.MAX_VALUE + 1);
00615         longTest(Long.MIN_VALUE + 1);
00616         longTest(Long.MIN_VALUE);
00617         longTest(Long.MIN_VALUE - 1);
00618         longTest(0x7F);
00619         longTest(0xFF);
00620         longTest(0x7FFF);
00621         longTest(0xFFFF);
00622         longTest(0x7FFFFFFF);
00623         longTest(0xFFFFFFFF);
00624         longTest(0x7FFFFFFFFFFFFFFFL);
00625         longTest(0xFFFFFFFFFFFFFFFFL);
00626 
00627         out.reset();
00628         out.writeLong(0);
00629         out.writeLong(1);
00630         out.writeLong(-1);
00631         assertEquals(3 * 8, out.size());
00632         copyOutputToInput();
00633         assertEquals(0, in.readLong());
00634         assertEquals(1, in.readLong());
00635         assertEquals(-1, in.readLong());
00636         assertEquals(0, in.available());
00637     }
00638 
00639     private void floatTest(double val) {
00640 
00641         out.reset();
00642         out.writeFloat((float) val);
00643         assertEquals(4, out.size());
00644         copyOutputToInput();
00645         if (Double.isNaN(val)) {
00646             assertTrue(Float.isNaN(in.readFloat()));
00647         } else {
00648             assertEquals((float) val, in.readFloat(), 0);
00649         }
00650     }
00651 
00652     public void testFloat() {
00653 
00654         floatTest(0);
00655         floatTest(1);
00656         floatTest(-1);
00657         floatTest(1.0);
00658         floatTest(0.1);
00659         floatTest(-1.0);
00660         floatTest(-0.1);
00661         floatTest(Float.NaN);
00662         floatTest(Float.NEGATIVE_INFINITY);
00663         floatTest(Float.POSITIVE_INFINITY);
00664         floatTest(Short.MAX_VALUE);
00665         floatTest(Short.MIN_VALUE);
00666         floatTest(Integer.MAX_VALUE);
00667         floatTest(Integer.MIN_VALUE);
00668         floatTest(Long.MAX_VALUE);
00669         floatTest(Long.MIN_VALUE);
00670         floatTest(Float.MAX_VALUE);
00671         floatTest(Float.MAX_VALUE + 1);
00672         floatTest(Float.MIN_VALUE + 1);
00673         floatTest(Float.MIN_VALUE);
00674         floatTest(Float.MIN_VALUE - 1);
00675         floatTest(0x7F);
00676         floatTest(0xFF);
00677         floatTest(0x7FFF);
00678         floatTest(0xFFFF);
00679         floatTest(0x7FFFFFFF);
00680         floatTest(0xFFFFFFFF);
00681         floatTest(0x7FFFFFFFFFFFFFFFL);
00682         floatTest(0xFFFFFFFFFFFFFFFFL);
00683 
00684         out.reset();
00685         out.writeFloat(0);
00686         out.writeFloat(1);
00687         out.writeFloat(-1);
00688         assertEquals(3 * 4, out.size());
00689         copyOutputToInput();
00690         assertEquals(0, in.readFloat(), 0);
00691         assertEquals(1, in.readFloat(), 0);
00692         assertEquals(-1, in.readFloat(), 0);
00693         assertEquals(0, in.available(), 0);
00694     }
00695 
00696     private void doubleTest(double val) {
00697 
00698         out.reset();
00699         out.writeDouble((double) val);
00700         assertEquals(8, out.size());
00701         copyOutputToInput();
00702         if (Double.isNaN(val)) {
00703             assertTrue(Double.isNaN(in.readDouble()));
00704         } else {
00705             assertEquals((double) val, in.readDouble(), 0);
00706         }
00707     }
00708 
00709     public void testDouble() {
00710 
00711         doubleTest(0);
00712         doubleTest(1);
00713         doubleTest(-1);
00714         doubleTest(1.0);
00715         doubleTest(0.1);
00716         doubleTest(-1.0);
00717         doubleTest(-0.1);
00718         doubleTest(Double.NaN);
00719         doubleTest(Double.NEGATIVE_INFINITY);
00720         doubleTest(Double.POSITIVE_INFINITY);
00721         doubleTest(Short.MAX_VALUE);
00722         doubleTest(Short.MIN_VALUE);
00723         doubleTest(Integer.MAX_VALUE);
00724         doubleTest(Integer.MIN_VALUE);
00725         doubleTest(Long.MAX_VALUE);
00726         doubleTest(Long.MIN_VALUE);
00727         doubleTest(Float.MAX_VALUE);
00728         doubleTest(Float.MIN_VALUE);
00729         doubleTest(Double.MAX_VALUE - 1);
00730         doubleTest(Double.MAX_VALUE);
00731         doubleTest(Double.MAX_VALUE + 1);
00732         doubleTest(Double.MIN_VALUE + 1);
00733         doubleTest(Double.MIN_VALUE);
00734         doubleTest(Double.MIN_VALUE - 1);
00735         doubleTest(0x7F);
00736         doubleTest(0xFF);
00737         doubleTest(0x7FFF);
00738         doubleTest(0xFFFF);
00739         doubleTest(0x7FFFFFFF);
00740         doubleTest(0xFFFFFFFF);
00741         doubleTest(0x7FFFFFFFFFFFFFFFL);
00742         doubleTest(0xFFFFFFFFFFFFFFFFL);
00743 
00744         out.reset();
00745         out.writeDouble(0);
00746         out.writeDouble(1);
00747         out.writeDouble(-1);
00748         assertEquals(3 * 8, out.size());
00749         copyOutputToInput();
00750         assertEquals(0, in.readDouble(), 0);
00751         assertEquals(1, in.readDouble(), 0);
00752         assertEquals(-1, in.readDouble(), 0);
00753         assertEquals(0, in.available(), 0);
00754     }
00755 }
00756 

Generated on Sun Dec 25 12:14:53 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2