001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (license2)
004: * Initial Developer: H2 Group
005: */
006: package org.h2.test.unit;
007:
008: import java.sql.SQLException;
009:
010: import org.h2.constant.SysProperties;
011: import org.h2.store.DataHandler;
012: import org.h2.store.DataPage;
013: import org.h2.store.FileStore;
014: import org.h2.test.TestBase;
015: import org.h2.util.SmallLRUCache;
016: import org.h2.value.Value;
017: import org.h2.value.ValueDouble;
018: import org.h2.value.ValueFloat;
019: import org.h2.value.ValueInt;
020: import org.h2.value.ValueNull;
021: import org.h2.value.ValueString;
022:
023: /**
024: * Data page tests.
025: */
026: public class TestDataPage extends TestBase implements DataHandler {
027:
028: boolean text;
029:
030: public void test() throws Exception {
031: testAll();
032: text = true;
033: testAll();
034: }
035:
036: private void testAll() throws Exception {
037: DataPage page = DataPage.create(this , 128);
038:
039: char[] data = new char[0x10000];
040: for (int i = 0; i < data.length; i++) {
041: data[i] = (char) i;
042: }
043: String s = new String(data);
044: page.writeString(s);
045: int len = page.length();
046: check(page.getStringLen(s), len);
047: page.reset();
048: check(s, page.readString());
049: page.reset();
050:
051: page.writeString("H\u1111!");
052: page.writeString("John\tBrack's \"how are you\" M\u1111ller");
053: page.writeValue(ValueInt.get(10));
054: page.writeValue(ValueString.get("test"));
055: page.writeValue(ValueFloat.get(-2.25f));
056: page.writeValue(ValueDouble.get(10.40));
057: page.writeValue(ValueNull.INSTANCE);
058: trace(new String(page.getBytes()));
059: page.reset();
060:
061: trace(page.readString());
062: trace(page.readString());
063: trace(page.readValue().getInt());
064: trace(page.readValue().getString());
065: trace("" + page.readValue().getFloat());
066: trace("" + page.readValue().getDouble());
067: trace(page.readValue().toString());
068: page.reset();
069:
070: page.writeInt(0);
071: page.writeInt(Integer.MAX_VALUE);
072: page.writeInt(Integer.MIN_VALUE);
073: page.writeInt(1);
074: page.writeInt(-1);
075: page.writeInt(1234567890);
076: page.writeInt(54321);
077: trace(new String(page.getBytes()));
078: page.reset();
079: trace(page.readInt());
080: trace(page.readInt());
081: trace(page.readInt());
082: trace(page.readInt());
083: trace(page.readInt());
084: trace(page.readInt());
085: trace(page.readInt());
086:
087: page = null;
088: }
089:
090: public boolean getTextStorage() {
091: return text;
092: }
093:
094: public String getDatabasePath() {
095: return null;
096: }
097:
098: public FileStore openFile(String name, String mode,
099: boolean mustExist) throws SQLException {
100: return null;
101: }
102:
103: public int getChecksum(byte[] data, int start, int end) {
104: return end - start;
105: }
106:
107: public void checkPowerOff() throws SQLException {
108: }
109:
110: public void checkWritingAllowed() throws SQLException {
111: }
112:
113: public void freeUpDiskSpace() throws SQLException {
114: }
115:
116: public void handleInvalidChecksum() throws SQLException {
117: throw new SQLException();
118: }
119:
120: public int compareTypeSave(Value a, Value b) throws SQLException {
121: throw new SQLException();
122: }
123:
124: public int getMaxLengthInplaceLob() {
125: throw new Error();
126: }
127:
128: public int allocateObjectId(boolean b, boolean c) {
129: throw new Error();
130: }
131:
132: public String createTempFile() throws SQLException {
133: throw new SQLException();
134: }
135:
136: public String getLobCompressionAlgorithm(int type) {
137: throw new Error();
138: }
139:
140: public Object getLobSyncObject() {
141: return this ;
142: }
143:
144: public boolean getLobFilesInDirectories() {
145: return SysProperties.LOB_FILES_IN_DIRECTORIES;
146: }
147:
148: public SmallLRUCache getLobFileListCache() {
149: return null;
150: }
151:
152: }
|