提交 ff6506a0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Additional test cases.

上级 9e7f4dfe
......@@ -783,34 +783,38 @@ public class DataType {
if (x.isPrimitive()) {
x = Utils.getNonPrimitiveClass(x);
}
if (ResultSet.class.isAssignableFrom(x)) {
return Value.RESULT_SET;
} else if (Value.ValueBlob.class.isAssignableFrom(x)) {
return Value.BLOB;
} else if (Value.ValueClob.class.isAssignableFrom(x)) {
return Value.CLOB;
} else if (String.class.isAssignableFrom(x)) {
if (String.class == x) {
return Value.STRING;
} else if (BigDecimal.class.isAssignableFrom(x)) {
return Value.DECIMAL;
} else if (Integer.class == x) {
return Value.INT;
} else if (Long.class == x) {
return Value.LONG;
} else if (Boolean.class == x) {
return Value.BOOLEAN;
} else if (Double.class == x) {
return Value.DOUBLE;
} else if (Byte.class == x) {
return Value.BYTE;
} else if (Short.class == x) {
return Value.SHORT;
} else if (Integer.class == x) {
return Value.INT;
} else if (Character.class == x) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, "char (not supported)");
} else if (Long.class == x) {
return Value.LONG;
} else if (Float.class == x) {
return Value.FLOAT;
} else if (Double.class == x) {
return Value.DOUBLE;
} else if (byte[].class.isAssignableFrom(x)) {
} else if (byte[].class == x) {
return Value.BYTES;
} else if (UUID.class == x) {
return Value.UUID;
} else if (Void.class == x) {
return Value.NULL;
} else if (BigDecimal.class.isAssignableFrom(x)) {
return Value.DECIMAL;
} else if (ResultSet.class.isAssignableFrom(x)) {
return Value.RESULT_SET;
} else if (Value.ValueBlob.class.isAssignableFrom(x)) {
return Value.BLOB;
} else if (Value.ValueClob.class.isAssignableFrom(x)) {
return Value.CLOB;
} else if (Date.class.isAssignableFrom(x)) {
return Value.DATE;
} else if (Time.class.isAssignableFrom(x)) {
......@@ -827,12 +831,9 @@ public class DataType {
return Value.BLOB;
} else if (java.sql.Blob.class.isAssignableFrom(x)) {
return Value.BLOB;
} else if (UUID.class.isAssignableFrom(x)) {
return Value.UUID;
} else if (Object[].class.isAssignableFrom(x)) {
// this includes String[] and so on
return Value.ARRAY;
} else if (Void.TYPE == x) {
return Value.NULL;
} else {
return Value.JAVA_OBJECT;
}
......
......@@ -7,6 +7,7 @@
package org.h2.test.unit;
import java.io.File;
import java.math.BigInteger;
import org.h2.test.TestBase;
import org.h2.util.Utils;
......@@ -30,6 +31,31 @@ public class TestUtils extends TestBase {
}
public void test() throws Exception {
testGetNonPrimitiveClass();
testGetNonPrimitiveClass();
testGetNonPrimitiveClass();
testReflectionUtils();
}
private void testGetNonPrimitiveClass() throws Exception {
testGetNonPrimitiveClass(BigInteger.class, BigInteger.class);
testGetNonPrimitiveClass(Boolean.class, boolean.class);
testGetNonPrimitiveClass(Byte.class, byte.class);
testGetNonPrimitiveClass(Character.class, char.class);
testGetNonPrimitiveClass(Byte.class, byte.class);
testGetNonPrimitiveClass(Double.class, double.class);
testGetNonPrimitiveClass(Float.class, float.class);
testGetNonPrimitiveClass(Integer.class, int.class);
testGetNonPrimitiveClass(Long.class, long.class);
testGetNonPrimitiveClass(Short.class, short.class);
testGetNonPrimitiveClass(Void.class, void.class);
}
private void testGetNonPrimitiveClass(Class<?> expected, Class<?> prim) {
assertEquals(expected.getName(), Utils.getNonPrimitiveClass(prim).getName());
}
private void testReflectionUtils() throws Exception {
// Static method call
long currentTimeMillis1 = System.currentTimeMillis();
long currentTimeMillis2 = (Long) Utils.callStaticMethod("java.lang.System.currentTimeMillis");
......
......@@ -6,7 +6,14 @@
*/
package org.h2.test.unit;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.UUID;
import org.h2.test.TestBase;
import org.h2.value.DataType;
import org.h2.value.Value;
import org.h2.value.ValueDouble;
import org.h2.value.ValueFloat;
......@@ -27,11 +34,48 @@ public class TestValue extends TestBase {
}
public void test() {
testDataType();
testUUID();
testDouble(false);
testDouble(true);
}
private void testDataType() {
testDataType(Value.NULL, null);
testDataType(Value.NULL, Void.class);
testDataType(Value.NULL, void.class);
testDataType(Value.ARRAY, String[].class);
testDataType(Value.STRING, String.class);
testDataType(Value.INT, Integer.class);
testDataType(Value.LONG, Long.class);
testDataType(Value.BOOLEAN, Boolean.class);
testDataType(Value.DOUBLE, Double.class);
testDataType(Value.BYTE, Byte.class);
testDataType(Value.SHORT, Short.class);
testDataType(Value.FLOAT, Float.class);
testDataType(Value.BYTES, byte[].class);
testDataType(Value.UUID, UUID.class);
testDataType(Value.NULL, Void.class);
testDataType(Value.DECIMAL, BigDecimal.class);
testDataType(Value.RESULT_SET, ResultSet.class);
testDataType(Value.BLOB, Value.ValueBlob.class);
testDataType(Value.CLOB, Value.ValueClob.class);
testDataType(Value.DATE, Date.class);
testDataType(Value.TIME, Time.class);
testDataType(Value.TIMESTAMP, Timestamp.class);
testDataType(Value.TIMESTAMP, java.util.Date.class);
testDataType(Value.CLOB, java.io.Reader.class);
testDataType(Value.CLOB, java.sql.Clob.class);
testDataType(Value.BLOB, java.io.InputStream.class);
testDataType(Value.BLOB, java.sql.Blob.class);
testDataType(Value.ARRAY, Object[].class);
testDataType(Value.JAVA_OBJECT, StringBuffer.class);
}
private void testDataType(int type, Class<?> clazz) {
assertEquals(type, DataType.getTypeFromClass(clazz));
}
private void testDouble(boolean useFloat) {
double[] d = {
Double.NEGATIVE_INFINITY,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论