Audacity 3.2.0
Functions
SQliteHelpersTests.cpp File Reference
#include <catch2/catch.hpp>
#include "sqlite/Connection.h"
Include dependency graph for SQliteHelpersTests.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("SQLiteHelpers", "")
 

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "SQLiteHelpers"  ,
""   
)

Definition at line 11 of file SQliteHelpersTests.cpp.

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}
wxString name
Definition: TagsEditor.cpp:166
int id

References id, and name.