Skip to content

use ctest and set path to dbc files with a compile definition #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FetchContent_Declare(
GIT_TAG v3.2.1
)
FetchContent_MakeAvailable(Catch2)
include(Catch)

list(APPEND TEST_SOURCES
test_dbc.cpp
Expand All @@ -20,5 +21,4 @@ target_sources(tests INTERFACE FILE_SET HEADERS
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES defines.hpp)

add_test(NAME tests COMMAND $<TARGET_FILE:tests>)
catch_discover_tests(tests)
44 changes: 22 additions & 22 deletions test/test_dbc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#include <catch2/catch_test_macros.hpp>
#include "defines.hpp"
#include <libdbc/dbc.hpp>
#include <string_view>

void create_tmp_dbc_with(const char* filename, const char* content)
{
auto* file = std::fopen(filename, "w");
CHECK(file);

std::fputs(PRIMITIVE_DBC.c_str(), file);
std::fputs(content, file);
std::fclose(file);
}


TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser());
Expand Down Expand Up @@ -51,51 +63,43 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {

}

/*!
* \brief TEST_CASE
* Test negative values in offset, min, max
*/
TEST_CASE("Testing negative values") {
const auto* filename = std::tmpnam(NULL);

auto* file = std::fopen(filename, "w");
CHECK(file);

std::fputs(PRIMITIVE_DBC.c_str(), file);
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
SG_ Sig2 : 39|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
SG_ Sig3 : 23|16@0- (10,0) [-3276.8|-3276.7] "C" Vector__XXX
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)", file);
std::fclose(file);
SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)");

auto parser = libdbc::DbcParser();
parser.parse_file(std::string(filename));

REQUIRE(parser.get_messages().size() == 1);
REQUIRE(parser.get_messages().at(0).signals.size() == 4);
{

SECTION("Evaluating first message") {
const auto signal = parser.get_messages().at(0).signals.at(0);
REQUIRE(signal.factor == 0.1);
REQUIRE(signal.offset == 0);
REQUIRE(signal.min == -3276.8);
REQUIRE(signal.max == -3276.7);
}
{
SECTION("Evaluating second message") {
const auto signal = parser.get_messages().at(0).signals.at(1);
REQUIRE(signal.factor == 0.1);
REQUIRE(signal.offset == 0);
REQUIRE(signal.min == -3276.8);
REQUIRE(signal.max == -3276.7);
}
{
SECTION("Evaluating third message"){
const auto signal = parser.get_messages().at(0).signals.at(2);
REQUIRE(signal.factor == 10);
REQUIRE(signal.offset == 0);
REQUIRE(signal.min == -3276.8);
REQUIRE(signal.max == -3276.7);
}
{
SECTION("Evaluating fourth message"){
const auto signal = parser.get_messages().at(0).signals.at(3);
REQUIRE(signal.factor == 1);
REQUIRE(signal.offset == -10);
Expand All @@ -108,20 +112,16 @@ TEST_CASE("Testing negative values") {
TEST_CASE("Special characters in unit") {
const auto* filename = std::tmpnam(NULL);

auto* file = std::fopen(filename, "w");
CHECK(file);
create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)");

std::fputs(PRIMITIVE_DBC.c_str(), file);
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)", file);
std::fclose(file);

auto parser = libdbc::DbcParser();
parser.parse_file(std::string(filename));

REQUIRE(parser.get_messages().size() == 1);
REQUIRE(parser.get_messages().at(0).signals.size() == 1);
{
SECTION("Checking that signal with special characters as unit is parsed correctly") {
const auto signal = parser.get_messages().at(0).signals.at(0);
REQUIRE(signal.unit.compare("Km/h") == 0);
}
Expand Down