Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4ec6e3bf
提交
4ec6e3bf
authored
6月 05, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make most tests locale independent
上级
070b2cec
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
76 行增加
和
44 行删除
+76
-44
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+3
-3
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+60
-28
TestRights.java
h2/src/test/org/h2/test/db/TestRights.java
+13
-13
没有找到文件。
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
4ec6e3bf
...
...
@@ -1009,13 +1009,13 @@ public abstract class TestBase {
* @param stat the statement
* @param sql the SQL statement to execute
*/
protected
void
assertThrows
(
String
expectedErrorMessag
e
,
Statement
stat
,
protected
void
assertThrows
(
int
expectedErrorCod
e
,
Statement
stat
,
String
sql
)
{
try
{
stat
.
execute
(
sql
);
fail
(
"Expected error: "
+
expectedError
Messag
e
);
fail
(
"Expected error: "
+
expectedError
Cod
e
);
}
catch
(
SQLException
ex
)
{
assert
StartsWith
(
ex
.
getMessage
(),
expectedErrorMessage
);
assert
Equals
(
expectedErrorCode
,
ex
.
getErrorCode
()
);
}
}
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
4ec6e3bf
...
...
@@ -22,6 +22,7 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
...
...
@@ -1239,7 +1240,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"1979-11-12 08:12:34.56"
,
stat
,
"SELECT X FROM T"
);
assertResult
(
"-100-01-15 14:04:02.12"
,
stat
,
"SELECT X FROM U"
);
assertResult
(
"12-NOV-79 08.12.34.560000 AM"
,
stat
,
"SELECT TO_CHAR(X) FROM T"
);
String
expected
=
String
.
format
(
"%tb"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
)).
toUpperCase
();
assertResult
(
"12-"
+
expected
+
"-79 08.12.34.560000 AM"
,
stat
,
"SELECT TO_CHAR(X) FROM T"
);
assertResult
(
"- / , . ; : text - /"
,
stat
,
"SELECT TO_CHAR(X, '- / , . ; : \"text\" - /') FROM T"
);
assertResult
(
"1979-11-12"
,
stat
,
...
...
@@ -1286,30 +1290,42 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"am"
,
stat
,
"SELECT TO_CHAR(X, 'pm') FROM T"
);
assertResult
(
"2"
,
stat
,
"SELECT TO_CHAR(X, 'D') FROM T"
);
assertResult
(
"2"
,
stat
,
"SELECT TO_CHAR(X, 'd') FROM T"
);
assertResult
(
"MONDAY "
,
stat
,
"SELECT TO_CHAR(X, 'DAY') FROM T"
);
assertResult
(
"Monday "
,
stat
,
"SELECT TO_CHAR(X, 'Day') FROM T"
);
assertResult
(
"monday "
,
stat
,
"SELECT TO_CHAR(X, 'day') FROM T"
);
assertResult
(
"monday "
,
stat
,
"SELECT TO_CHAR(X, 'dAY') FROM T"
);
assertResult
(
"Monday"
,
stat
,
"SELECT TO_CHAR(X, 'fmDay') FROM T"
);
assertResult
(
"monday -monday-monday-monday -monday"
,
stat
,
"SELECT TO_CHAR(X, 'day-fmday-day-fmday-fmday') FROM T"
);
expected
=
String
.
format
(
"%tA"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
expected
.
substring
(
0
,
1
).
toUpperCase
()
+
expected
.
substring
(
1
);
String
spaces
=
" "
;
String
first9
=
(
expected
+
spaces
).
substring
(
0
,
9
);
assertResult
(
first9
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'DAY') FROM T"
);
assertResult
(
first9
,
stat
,
"SELECT TO_CHAR(X, 'Day') FROM T"
);
assertResult
(
first9
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'day') FROM T"
);
assertResult
(
first9
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'dAY') FROM T"
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'fmDay') FROM T"
);
assertResult
(
"12"
,
stat
,
"SELECT TO_CHAR(X, 'DD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'DDD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'DdD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'dDD') FROM T"
);
assertResult
(
"316"
,
stat
,
"SELECT TO_CHAR(X, 'ddd') FROM T"
);
assertResult
(
"Monday, November 12, 1979"
,
stat
,
expected
=
String
.
format
(
"%1$tA, %1$tB %1$te, %1$tY"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'DL') FROM T"
);
assertResult
(
"Monday, November 12, 1979"
,
stat
,
"SELECT TO_CHAR(X, 'DL', 'NLS_DATE_LANGUAGE = English') FROM T"
);
//
assertResult("Monday, November 12, 1979", stat,
//
"SELECT TO_CHAR(X, 'DL', 'NLS_DATE_LANGUAGE = English') FROM T");
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'DS') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'Ds') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'dS') FROM T"
);
assertResult
(
"11/12/1979"
,
stat
,
"SELECT TO_CHAR(X, 'ds') FROM T"
);
assertResult
(
"MON"
,
stat
,
"SELECT TO_CHAR(X, 'DY') FROM T"
);
assertResult
(
"Mon"
,
stat
,
"SELECT TO_CHAR(X, 'Dy') FROM T"
);
assertResult
(
"mon"
,
stat
,
"SELECT TO_CHAR(X, 'dy') FROM T"
);
assertResult
(
"mon"
,
stat
,
"SELECT TO_CHAR(X, 'dY') FROM T"
);
expected
=
String
.
format
(
"%1$ta"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'DY') FROM T"
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'Dy') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'dy') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'dY') FROM T"
);
assertResult
(
"08:12:34.560000"
,
stat
,
"SELECT TO_CHAR(X, 'HH:MI:SS.FF') FROM T"
);
assertResult
(
"08:12:34.5"
,
stat
,
...
...
@@ -1350,13 +1366,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'Mm') FROM T"
);
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'mM') FROM T"
);
assertResult
(
"11"
,
stat
,
"SELECT TO_CHAR(X, 'mm') FROM T"
);
assertResult
(
"NOV"
,
stat
,
"SELECT TO_CHAR(X, 'MON') FROM T"
);
assertResult
(
"Nov"
,
stat
,
"SELECT TO_CHAR(X, 'Mon') FROM T"
);
assertResult
(
"nov"
,
stat
,
"SELECT TO_CHAR(X, 'mon') FROM T"
);
assertResult
(
"NOVEMBER "
,
stat
,
"SELECT TO_CHAR(X, 'MONTH') FROM T"
);
assertResult
(
"November "
,
stat
,
"SELECT TO_CHAR(X, 'Month') FROM T"
);
assertResult
(
"november "
,
stat
,
"SELECT TO_CHAR(X, 'month') FROM T"
);
assertResult
(
"November"
,
stat
,
"SELECT TO_CHAR(X, 'fmMonth') FROM T"
);
expected
=
String
.
format
(
"%1$tb"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
expected
.
substring
(
0
,
1
).
toUpperCase
()
+
expected
.
substring
(
1
);
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'MON') FROM T"
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'Mon') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'mon') FROM T"
);
expected
=
String
.
format
(
"%1$tB"
,
Timestamp
.
valueOf
(
"1979-11-12 08:12:34.560"
));
expected
=
(
expected
+
" "
).
substring
(
0
,
9
);
assertResult
(
expected
.
toUpperCase
(),
stat
,
"SELECT TO_CHAR(X, 'MONTH') FROM T"
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'Month') FROM T"
);
assertResult
(
expected
.
toLowerCase
(),
stat
,
"SELECT TO_CHAR(X, 'month') FROM T"
);
assertResult
(
expected
.
trim
(),
stat
,
"SELECT TO_CHAR(X, 'fmMonth') FROM T"
);
assertResult
(
"4"
,
stat
,
"SELECT TO_CHAR(X, 'Q') FROM T"
);
assertResult
(
"XI"
,
stat
,
"SELECT TO_CHAR(X, 'RM') FROM T"
);
assertResult
(
"xi"
,
stat
,
"SELECT TO_CHAR(X, 'rm') FROM T"
);
...
...
@@ -1368,8 +1397,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"8:12:34 AM"
,
stat
,
"SELECT TO_CHAR(X, 'TS') FROM T"
);
assertResult
(
tzLongName
,
stat
,
"SELECT TO_CHAR(X, 'TZR') FROM T"
);
assertResult
(
tzShortName
,
stat
,
"SELECT TO_CHAR(X, 'TZD') FROM T"
);
assertResult
(
"."
,
stat
,
"SELECT TO_CHAR(X, 'X') FROM T"
);
assertResult
(
"1,979"
,
stat
,
"SELECT TO_CHAR(X, 'Y,YYY') FROM T"
);
expected
=
String
.
format
(
"%f"
,
1.1
).
substring
(
1
,
2
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'X') FROM T"
);
expected
=
String
.
format
(
"%,d"
,
1979
);
assertResult
(
expected
,
stat
,
"SELECT TO_CHAR(X, 'Y,YYY') FROM T"
);
assertResult
(
"1979"
,
stat
,
"SELECT TO_CHAR(X, 'YYYY') FROM T"
);
assertResult
(
"1979"
,
stat
,
"SELECT TO_CHAR(X, 'SYYYY') FROM T"
);
assertResult
(
"-0100"
,
stat
,
"SELECT TO_CHAR(X, 'SYYYY') FROM U"
);
...
...
@@ -1377,7 +1408,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertResult
(
"79"
,
stat
,
"SELECT TO_CHAR(X, 'YY') FROM T"
);
assertResult
(
"9"
,
stat
,
"SELECT TO_CHAR(X, 'Y') FROM T"
);
assertResult
(
"7979"
,
stat
,
"SELECT TO_CHAR(X, 'yyfxyy') FROM T"
);
assertThrows
(
""
,
stat
,
"SELECT TO_CHAR(X, 'A') FROM T"
);
assertThrows
(
ErrorCode
.
INVALID_TO_CHAR_FORMAT
,
stat
,
"SELECT TO_CHAR(X, 'A') FROM T"
);
// check a bug we had when the month or day of the month is 1 digit
stat
.
executeUpdate
(
"TRUNCATE TABLE T"
);
...
...
@@ -1608,11 +1640,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
"SELECT TO_CHAR(123456789012345, 'TME') FROM DUAL"
);
assertResult
(
"4.5E-01"
,
stat
,
"SELECT TO_CHAR(0.45, 'TME') FROM DUAL"
);
assertResult
(
"4.5E-01"
,
stat
,
"SELECT TO_CHAR(0.45, 'tMe') FROM DUAL"
);
assertThrows
(
"Invalid TO_CHAR format \"999.99q\""
,
stat
,
assertThrows
(
ErrorCode
.
INVALID_TO_CHAR_FORMAT
,
stat
,
"SELECT TO_CHAR(123.45, '999.99q') FROM DUAL"
);
assertThrows
(
"Invalid TO_CHAR format \"fm999.99q\""
,
stat
,
assertThrows
(
ErrorCode
.
INVALID_TO_CHAR_FORMAT
,
stat
,
"SELECT TO_CHAR(123.45, 'fm999.99q') FROM DUAL"
);
assertThrows
(
"Invalid TO_CHAR format \"q999.99\""
,
stat
,
assertThrows
(
ErrorCode
.
INVALID_TO_CHAR_FORMAT
,
stat
,
"SELECT TO_CHAR(123.45, 'q999.99') FROM DUAL"
);
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestRights.java
浏览文件 @
4ec6e3bf
...
...
@@ -145,10 +145,10 @@ public class TestRights extends TestBase {
stat
.
execute
(
"insert into test3 values (1)"
);
stat
.
execute
(
"insert into test4 values (1)"
);
// Must not proceed
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST1\""
,
stat
,
"select * from test1"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST2\""
,
stat
,
"select * from test2"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST3\""
,
stat
,
"select * from test3"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST4\""
,
stat
,
"select * from test4"
);
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test1"
);
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test2"
);
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test3"
);
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test4"
);
// Test with role
statAdmin
.
execute
(
"create role test_role"
);
...
...
@@ -199,13 +199,13 @@ public class TestRights extends TestBase {
statAdmin
.
execute
(
"create table test4(id int)"
);
// Must not proceed
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST1\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"insert into test1 values (2)"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST2\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"insert into test2 values (2)"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST3\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"insert into test3 values (2)"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST4\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"insert into test4 values (2)"
);
// Test with role
...
...
@@ -223,15 +223,15 @@ public class TestRights extends TestBase {
statAdmin
.
execute
(
"create table test5(id int)"
);
// Must not proceed
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST1\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test1"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST2\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test2"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST3\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test3"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST4\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test4"
);
assertThrows
(
"Not enough rights for object \"PUBLIC.TEST5\""
,
assertThrows
(
ErrorCode
.
NOT_ENOUGH_RIGHTS_FOR_1
,
stat
,
"select * from test5"
);
conn
.
close
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论