Skip to content

Commit

Permalink
Overall cleanup as suggested by clang-tidy :)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <[email protected]>
  • Loading branch information
christianparpart committed Feb 2, 2025
1 parent dd0579c commit f77d564
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Lightweight/SqlConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ bool SqlConnection::IsAlive() const noexcept
return SQL_SUCCEEDED(sqlResult) && state == SQL_CD_FALSE;
}

void SqlConnection::RequireSuccess(SQLRETURN error, std::source_location sourceLocation) const
void SqlConnection::RequireSuccess(SQLRETURN sqlResult, std::source_location sourceLocation) const
{
if (SQL_SUCCEEDED(error))
if (SQL_SUCCEEDED(sqlResult))
return;

auto errorInfo = LastError();
Expand Down
2 changes: 1 addition & 1 deletion src/Lightweight/SqlError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SqlException::SqlException(SqlErrorInfo info, std::source_location sourceLocatio
std::runtime_error(std::format("{}", info)),
_info { std::move(info) }
{
SqlLogger::GetLogger().OnError(info, sourceLocation);
SqlLogger::GetLogger().OnError(_info, sourceLocation);
}

void SqlErrorInfo::RequireStatementSuccess(SQLRETURN result, SQLHSTMT hStmt, std::string_view message)
Expand Down
5 changes: 2 additions & 3 deletions src/Lightweight/SqlSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace
case SQL_WLONGVARCHAR: return NVarchar { size };
case SQL_WVARCHAR: return NVarchar { size };
// case SQL_UNKNOWN_TYPE:
default:
default:
SqlLogger::GetLogger().OnError(SqlError::UNSUPPORTED_TYPE);
throw std::runtime_error(std::format("Unsupported data type: {}", value));
}
Expand Down Expand Up @@ -276,8 +276,7 @@ void ReadAllTables(std::string_view database, std::string_view schema, EventHand
std::string ToLowerCase(std::string_view str)
{
std::string result(str);
std::transform(
result.begin(), result.end(), result.begin(), [](char c) { return static_cast<char>(std::tolower(c)); });
std::ranges::transform(result, result.begin(), [](char c) { return static_cast<char>(std::tolower(c)); });
return result;
}

Expand Down
5 changes: 5 additions & 0 deletions src/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class SqlTestFixture
DropAllTablesInDatabase();
}

SqlTestFixture(SqlTestFixture&&) = delete;
SqlTestFixture(SqlTestFixture const&) = delete;
SqlTestFixture& operator=(SqlTestFixture&&) = delete;
SqlTestFixture& operator=(SqlTestFixture const&) = delete;

virtual ~SqlTestFixture() = default;

private:
Expand Down
10 changes: 9 additions & 1 deletion src/tests/CoreTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST_CASE_METHOD(SqlTestFixture, "SqlStatement: ctor std::nullopt")
// Get `stmt` valid by assigning it a valid SqlStatement
stmt = SqlStatement {};
REQUIRE(stmt.IsAlive());
CHECK(stmt.ExecuteDirectScalar<int>("SELECT 42").value() == 42);
CHECK(stmt.ExecuteDirectScalar<int>("SELECT 42").value_or(-1) == 42);
}

TEST_CASE_METHOD(SqlTestFixture, "select: get columns")
Expand All @@ -69,6 +69,8 @@ TEST_CASE_METHOD(SqlTestFixture, "select: get columns")

TEST_CASE_METHOD(SqlTestFixture, "move semantics", "[SqlConnection]")
{
// NOLINTBEGIN(bugprone-use-after-move,clang-analyzer-cplusplus.Move)

auto a = SqlConnection {};
CHECK(a.IsAlive());

Expand All @@ -80,10 +82,14 @@ TEST_CASE_METHOD(SqlTestFixture, "move semantics", "[SqlConnection]")
CHECK(!a.IsAlive());
CHECK(!b.IsAlive());
CHECK(c.IsAlive());

// NOLINTEND(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
}

TEST_CASE_METHOD(SqlTestFixture, "move semantics", "[SqlStatement]")
{
// NOLINTBEGIN(bugprone-use-after-move,clang-analyzer-cplusplus.Move)

auto conn = SqlConnection {};

auto const TestRun = [](SqlStatement& stmt) {
Expand All @@ -107,6 +113,8 @@ TEST_CASE_METHOD(SqlTestFixture, "move semantics", "[SqlStatement]")
CHECK(!b.IsAlive());
CHECK(c.IsAlive());
TestRun(c);

// NOLINTEND(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
}

TEST_CASE_METHOD(SqlTestFixture, "select: get column (invalid index)")
Expand Down
5 changes: 3 additions & 2 deletions src/tests/DataBinderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace std

std::ostream& operator<<(std::ostream& os, std::u8string const& value)
{
return os << std::format("\"{}\"", (char const*) value.c_str());
return os << std::format("\"{}\"", value);
}

std::ostream& operator<<(std::ostream& os, std::u8string_view value)
Expand Down Expand Up @@ -242,6 +242,7 @@ TEST_CASE_METHOD(SqlTestFixture, "SqlVariant: SqlDate", "[SqlDataBinder],[SqlVar

using namespace std::chrono_literals;
auto const expected = SqlVariant { SqlDate { 2017y, std::chrono::August, 16d } };
auto const& expectedDateTime = std::get<SqlDate>(expected.value);

stmt.Prepare(stmt.Query("Test").Insert().Set("Value", SqlWildcard));
stmt.Execute(expected);
Expand All @@ -251,7 +252,7 @@ TEST_CASE_METHOD(SqlTestFixture, "SqlVariant: SqlDate", "[SqlDataBinder],[SqlVar
auto reader = stmt.GetResultCursor();
(void) stmt.FetchRow();
auto const actual = reader.GetColumn<SqlVariant>(1);
CHECK(actual.TryGetDate().value() == std::get<SqlDate>(expected.value));
CHECK(actual.TryGetDate().value_or(SqlDate {}) == expectedDateTime);
}

// Test for inserting/getting NULL values
Expand Down
4 changes: 4 additions & 0 deletions src/tests/DataMapperTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using namespace std::string_view_literals;

// NOLINTBEGIN(bugprone-unchecked-optional-access)

std::ostream& operator<<(std::ostream& os, RecordId const& id)
{
return os << id.value;
Expand Down Expand Up @@ -880,3 +882,5 @@ TEST_CASE_METHOD(SqlTestFixture, "Test DifferenceView", "[DataMapper]")
// 3 because of the auto-assigned GUID on top of name and age
CHECK(differenceCount == 3);
}

// NOLINTEND(bugprone-unchecked-optional-access)
4 changes: 4 additions & 0 deletions src/tests/MigrationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class SqlMigrationTestFixture: public SqlTestFixture
{
SqlMigration::MigrationManager::GetInstance().RemoveAllMigrations();
}
SqlMigrationTestFixture(SqlMigrationTestFixture&&) = delete;
SqlMigrationTestFixture(SqlMigrationTestFixture const&) = delete;
SqlMigrationTestFixture& operator=(SqlMigrationTestFixture&&) = delete;
SqlMigrationTestFixture& operator=(SqlMigrationTestFixture const&) = delete;

~SqlMigrationTestFixture() override
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ddl2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ int main(int argc, char const* argv[])
std::println("{}", printer.str(config.modelNamespace));
else
{
auto file = std::ofstream(config.outputFileName.data());
auto file = std::ofstream(config.outputFileName.data()); // NOLINT(bugprone-suspicious-stringview-data-usage)
file << printer.str(config.modelNamespace);
}

Expand Down

0 comments on commit f77d564

Please sign in to comment.