forked from google/oss-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestServer.java
85 lines (70 loc) · 2.08 KB
/
TestServer.java
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
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh;
import org.hsqldb.server.Server;
import org.hsqldb.server.ServerConstants;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
public abstract class TestServer extends Server implements AutoCloseable {
private PrintWriter m_stderr = null;
private PrintWriter m_stdout = null;
TestServer(boolean verbose) {
super();
setVerbose(verbose);
setDatabaseName(0, getTestName());
setDatabasePath(0, "mem:" + getTestName());
start();
try {
createTestTable();
} catch(SQLException ex) {
/* cannot happen? */
}
}
void createTestTable() throws SQLException {
try (Connection connection = getConnection()) {
Statement statement = connection.createStatement();
statement.execute("DROP TABLE TestTable IF EXISTS");
statement.execute("CREATE TABLE TestTable (key INTEGER, value VARCHAR(256))");
statement.execute("INSERT INTO TestTable VALUES ((0, \"Hello\"),(1, \"World\"))");
}
}
public void close() throws Exception {
stop();
}
protected void setVerbose(boolean verbose) {
if (verbose) {
m_stderr = new PrintWriter(System.err);
m_stdout = new PrintWriter(System.out);
} else {
m_stderr = null;
m_stdout = null;
}
this.setErrWriter(m_stderr);
this.setLogWriter(m_stdout);
}
public int stop() {
int retval = super.stop();
/*
* polling [...]
*/
while (getState() == ServerConstants.SERVER_STATE_CLOSING) {
Thread.yield();
}
return retval;
}
Connection getConnection(String options) throws SQLException {
return DriverManager.getConnection("jdbc:hsqldb:mem:" + getTestName() + ";" + options, "sa", "");
}
Connection getConnection() throws SQLException {
return getConnection("");
}
String getTestName() {
return getClass().getSimpleName();
}
abstract void testOneInput(String fuzzyString);
}