1#include "catch.hpp"
2#include "duckdb/common/file_system.hpp"
3#include "test_helpers.hpp"
4
5using namespace duckdb;
6using namespace std;
7
8TEST_CASE("Test functioning of checksum", "[storage]") {
9 FileSystem fs;
10 unique_ptr<DuckDB> database;
11 auto storage_database = TestCreatePath("checksum_test");
12 auto config = GetTestConfig();
13
14 // make sure the database does not exist
15 DeleteDatabase(storage_database);
16 {
17 // create a database and insert values
18 DuckDB db(storage_database, config.get());
19 Connection con(db);
20 REQUIRE_NO_FAIL(con.Query("CREATE TABLE test(a INTEGER);"));
21 REQUIRE_NO_FAIL(con.Query("INSERT INTO test VALUES (3);"));
22 }
23 // we can open the database file now
24 REQUIRE_NOTHROW(database = make_unique<DuckDB>(storage_database, config.get()));
25 database.reset();
26
27 // now write random values into the file
28 auto handle = fs.OpenFile(storage_database, FileFlags::WRITE);
29 int8_t value = 0x22;
30 fs.Write(*handle, &value, sizeof(int8_t), 100);
31 handle->Sync();
32 handle.reset();
33 // reloading the database no longer works
34 REQUIRE_THROWS(database = make_unique<DuckDB>(storage_database, config.get()));
35
36 DeleteDatabase(storage_database);
37}
38