Audacity 3.2.0
SQliteHelpersTests.cpp
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * SPDX-FileName: SQliteHelpersTests.cpp
4 * SPDX-FileContributor: Dmitry Vedenko
5 */
6
7#include <catch2/catch.hpp>
8
9#include "sqlite/Connection.h"
10
11TEST_CASE("SQLiteHelpers", "")
12{
13 using namespace audacity::sqlite;
14
15 auto connection = Connection::Open(":memory:", OpenMode::Memory);
16 REQUIRE(connection);
17 REQUIRE(connection->CheckTableExists("test") == false);
18 REQUIRE(!!connection->Execute(
19 "CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT);"));
20 REQUIRE(connection->CheckTableExists("test") == true);
21 REQUIRE(!!connection->Execute("INSERT INTO test (name) VALUES ('test1');"));
22
23 {
24 auto stmt =
25 connection->CreateStatement("INSERT INTO test (name) VALUES (?);");
26
27 REQUIRE(stmt);
28 auto& ctx = stmt->Prepare();
29 ctx.Bind(1, "test2");
30 auto run1 = ctx.Run();
31 REQUIRE(run1.IsOk());
32 REQUIRE(run1.HasRows() == false);
33
34 ctx.Bind(1, "test3");
35 auto run2 = ctx.Run();
36 REQUIRE(run2.IsOk());
37 REQUIRE(run2.HasRows() == false);
38 }
39
40 {
41 auto stmt = connection->CreateStatement("SELECT * FROM test;");
42
43 REQUIRE(stmt);
44 auto run = stmt->Prepare().Run();
45
46 REQUIRE(run.IsOk());
47 REQUIRE(run.HasRows() == true);
48
49 int rowId = 1;
50
51 for (auto row : run)
52 {
53 int id;
54 std::string name;
55
56 REQUIRE(row.Get(0, id));
57 REQUIRE(row.Get(1, name));
58 REQUIRE(!row.Get(2, id));
59
60 REQUIRE(rowId == id);
61 REQUIRE(name == "test" + std::to_string(rowId));
62
63 ++rowId;
64 }
65
66 REQUIRE(rowId == 4);
67 }
68}
const TranslatableString name
Definition: Distortion.cpp:76
TEST_CASE("SQLiteHelpers", "")
int id