<commit_before>#include "catch/catch.hpp"
#include "SQLiteXX.h"

#include <string>
#include <utility>
#include <vector>

TEST_CASE("Combinations of OpenMode flags with new database", "[DBConnection]") {
    remove("testDBConnection.db");

    SECTION("Open file as read only but file does not exist") {
        REQUIRE_THROWS_AS(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadOnly), SQLite::Exception);
    }

    SECTION("Open and create file with ReadOnly") {
        REQUIRE_THROWS_AS(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadOnly | SQLite::OpenMode::Create), SQLite::Exception);
    }

    SECTION("Open and create file with ReadWrite") {
        REQUIRE_NOTHROW(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create));
    }

    SECTION("Open, create, and write to file") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create);

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}

TEST_CASE("Combinations of OpenMode flags with already existing database", "[DBConnection]") {
    remove("testDBConnection.db");
    {
        SQLite::DBConnection connection("testDBConnection.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("Open ReadOnly") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadOnly);

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);

        REQUIRE_THROWS_AS(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"), SQLite::Exception);
    }

    SECTION("Open ReadWrite") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite);

        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"two\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("Open ReadWrite and Create") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create);

        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"two\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}

TEST_CASE("Combinations of OpenMode mutex flags", "[DBConnection]") {
    remove("testDBConnection.db");

    SECTION("Opening database with no Mutex") {
        SQLite::DBConnection connection(
            "testDBConnection.db",
            SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create | SQLite::OpenMode::NoMutex);

        REQUIRE_THROWS_AS(connection.getMutex(), SQLite::SQLiteXXException);
    }
}

TEST_CASE("DBConnection UTF8 Support", "[DBConnection]") {
    remove("testDBConnection_utf8.db");

    SECTION("Memory database") {
        SQLite::DBConnection connection = SQLite::DBConnection::wideMemory();

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("File database using open") {
        SQLite::DBConnection connection;
        connection.open(L"testDBConnection_utf8.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("File database from contructor") {
        SQLite::DBConnection connection(L"testDBConnection_utf8.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}
<commit_msg>Fixed using wrong string literals for UTF16<commit_after>#include "catch/catch.hpp"
#include "SQLiteXX.h"

#include <string>
#include <utility>
#include <vector>

TEST_CASE("Combinations of OpenMode flags with new database", "[DBConnection]") {
    remove("testDBConnection.db");

    SECTION("Open file as read only but file does not exist") {
        REQUIRE_THROWS_AS(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadOnly), SQLite::Exception);
    }

    SECTION("Open and create file with ReadOnly") {
        REQUIRE_THROWS_AS(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadOnly | SQLite::OpenMode::Create), SQLite::Exception);
    }

    SECTION("Open and create file with ReadWrite") {
        REQUIRE_NOTHROW(SQLite::DBConnection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create));
    }

    SECTION("Open, create, and write to file") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create);

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}

TEST_CASE("Combinations of OpenMode flags with already existing database", "[DBConnection]") {
    remove("testDBConnection.db");
    {
        SQLite::DBConnection connection("testDBConnection.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("Open ReadOnly") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadOnly);

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);

        REQUIRE_THROWS_AS(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"), SQLite::Exception);
    }

    SECTION("Open ReadWrite") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite);

        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"two\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("Open ReadWrite and Create") {
        SQLite::DBConnection connection("testDBConnection.db", SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create);

        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"two\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}

TEST_CASE("Combinations of OpenMode mutex flags", "[DBConnection]") {
    remove("testDBConnection.db");

    SECTION("Opening database with no Mutex") {
        SQLite::DBConnection connection(
            "testDBConnection.db",
            SQLite::OpenMode::ReadWrite | SQLite::OpenMode::Create | SQLite::OpenMode::NoMutex);

        REQUIRE_THROWS_AS(connection.getMutex(), SQLite::SQLiteXXException);
    }
}

TEST_CASE("DBConnection UTF8 Support", "[DBConnection]") {
    remove("testDBConnection_utf16.db");

    SECTION("Memory database") {
        SQLite::DBConnection connection = SQLite::DBConnection::wideMemory();

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("File database using open") {
        SQLite::DBConnection connection;
        connection.open(u"testDBConnection_utf16.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }

    SECTION("File database from contructor") {
        SQLite::DBConnection connection(u"testDBConnection_utf16.db");

        REQUIRE_NOTHROW(Execute(connection, "CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
        REQUIRE_NOTHROW(Execute(connection, "INSERT INTO test VALUES (NULL, \"one\")"));

        SQLite::Statement query(connection, "SELECT * FROM test");
        REQUIRE(query.getColumnCount() == 2);
    }
}

{'fraction_non_alphanumeric': 0.14004007170726562, 'fraction_numerical': 0.0030581039755351682, 'mean_word_length': 4.1967123287671235, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '220903', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2742, 'n_words': 600}