1#include "catch.hpp"
2#include "duckdb/common/file_system.hpp"
3#include "duckdb/storage/storage_manager.hpp"
4#include "test_helpers.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9static void test_in_memory_initialization(string dbdir) {
10 FileSystem fs;
11 unique_ptr<DuckDB> db;
12 string in_memory_tmp = ".tmp";
13
14 // make sure the temporary folder does not exist
15 DeleteDatabase(dbdir);
16 fs.RemoveDirectory(in_memory_tmp);
17
18 // cannot create an in-memory database using ":memory:" argument
19 REQUIRE_NOTHROW(db = make_unique<DuckDB>(dbdir));
20
21 // WAL is not null, which indicates that data is being persisted somewhere
22 REQUIRE(db->storage->GetWriteAheadLog() == 0);
23
24 // the temporary folder .tmp should be created in in-memory mode, but was not
25 REQUIRE(fs.DirectoryExists(in_memory_tmp));
26
27 // the database dir should not be created in in-memory mode, but was
28 REQUIRE(!fs.DirectoryExists(dbdir));
29
30 // clean up
31 db.reset();
32
33 // make sure to clean up the database & temporary folder
34 DeleteDatabase(dbdir);
35 fs.RemoveDirectory(in_memory_tmp);
36}
37
38TEST_CASE("Test in-memory database initialization argument \":memory:\"", "[api]") {
39 test_in_memory_initialization(":memory:");
40}
41
42TEST_CASE("Test in-memory database initialization argument \"\"", "[api]") {
43 test_in_memory_initialization("");
44}
45