1 5 package org.h2.test.unit; 6 7 import java.sql.SQLException ; 8 9 import org.h2.store.DataHandler; 10 import org.h2.store.DataPage; 11 import org.h2.store.FileStore; 12 import org.h2.test.TestBase; 13 import org.h2.value.Value; 14 import org.h2.value.ValueDouble; 15 import org.h2.value.ValueFloat; 16 import org.h2.value.ValueInt; 17 import org.h2.value.ValueNull; 18 import org.h2.value.ValueString; 19 20 23 24 public class TestDataPage extends TestBase implements DataHandler { 25 26 boolean text; 27 28 public void test() throws Exception { 29 testAll(); 30 text = true; 31 testAll(); 32 } 33 34 private void testAll() throws Exception { 35 DataPage page = DataPage.create(this, 128); 36 37 char[] data = new char[0x10000]; 38 for(int i=0; i<data.length; i++) { 39 data[i] = (char)i; 40 } 41 String s = new String (data); 42 page.writeString(s); 43 int len = page.length(); 44 check(page.getStringLen(s), len); 45 page.reset(); 46 check(s, page.readString()); 47 page.reset(); 48 49 page.writeString("H\u1111!"); 50 page.writeString("John\tBrack's \"how are you\" M\u1111ller"); 51 page.writeValue(ValueInt.get(10)); 52 page.writeValue(ValueString.get("test")); 53 page.writeValue(ValueFloat.get(-2.25f)); 54 page.writeValue(ValueDouble.get(10.40)); 55 page.writeValue(ValueNull.INSTANCE); 56 trace(new String (page.getBytes())); 57 page.reset(); 58 59 trace(page.readString()); 60 trace(page.readString()); 61 trace(page.readValue().getInt()); 62 trace(page.readValue().getString()); 63 trace(""+page.readValue().getFloat()); 64 trace(""+page.readValue().getDouble()); 65 trace(page.readValue().toString()); 66 page.reset(); 67 68 page.writeInt(0); 69 page.writeInt(Integer.MAX_VALUE); 70 page.writeInt(Integer.MIN_VALUE); 71 page.writeInt(1); 72 page.writeInt(-1); 73 page.writeInt(1234567890); 74 page.writeInt(54321); 75 trace(new String (page.getBytes())); 76 page.reset(); 77 trace(page.readInt()); 78 trace(page.readInt()); 79 trace(page.readInt()); 80 trace(page.readInt()); 81 trace(page.readInt()); 82 trace(page.readInt()); 83 trace(page.readInt()); 84 85 page = null; 86 } 87 88 public boolean getTextStorage() { 89 return text; 90 } 91 92 public String getDatabasePath() { 93 return null; 94 } 95 96 public FileStore openFile(String name, boolean mustExist) throws SQLException { 97 return null; 98 } 99 100 public int getChecksum(byte[] data, int start, int end) { 101 return end-start; 102 } 103 104 public void checkPowerOff() throws SQLException { 105 } 106 107 public void checkWritingAllowed() throws SQLException { 108 } 109 110 public void freeUpDiskSpace() throws SQLException { 111 } 112 113 public void handleInvalidChecksum() throws SQLException { 114 throw new SQLException (); 115 } 116 117 public int compareTypeSave(Value a, Value b) throws SQLException { 118 throw new SQLException (); 119 } 120 121 public int getMaxLengthInplaceLob() { 122 throw new Error (); 123 } 124 125 public int allocateObjectId(boolean b, boolean c) { 126 throw new Error (); 127 } 128 129 public String createTempFile() throws SQLException { 130 throw new SQLException (); 131 } 132 133 public String getLobCompressionAlgorithm(int type) { 134 throw new Error (); 135 } 136 137 } 138 | Popular Tags |