FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlancer/test/sqlancer/TestStateToReproduce.java at main · sqlancer/sqlancer · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sqlancer
/
sqlancer
Public
Notifications
You must be signed in to change notification settings
Fork
398
Star
1.8k
Code
Issues
80
Pull requests
60
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlancer
/
test
/
sqlancer
/
TestStateToReproduce.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (84 loc) · 4.19 KB
Breadcrumbs
sqlancer
/
test
/
sqlancer
/
TestStateToReproduce.java
Copy path
File metadata and controls
109 lines (84 loc) · 4.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package
sqlancer
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
java
.
io
.
IOException
;
import
java
.
nio
.
file
.
Path
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
org
.
junit
.
jupiter
.
api
.
Test
;
import
org
.
junit
.
jupiter
.
api
.
io
.
TempDir
;
import
sqlancer
.
common
.
query
.
ExpectedErrors
;
import
sqlancer
.
common
.
query
.
Query
;
import
sqlancer
.
common
.
query
.
SQLQueryAdapter
;
import
sqlancer
.
sqlite3
.
SQLite3Provider
;
public
class
TestStateToReproduce
{
@
TempDir
Path
tempDir
;
@
Test
public
void
testBasicFields
()
throws
IOException
{
SQLite3Provider
provider
=
new
SQLite3Provider
();
StateToReproduce
state
=
new
StateToReproduce
(
"test_db"
,
provider
);
state
.
databaseVersion
=
"3.36.0"
;
state
.
seedValue
=
12345L
;
state
.
exception
=
"Test exception message"
;
Path
file
=
tempDir
.
resolve
(
"test_basic.ser"
);
state
.
serialize
(
file
);
StateToReproduce
result
=
StateToReproduce
.
deserialize
(
file
);
assertEquals
(
state
.
getDatabaseName
(),
result
.
getDatabaseName
());
assertEquals
(
state
.
getDatabaseVersion
(),
result
.
getDatabaseVersion
());
assertEquals
(
state
.
getSeedValue
(),
result
.
getSeedValue
());
assertEquals
(
state
.
getException
(),
result
.
getException
());
}
@
Test
public
void
testStatements
()
throws
IOException
{
SQLite3Provider
provider
=
new
SQLite3Provider
();
StateToReproduce
state
=
new
StateToReproduce
(
"test_statements"
,
provider
);
List
<
Query
<?>>
statements
=
new
ArrayList
<>();
ExpectedErrors
errors1
=
new
ExpectedErrors
();
errors1
.
add
(
"syntax error"
);
errors1
.
add
(
"table already exists"
);
statements
.
add
(
new
SQLQueryAdapter
(
"CREATE TABLE test (id INTEGER);"
,
errors1
));
ExpectedErrors
errors2
=
new
ExpectedErrors
();
errors2
.
add
(
"constraint failed"
);
statements
.
add
(
new
SQLQueryAdapter
(
"INSERT INTO test VALUES (1);"
,
errors2
));
statements
.
add
(
new
SQLQueryAdapter
(
"SELECT * FROM test;"
,
new
ExpectedErrors
()));
state
.
setStatements
(
statements
);
Path
file
=
tempDir
.
resolve
(
"test_statements.ser"
);
state
.
serialize
(
file
);
StateToReproduce
result
=
StateToReproduce
.
deserialize
(
file
);
List
<
Query
<?>>
resultStatements
=
result
.
getStatements
();
assertEquals
(
3
,
resultStatements
.
size
());
Query
<?>
q1
=
resultStatements
.
get
(
0
);
Query
<?>
q2
=
resultStatements
.
get
(
1
);
Query
<?>
q3
=
resultStatements
.
get
(
2
);
assertEquals
(
"CREATE TABLE test (id INTEGER);"
,
q1
.
getLogString
());
assertEquals
(
"INSERT INTO test VALUES (1);"
,
q2
.
getLogString
());
assertEquals
(
"SELECT * FROM test;"
,
q3
.
getLogString
());
ExpectedErrors
e1
=
q1
.
getExpectedErrors
();
ExpectedErrors
e2
=
q2
.
getExpectedErrors
();
ExpectedErrors
e3
=
q3
.
getExpectedErrors
();
assertTrue
(
e1
.
errorIsExpected
(
"syntax error"
));
assertTrue
(
e1
.
errorIsExpected
(
"table already exists"
));
assertFalse
(
e1
.
errorIsExpected
(
"constraint failed"
));
assertFalse
(
e2
.
errorIsExpected
(
"syntax error"
));
assertTrue
(
e2
.
errorIsExpected
(
"constraint failed"
));
assertFalse
(
e3
.
errorIsExpected
(
"syntax error"
));
assertFalse
(
e3
.
errorIsExpected
(
"constraint failed"
));
}
@
Test
public
void
testDatabaseProvider
()
throws
IOException
{
SQLite3Provider
provider
=
new
SQLite3Provider
();
StateToReproduce
state
=
new
StateToReproduce
(
"test_provider"
,
provider
);
state
.
logStatement
(
"CREATE TABLE test (id INTEGER);"
);
Path
file
=
tempDir
.
resolve
(
"test_provider.ser"
);
state
.
serialize
(
file
);
StateToReproduce
result
=
StateToReproduce
.
deserialize
(
file
);
// Verify databaseProvider is correctly deserialized
assertEquals
(
"sqlite3"
,
result
.
getDatabaseProvider
().
getDBMSName
());
// Verify databaseProvider functionality by testing logStatement
result
.
logStatement
(
"INSERT INTO test VALUES (1);"
);
assertEquals
(
2
,
result
.
getStatements
().
size
());
assertEquals
(
"INSERT INTO test VALUES (1);"
,
result
.
getStatements
().
get
(
1
).
getLogString
());
}
}
Back
|
FazBrowse Home
|
New Git URL