Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
fd51d35f
提交
fd51d35f
authored
12月 06, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve code coverage.
上级
b2b95ccd
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
225 行增加
和
28 行删除
+225
-28
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+4
-0
TestWeb.java
h2/src/test/org/h2/test/server/TestWeb.java
+105
-17
TestOldVersion.java
h2/src/test/org/h2/test/unit/TestOldVersion.java
+88
-10
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+28
-1
没有找到文件。
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
fd51d35f
...
...
@@ -567,6 +567,10 @@ public abstract class TestBase {
* @throws AssertionError if the values are not equal
*/
public
void
assertEquals
(
byte
[]
expected
,
byte
[]
actual
)
{
if
(
expected
==
null
||
actual
==
null
)
{
assertTrue
(
expected
==
actual
);
return
;
}
assertEquals
(
expected
.
length
,
actual
.
length
);
for
(
int
i
=
0
;
i
<
expected
.
length
;
i
++)
{
if
(
expected
[
i
]
!=
actual
[
i
])
{
...
...
h2/src/test/org/h2/test/server/TestWeb.java
浏览文件 @
fd51d35f
差异被折叠。
点击展开。
h2/src/test/org/h2/test/unit/TestOldVersion.java
浏览文件 @
fd51d35f
...
...
@@ -10,18 +10,25 @@ import java.net.URL;
import
java.net.URLClassLoader
;
import
java.sql.Connection
;
import
java.sql.Driver
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Server
;
import
org.hsqldb.types.Types
;
/**
* Tests the compatibility with older versions
*/
public
class
TestOldVersion
extends
TestBase
{
private
ClassLoader
cl
;
private
Driver
driver
;
/**
* Run just this test.
*
...
...
@@ -32,20 +39,72 @@ public class TestOldVersion extends TestBase {
}
public
void
test
()
throws
Exception
{
URL
[]
urls
=
{
new
URL
(
"file:ext/h2-1.2.127.jar"
)
};
ClassLoader
cl
=
new
URLClassLoader
(
urls
,
null
);
// cl = getClass().getClassLoader();
Class
<?>
driverClass
;
try
{
driverClass
=
cl
.
loadClass
(
"org.h2.Driver"
);
}
catch
(
ClassNotFoundException
e
)
{
cl
=
getClassLoader
(
"file:ext/h2-1.2.127.jar"
);
driver
=
getDriver
(
cl
);
if
(
driver
==
null
)
{
println
(
"not found: ext/h2-1.2.127.jar - test skipped"
);
return
;
}
Method
m
=
driverClass
.
getMethod
(
"load"
);
Driver
driver
=
(
Driver
)
m
.
invoke
(
null
);
Connection
conn
=
driver
.
connect
(
"jdbc:h2:mem:"
,
null
);
assertEquals
(
"1.2.127 (2010-01-15)"
,
conn
.
getMetaData
().
getDatabaseProductVersion
());
conn
.
close
();
testLobInFiles
();
testOldClientNewServer
();
}
private
void
testLobInFiles
()
throws
Exception
{
deleteDb
(
"oldVersion"
);
Connection
conn
;
Statement
stat
;
conn
=
driver
.
connect
(
"jdbc:h2:"
+
getBaseDir
()
+
"/oldVersion"
,
null
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, b blob, c clob)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?, ?)"
);
prep
.
setInt
(
1
,
0
);
prep
.
setNull
(
2
,
Types
.
BLOB
);
prep
.
setNull
(
3
,
Types
.
CLOB
);
prep
.
execute
();
prep
.
setInt
(
1
,
1
);
prep
.
setBytes
(
2
,
new
byte
[
0
]);
prep
.
setString
(
3
,
""
);
prep
.
execute
();
prep
.
setInt
(
1
,
2
);
prep
.
setBytes
(
2
,
new
byte
[
5
]);
prep
.
setString
(
3
,
"\u1234\u1234\u1234\u1234\u1234"
);
prep
.
execute
();
prep
.
setInt
(
1
,
3
);
prep
.
setBytes
(
2
,
new
byte
[
100000
]);
prep
.
setString
(
3
,
new
String
(
new
char
[
100000
]));
prep
.
execute
();
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
getBaseDir
()
+
"/oldVersion"
,
new
Properties
());
stat
=
conn
.
createStatement
();
checkResult
(
stat
.
executeQuery
(
"select * from test order by id"
));
stat
.
execute
(
"create table test2 as select * from test"
);
checkResult
(
stat
.
executeQuery
(
"select * from test2 order by id"
));
stat
.
execute
(
"delete from test"
);
conn
.
close
();
}
private
void
checkResult
(
ResultSet
rs
)
throws
SQLException
{
rs
.
next
();
assertEquals
(
0
,
rs
.
getInt
(
1
));
assertEquals
(
null
,
rs
.
getBytes
(
2
));
assertEquals
(
null
,
rs
.
getString
(
3
));
rs
.
next
();
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
new
byte
[
0
],
rs
.
getBytes
(
2
));
assertEquals
(
""
,
rs
.
getString
(
3
));
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
new
byte
[
5
],
rs
.
getBytes
(
2
));
assertEquals
(
"\u1234\u1234\u1234\u1234\u1234"
,
rs
.
getString
(
3
));
rs
.
next
();
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
new
byte
[
100000
],
rs
.
getBytes
(
2
));
assertEquals
(
new
String
(
new
char
[
100000
]),
rs
.
getString
(
3
));
}
private
void
testOldClientNewServer
()
throws
Exception
{
Server
server
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
"9001"
);
server
.
start
();
try
{
...
...
@@ -56,10 +115,12 @@ public class TestOldVersion extends TestBase {
server
.
stop
();
Class
<?>
serverClass
=
cl
.
loadClass
(
"org.h2.tools.Server"
);
Method
m
;
m
=
serverClass
.
getMethod
(
"createTcpServer"
,
String
[].
class
);
Object
serverOld
=
m
.
invoke
(
null
,
new
Object
[]{
new
String
[]{
"-tcpPort"
,
"9001"
}});
m
=
serverOld
.
getClass
().
getMethod
(
"start"
);
m
.
invoke
(
serverOld
);
Connection
conn
;
conn
=
org
.
h2
.
Driver
.
load
().
connect
(
"jdbc:h2:mem:"
,
null
);
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"call 1"
);
...
...
@@ -70,4 +131,21 @@ public class TestOldVersion extends TestBase {
m
.
invoke
(
serverOld
);
}
private
ClassLoader
getClassLoader
(
String
jarFile
)
throws
Exception
{
URL
[]
urls
=
{
new
URL
(
jarFile
)
};
return
new
URLClassLoader
(
urls
,
null
);
}
private
Driver
getDriver
(
ClassLoader
cl
)
throws
Exception
{
Class
<?>
driverClass
;
try
{
driverClass
=
cl
.
loadClass
(
"org.h2.Driver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
null
;
}
Method
m
=
driverClass
.
getMethod
(
"load"
);
Driver
driver
=
(
Driver
)
m
.
invoke
(
null
);
return
driver
;
}
}
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
fd51d35f
...
...
@@ -9,15 +9,19 @@ package org.h2.test.unit;
import
java.math.BigDecimal
;
import
java.sql.Date
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.util.UUID
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueResultSet
;
import
org.h2.value.ValueUuid
;
import
org.hsqldb.types.Types
;
/**
* Tests features of values.
...
...
@@ -33,13 +37,36 @@ public class TestValue extends TestBase {
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
{
public
void
test
()
throws
SQLException
{
testValueResultSet
();
testDataType
();
testUUID
();
testDouble
(
false
);
testDouble
(
true
);
}
private
void
testValueResultSet
()
throws
SQLException
{
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"ID"
,
Types
.
INTEGER
,
0
,
0
);
rs
.
addColumn
(
"NAME"
,
Types
.
VARCHAR
,
255
,
0
);
rs
.
addRow
(
1
,
"Hello"
);
rs
.
addRow
(
2
,
"World"
);
rs
.
addRow
(
3
,
"Peace"
);
ValueResultSet
v
=
ValueResultSet
.
getCopy
(
rs
,
2
);
rs
.
beforeFirst
();
ResultSet
rs2
=
v
.
getResultSet
();
rs2
.
next
();
rs
.
next
();
assertEquals
(
rs
.
getInt
(
1
),
rs2
.
getInt
(
1
));
assertEquals
(
rs
.
getString
(
2
),
rs2
.
getString
(
2
));
rs2
.
next
();
rs
.
next
();
assertEquals
(
rs
.
getInt
(
1
),
rs2
.
getInt
(
1
));
assertEquals
(
rs
.
getString
(
2
),
rs2
.
getString
(
2
));
assertFalse
(
rs2
.
next
());
assertTrue
(
rs
.
next
());
}
private
void
testDataType
()
{
testDataType
(
Value
.
NULL
,
null
);
testDataType
(
Value
.
NULL
,
Void
.
class
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论