Skip to content

Commit

Permalink
Merge remote-tracking branch 'proplib-template/main' into cross-platf…
Browse files Browse the repository at this point in the history
…orm-cli-driver
  • Loading branch information
aromanielloNTIA committed Dec 3, 2024
2 parents 945ba08 + df52dea commit 55357a8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ target_include_directories(${LIB_NAME} PUBLIC "${LIB_HEADERS}")
# link library to proplib_compiler_flags
target_link_libraries(${LIB_NAME} PUBLIC proplib_compiler_flags)

# Add definition to get the library name inside the library
add_compile_definitions(LIBRARY_NAME="${LIB_NAME}")
# Add definition to get the library name and version inside the library
add_compile_definitions(
LIBRARY_NAME="${LIB_NAME}"
LIBRARY_VERSION="${PROJECT_VERSION}"
)

# Platform-specific configurations
if (WIN32)
Expand Down
2 changes: 2 additions & 0 deletions src/ReturnCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ std::string GetReturnStatus(const int code) {
{ERROR33__PERCENTAGE, "Percentage must be between 0 and 100"}};
// Construct status message
std::string msg = LIBRARY_NAME;
msg += " v";
msg += LIBRARY_VERSION;
if (code == SUCCESS) {
msg += " Status: ";
} else {
Expand Down
33 changes: 24 additions & 9 deletions tests/TestUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
/** @file TestUtils.cpp
* Primary implementations for fixtures or common functions used by unit tests.
*/
#include "TestUtils.h"

#include <fstream> // for std::ifstream
#include <sstream> // for std::istringstream
#include <string> // for std::string, std::getline
#include <vector> // for std::vector

void appendDirectorySep(std::string &str) {
/*******************************************************************************
* Append a directory separator ('/' or '\') to a string, based on the
* current operating system.
*
* @param[in, out] str String to which the character will be appended.
*****************************************************************************/
void AppendDirectorySep(std::string &str) {
#ifdef _WIN32
str += "\\";
#else
str += "/";
#endif
}

std::string getDataDirectory() {
/******************************************************************************
* Get the full path of the directory containing test data files.
*
* @return The path of the test data directory.
*****************************************************************************/
std::string GetDataDirectory() {
std::string dataDir(__FILE__);
dataDir.resize(dataDir.find_last_of("/\\"));
dataDir.resize(dataDir.find_last_of("/\\"));
appendDirectorySep(dataDir);
AppendDirectorySep(dataDir);
dataDir += "extern";
appendDirectorySep(dataDir);
dataDir += "p2108-test-data"; // Name of data directory as cloned in the `extern` directory
appendDirectorySep(dataDir);
AppendDirectorySep(dataDir);
dataDir
+= "test-data"; // Name of data directory as cloned in the `extern` directory
AppendDirectorySep(dataDir);
return dataDir;
}

std::vector<AeronauticalStatisticalModelTestData>
readAeronauticalStatisticalModelTestData(const std::string &filename) {
std::vector<AeronauticalStatisticalModelTestData> testData;
std::string dataDir = getDataDirectory();
std::string dataDir = GetDataDirectory();
std::ifstream file(dataDir + filename);
std::string line;
// struct to store data from a single line of CSV:
Expand All @@ -49,7 +64,7 @@ std::vector<AeronauticalStatisticalModelTestData>
std::vector<HeightGainTerminalCorrectionModelTestData>
readHeightGainTerminalCorrectionModelTestData(const std::string &filename) {
std::vector<HeightGainTerminalCorrectionModelTestData> testData;
std::string dataDir = getDataDirectory();
std::string dataDir = GetDataDirectory();
std::ifstream file(dataDir + filename);
std::string line;
// struct to store data from a single line of CSV:
Expand All @@ -74,7 +89,7 @@ std::vector<HeightGainTerminalCorrectionModelTestData>
std::vector<TerrestrialStatisticalModelTestData>
readTerrestrialStatisticalModelTestData(const std::string &filename) {
std::vector<TerrestrialStatisticalModelTestData> testData;
std::string dataDir = getDataDirectory();
std::string dataDir = GetDataDirectory();
std::ifstream file(dataDir + filename);
std::string line;
// struct to store data from a single line of CSV:
Expand Down
3 changes: 3 additions & 0 deletions tests/TestUtils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** @file TestUtils.h
* Primary header for fixtures or common functions used by unit tests.
*/
#pragma once

#include "P2108.h"
Expand Down

0 comments on commit 55357a8

Please sign in to comment.