|
1 | 1 | #include <catch2/catch_test_macros.hpp> |
2 | 2 | #include "defines.hpp" |
3 | 3 | #include <libdbc/dbc.hpp> |
| 4 | +#include <string_view> |
| 5 | + |
| 6 | +void create_tmp_dbc_with(const char* filename, const char* content) |
| 7 | +{ |
| 8 | + auto* file = std::fopen(filename, "w"); |
| 9 | + CHECK(file); |
| 10 | + |
| 11 | + std::fputs(PRIMITIVE_DBC.c_str(), file); |
| 12 | + std::fputs(content, file); |
| 13 | + std::fclose(file); |
| 14 | +} |
| 15 | + |
4 | 16 |
|
5 | 17 | TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") { |
6 | 18 | auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser()); |
@@ -58,16 +70,11 @@ TEST_CASE("Testing dbc file loading", "[fileio]") { |
58 | 70 | TEST_CASE("Testing negative values") { |
59 | 71 | const auto* filename = std::tmpnam(NULL); |
60 | 72 |
|
61 | | - auto* file = std::fopen(filename, "w"); |
62 | | - CHECK(file); |
63 | | - |
64 | | - std::fputs(PRIMITIVE_DBC.c_str(), file); |
65 | | - std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX |
| 73 | + create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX |
66 | 74 | SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX |
67 | 75 | SG_ Sig2 : 39|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX |
68 | 76 | SG_ Sig3 : 23|16@0- (10,0) [-3276.8|-3276.7] "C" Vector__XXX |
69 | | - SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)", file); |
70 | | - std::fclose(file); |
| 77 | + SG_ Sig4 : 7|16@0- (1,-10) [0|32767] "" Vector__XXX)"); |
71 | 78 |
|
72 | 79 | auto parser = libdbc::DbcParser(); |
73 | 80 | parser.parse_file(std::string(filename)); |
@@ -109,13 +116,9 @@ TEST_CASE("Testing negative values") { |
109 | 116 | TEST_CASE("Special characters in unit") { |
110 | 117 | const auto* filename = std::tmpnam(NULL); |
111 | 118 |
|
112 | | - auto* file = std::fopen(filename, "w"); |
113 | | - CHECK(file); |
| 119 | + create_tmp_dbc_with(filename, R"(BO_ 234 MSG1: 8 Vector__XXX |
| 120 | + SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)"); |
114 | 121 |
|
115 | | - std::fputs(PRIMITIVE_DBC.c_str(), file); |
116 | | - std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX |
117 | | - SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)", file); |
118 | | - std::fclose(file); |
119 | 122 |
|
120 | 123 | auto parser = libdbc::DbcParser(); |
121 | 124 | parser.parse_file(std::string(filename)); |
|
0 commit comments