Files
torstenandCopilot 342ffd3e5c Update submodule to latest BUILD_RTI fixes
- HandlerMinelayerData: BUILD_RTI Guards für RTI-Abhängigkeiten
- svcTabCommon: Export-Header-Fix via Fallback-Target
- TrainingAreaBase: Stub-Header für BUILD_RTI=OFF
- ddsfts: Include-Pfad und Dependency-Fixes
- BUILD_RTI=OFF Compilation vollständig unterstützt

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 01M0JNZA586SACX1PRZ2DJAE5S
2026-08-21 19:30:20 +02:00

215 lines
6.4 KiB
C++

/*
(c) Copyright, Real-Time Innovations, 2023-.
All rights reserved.
No duplications, whole or partial, manual or electronic, may be made
without express written permission. Any such copies, or
revisions thereof, must display this notice unaltered.
This code contains trade secrets of Real-Time Innovations, Inc.
*/
#ifndef HPP_APPUTILS_SQLITEVERIFIER_HPP_
#define HPP_APPUTILS_SQLITEVERIFIER_HPP_
#include "rti/apputils/SQLiteConnection.hpp"
#include "rti/apputils/test/TestFramework.hpp"
#include "rti/util/util.hpp"
#include "rti/recording/storage/EStorageFormat.hpp"
namespace rti { namespace apputils { namespace test {
/**
* @brief Basic utility class with different checks for an SQLite Connection.
*/
class SQLiteVerifierBase {
public:
SQLiteVerifierBase(rti::apputils::SQLiteConnection& connection) :
connection_(connection) { }
bool check_table_exists(const std::string& table)
{
std::ostringstream string_stream;
string_stream << "SELECT name FROM sqlite_master WHERE name = '";
string_stream << table;
string_stream << "'";
rti::apputils::SQLiteConnection::RowIterator row_it =
connection_.begin(string_stream.str());
if (!row_it.at_end()) {
return true;
}
return false;
}
bool wait_till_table_exists(
const std::string& table,
const unsigned int seconds = DEFAULT_TEST_TIMEOUT_SEC)
{
bool exists = check_table_exists(table);
dds::core::Duration sleepDuration(1,0);
for (uint32_t i = 0; i < seconds && !exists; i++) {
rti::util::sleep(sleepDuration);
exists = check_table_exists(table);
}
if (!exists) {
RTITestLogger_log(
RTI_LOG_BIT_EXCEPTION,
&RTI_TEST_LOG_FAILURE_TEMPLATE,
"Table not found: %s",
table.c_str());
}
return exists;
}
bool check_column_exists(
const std::string& table,
const std::string& column)
{
std::ostringstream string_stream;
string_stream << "PRAGMA table_info([" << table << "])";
rti::apputils::SQLiteConnection::RowIterator row_it =
connection_.begin(string_stream.str());
while (!row_it.at_end()) {
std::string column_name;
row_it.get(1, column_name);
if (column_name.compare(column) == 0) {
return true;
}
++row_it;
}
return false;
}
uint32_t num_rows_for_statement(const std::string& sql)
{
rti::apputils::SQLiteConnection::RowIterator row_it =
connection_.begin(sql);
uint32_t row_count = 0;
while (!row_it.at_end()) {
row_count++;
++row_it;
}
return row_count;
}
/**
* @pre check_table_exists(table) == true
*/
uint32_t num_rows(
const std::string& table,
const bool filter_invalid = false)
{
std::ostringstream string_stream;
string_stream << "SELECT COUNT(*) FROM [" << table << "]";
if (filter_invalid) {
string_stream << " WHERE SampleInfo_valid_data = 1";
}
rti::apputils::SQLiteConnection::RowIterator row_it =
connection_.begin(string_stream.str());
int64_t value = 0;
row_it.get(0, value);
return (uint32_t) value;
}
bool check_num_rows(
const std::string& table,
const uint32_t expected_count,
const bool filter_invalid = false)
{
try {
RTI_TEST_ASSERT_EQUALS_INT(
expected_count,
num_rows(table, filter_invalid));
} catch (const std::exception&) {
return false;
}
return true;
}
bool check_num_rows_for_statement(
const std::string& sql,
const unsigned int expected_count)
{
try {
RTI_TEST_ASSERT_EQUALS_INT(
expected_count,
num_rows_for_statement(sql));
} catch (const std::exception&) {
return false;
}
return true;
}
bool wait_till_num_rows(
const std::string& table,
const unsigned int expected_count,
const bool filter_invalid = false,
const unsigned int seconds = DEFAULT_TEST_TIMEOUT_SEC)
{
try {
RTI_TEST_WAIT_FOR_EQUALS_INT(
expected_count,
num_rows(table, filter_invalid),
static_cast<int32_t>(seconds));
} catch (const std::exception& ex) {
RTITestLogger_log(
RTI_LOG_BIT_EXCEPTION,
&RTI_TEST_LOG_FAILURE_TEMPLATE,
"exception thrown: %s",
ex.what());
return false;
}
return true;
}
bool wait_till_num_rows_for_statement(
const std::string& sql,
const unsigned int expected_count,
const unsigned int seconds = DEFAULT_TEST_TIMEOUT_SEC)
{
try {
RTI_TEST_WAIT_FOR_EQUALS_INT(
expected_count,
num_rows_for_statement(sql),
static_cast<int32_t>(seconds));
} catch (const std::exception& ex) {
RTITestLogger_log(
RTI_LOG_BIT_EXCEPTION,
&RTI_TEST_LOG_FAILURE_TEMPLATE,
"exception thrown: %s",
ex.what());
return false;
}
return true;
}
bool check_num_rows_invariant(
const std::string& table,
const unsigned int expected_count,
const bool filter_invalid = false,
const unsigned int seconds = DEFAULT_TEST_TIMEOUT_SEC)
{
const struct RTINtpTime sleepTime = {0,429496730};
int sleeps = 0;
bool result = check_num_rows(table, expected_count, filter_invalid);
while(result && sleeps < (static_cast<int32_t>(seconds)) * 10) {
RTIOsapiThread_sleep(&sleepTime);
++sleeps;
result = check_num_rows(table, expected_count, filter_invalid);
}
return result;
}
protected:
rti::apputils::SQLiteConnection& connection_;
};
} } } /* namespace rti::apputils::test */
#endif /* HPP_APPUTILS_SQLITEVERIFIER_HPP_ */