Class DatabaseConformanceSuite
The portable acceptance test for com.codename1.db.
One set of assertions, run unchanged on every platform. A port is conformant when this suite passes against it; there is no separate, per-platform notion of correct behaviour. It lives in the framework rather than in a test project so that the device suite, the simulator unit tests and anyone writing a new port can all run the same checks.
Failures are reported through a Reporter rather than thrown, so a single run reports every
violation instead of stopping at the first. That matters most when bringing up a new port,
where the useful output is the whole list.
DatabaseConformanceSuite.runAll("conformance.db",
DatabaseConformanceSuite.MODE_STRICT, myReporter);
Modes
#MODE_STRICT asserts the contract documented in the com.codename1.db package. #MODE_LEGACY
asserts that Database#setLegacyBehavior(boolean) really does restore what each platform used
to do, which is what makes the compatibility promise testable rather than aspirational. Run the
legacy mode only with the flag actually set.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceReceives the outcome of each individual check. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAssert that legacy compatibility mode restores the previous per-platform behaviour.static final intAssert the portable contract.static final intThe Android port.static final intNot overridden; the port is read from the runningDisplay.static final intThe iOS port, which has the most legacy behaviour to restore.static final intA port with no legacy behaviour of its own to restore.static final intThe simulator, whosegetPosition()used to be 1-based. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReports whether this platform provides a database at all.static voidrunAll(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) Runs every group against a scratch database.static voidrunCursor(Database db, int mode, DatabaseConformanceSuite.Reporter r) Checks cursor navigation, positions, metadata and null reads.static voidrunEncryption(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) Checks encrypted opens, the wrong-key path and the on-disk result.static voidrunLifecycle(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) Checks opening, existence, deletion, paths and use-after-close.static voidrunStatements(Database db, int mode, DatabaseConformanceSuite.Reporter r) Checks statement execution, parameter binding and error reporting.static voidrunTransactions(Database db, int mode, DatabaseConformanceSuite.Reporter r) Checks commit, rollback and the flat transaction rules.static voidsetPortKind(int portKind) Declares which port the suite is being run against, for a harness with noDisplay.
-
Field Details
-
MODE_STRICT
public static final int MODE_STRICTAssert the portable contract.- See Also:
-
MODE_LEGACY
public static final int MODE_LEGACYAssert that legacy compatibility mode restores the previous per-platform behaviour.- See Also:
-
PORT_OTHER
public static final int PORT_OTHERA port with no legacy behaviour of its own to restore.- See Also:
-
PORT_SIMULATOR
public static final int PORT_SIMULATORThe simulator, whosegetPosition()used to be 1-based.- See Also:
-
PORT_IOS
public static final int PORT_IOSThe iOS port, which has the most legacy behaviour to restore.- See Also:
-
PORT_ANDROID
public static final int PORT_ANDROIDThe Android port.- See Also:
-
PORT_AUTODETECT
public static final int PORT_AUTODETECTNot overridden; the port is read from the runningDisplay.- See Also:
-
-
Method Details
-
setPortKind
public static void setPortKind(int portKind) Declares which port the suite is being run against, for a harness with no
Display.Pass
#PORT_AUTODETECTto go back to reading it fromDisplay, which is what an on-device harness wants. This is global state, so a harness that sets it should reset it afterwards.Parameters
portKind: one of thePORT_constants
-
runAll
public static void runAll(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Runs every group against a scratch database.
The database is created and deleted by this method, so pass a name the application does not otherwise use.
Parameters
-
databaseName: a scratch database name -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch database cannot be created at all
- Throws:
IOException
-
-
isDatabaseAvailable
Reports whether this platform provides a database at all.
Ports without an implementation return null from
Database#openOrCreate(java.lang.String). Callers use this to skip cleanly rather than fail.Parameters
r: receives a skip message when there is no database
Returns
true when a database can be opened
-
runLifecycle
public static void runLifecycle(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Checks opening, existence, deletion, paths and use-after-close.
Parameters
-
databaseName: a scratch database name -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch database cannot be created
- Throws:
IOException
-
-
runStatements
public static void runStatements(Database db, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Checks statement execution, parameter binding and error reporting.
Parameters
-
db: an open database, left usable -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch table cannot be created
- Throws:
IOException
-
-
runCursor
public static void runCursor(Database db, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Checks cursor navigation, positions, metadata and null reads.
Parameters
-
db: an open database, left usable -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch table cannot be created
- Throws:
IOException
-
-
runTransactions
public static void runTransactions(Database db, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Checks commit, rollback and the flat transaction rules.
Parameters
-
db: an open database, left usable -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch table cannot be created
- Throws:
IOException
-
-
runEncryption
public static void runEncryption(String databaseName, int mode, DatabaseConformanceSuite.Reporter r) throws IOException Checks encrypted opens, the wrong-key path and the on-disk result.
Parameters
-
databaseName: a scratch database name, created and deleted here -
mode:#MODE_STRICTor#MODE_LEGACY -
r: receives the results
Throws
IOException: if the scratch database cannot be created
- Throws:
IOException
-
-