diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e8bb5d11..827318e0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ endif() # configure a header file to pass some of the CMake settings # to the source code + +# Base path for test files +set(MRMC_CPP_TESTS_BASE_PATH ${PROJECT_SOURCE_DIR}/test) + configure_file ( "${PROJECT_SOURCE_DIR}/MRMCConfig.h.in" "${PROJECT_BINARY_DIR}/MRMCConfig.h" diff --git a/MRMCConfig.h.in b/MRMCConfig.h.in index 5d2b9fbf2..5546d324b 100644 --- a/MRMCConfig.h.in +++ b/MRMCConfig.h.in @@ -1,3 +1,4 @@ // the configured options and settings for MRMC_CPP #define MRMC_CPP_VERSION_MAJOR @MRMC_CPP_VERSION_MAJOR@ -#define MRMC_CPP_VERSION_MINOR @MRMC_CPP_VERSION_MINOR@ \ No newline at end of file +#define MRMC_CPP_VERSION_MINOR @MRMC_CPP_VERSION_MINOR@ +#define MRMC_CPP_TESTS_BASE_PATH "@MRMC_CPP_TESTS_BASE_PATH@" \ No newline at end of file diff --git a/src/dtmc/labeling.h b/src/dtmc/labeling.h index 56db09aeb..76311ce53 100644 --- a/src/dtmc/labeling.h +++ b/src/dtmc/labeling.h @@ -44,7 +44,7 @@ class labeling { proposition_count = propositionCount; propositions_current = 0; propositions = new AtomicProposition*[proposition_count]; - for (int i = 0; i < proposition_count; ++i) { + for (uint_fast32_t i = 0; i < proposition_count; ++i) { propositions[i] = new AtomicProposition(node_count); } } @@ -52,7 +52,7 @@ class labeling { virtual ~labeling() { //deleting all the labeling vectors in the map. MAP::iterator it; - for (int i = 0; i < proposition_count; ++i) { + for (uint_fast32_t i = 0; i < proposition_count; ++i) { delete propositions[i]; propositions[i] = NULL; } @@ -95,7 +95,7 @@ class labeling { } uint_fast32_t getNumberOfPropositions() { - return proposition_map.size(); + return proposition_count; } AtomicProposition* getProposition(std::string proposition) { diff --git a/src/parser/read_lab_file.cpp b/src/parser/read_lab_file.cpp index 85547d7ad..0d89b3935 100644 --- a/src/parser/read_lab_file.cpp +++ b/src/parser/read_lab_file.cpp @@ -19,6 +19,12 @@ #include #include +#ifdef WIN32 +# define STRTOK_FUNC strtok_s +#else +# define STRTOK_FUNC strtok_r +#endif + namespace mrmc { @@ -115,9 +121,9 @@ mrmc::dtmc::labeling * read_lab_file(int node_count, const char * filename) mrmc::dtmc::labeling* result = new mrmc::dtmc::labeling(node_count, proposition_count); //Here, all propositions are to be declared... - for (proposition = strtok_r(decl_buffer, sep, &saveptr); + for (proposition = STRTOK_FUNC(decl_buffer, sep, &saveptr); proposition != NULL; - proposition = strtok_r(NULL, sep, &saveptr)) { + proposition = STRTOK_FUNC(NULL, sep, &saveptr)) { result -> addProposition(proposition); } @@ -140,7 +146,7 @@ mrmc::dtmc::labeling * read_lab_file(int node_count, const char * filename) /* First token has to be a number identifying the node, * hence it is treated differently from the other tokens. */ - token = strtok_r(s, sep, &saveptr); + token = STRTOK_FUNC(s, sep, &saveptr); if (sscanf(token, "%u", &node) == 0) { fclose(P); delete result; @@ -148,7 +154,7 @@ mrmc::dtmc::labeling * read_lab_file(int node_count, const char * filename) throw mrmc::exceptions::wrong_file_format(); } do { - token = strtok_r(NULL, sep, &saveptr); + token = STRTOK_FUNC(NULL, sep, &saveptr); if (token == NULL) { break; } diff --git a/src/sparse/static_sparse_matrix.h b/src/sparse/static_sparse_matrix.h index 6393d0d2d..9fd7cd389 100644 --- a/src/sparse/static_sparse_matrix.h +++ b/src/sparse/static_sparse_matrix.h @@ -183,6 +183,15 @@ class StaticSparseMatrix { row_indications[row_count] = storage_size; } + + uint_fast32_t getRowCount() const { + return row_count; + } + + T* getStoragePointer() const { + return value_storage; + } + private: uint_fast32_t storage_size; uint_fast32_t current_size; diff --git a/test/parser/read_lab_file_test.cpp b/test/parser/read_lab_file_test.cpp index 9a614355e..925952625 100644 --- a/test/parser/read_lab_file_test.cpp +++ b/test/parser/read_lab_file_test.cpp @@ -6,6 +6,7 @@ */ #include "gtest/gtest.h" +#include "MRMCConfig.h" #include "src/dtmc/labeling.h" #include "src/parser/read_lab_file.h" #include "src/exceptions/file_IO_exception.h" @@ -13,7 +14,7 @@ TEST(ReadLabFileTest, NonExistingFileTest) { //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-) - ASSERT_THROW(mrmc::parser::read_lab_file(0,"nonExistingFile.not"), mrmc::exceptions::file_IO_exception); + ASSERT_THROW(mrmc::parser::read_lab_file(0,MRMC_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), mrmc::exceptions::file_IO_exception); } TEST(ReadLabFileTest, ParseTest) { @@ -21,7 +22,7 @@ TEST(ReadLabFileTest, ParseTest) { mrmc::dtmc::labeling* labeling; //Parsing the file - ASSERT_NO_THROW(labeling = mrmc::parser::read_lab_file(12,"test/parser/lab_files/pctl_general_input_01.lab")); + ASSERT_NO_THROW(labeling = mrmc::parser::read_lab_file(12, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/pctl_general_input_01.lab")); //Checking whether all propositions are in the labelling @@ -77,14 +78,14 @@ TEST(ReadLabFileTest, ParseTest) { } TEST(ReadLabFileTest, WrongHeaderTest1) { - ASSERT_THROW(mrmc::parser::read_lab_file(3,"test/parser/lab_files/wrong_format_header1.lab"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header1.lab"), mrmc::exceptions::wrong_file_format); } TEST(ReadLabFileTest, WrongHeaderTest2) { - ASSERT_THROW(mrmc::parser::read_lab_file(3,"test/parser/lab_files/wrong_format_header2.lab"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header2.lab"), mrmc::exceptions::wrong_file_format); } TEST(ReadLabFileTest, WrongPropositionTest) { - ASSERT_THROW(mrmc::parser::read_lab_file(3,"test/parser/lab_files/wrong_format_proposition.lab"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_proposition.lab"), mrmc::exceptions::wrong_file_format); } diff --git a/test/parser/read_tra_file_test.cpp b/test/parser/read_tra_file_test.cpp index ddf83b4ce..fead6b563 100644 --- a/test/parser/read_tra_file_test.cpp +++ b/test/parser/read_tra_file_test.cpp @@ -6,6 +6,7 @@ */ #include "gtest/gtest.h" +#include "MRMCConfig.h" #include "src/sparse/static_sparse_matrix.h" #include "src/parser/read_tra_file.h" #include "src/exceptions/file_IO_exception.h" @@ -15,7 +16,7 @@ TEST(ReadTraFileTest, NonExistingFileTest) { pantheios::log_INFORMATIONAL("Started NonExistingFileTest"); //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-) - ASSERT_THROW(mrmc::parser::read_tra_file("nonExistingFile.not"), mrmc::exceptions::file_IO_exception); + ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), mrmc::exceptions::file_IO_exception); } /* The following test case is based on one of the original MRMC test cases @@ -23,7 +24,7 @@ TEST(ReadTraFileTest, NonExistingFileTest) { TEST(ReadTraFileTest, ParseFileTest1) { pantheios::log_INFORMATIONAL("Started ParseFileTest1"); mrmc::sparse::StaticSparseMatrix *result; - ASSERT_NO_THROW(result = mrmc::parser::read_tra_file("test/parser/tra_files/csl_general_input_01.tra")); + ASSERT_NO_THROW(result = mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra")); double val = 0; ASSERT_TRUE(result->getValue(1,1,&val)); @@ -65,17 +66,17 @@ TEST(ReadTraFileTest, ParseFileTest1) { TEST(ReadTraFileTest, WrongFormatTestHeader1) { pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader1"); - ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/tra_files/wrong_format_header1.tra"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header1.tra"), mrmc::exceptions::wrong_file_format); } TEST(ReadTraFileTest, WrongFormatTestHeader2) { pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader2"); - ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/tra_files/wrong_format_header2.tra"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header2.tra"), mrmc::exceptions::wrong_file_format); } TEST(ReadTraFileTest, WrongFormatTestTransition) { pantheios::log_INFORMATIONAL("Started WrongFormatTestTransition"); - ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/tra_files/wrong_format_transition.tra"), mrmc::exceptions::wrong_file_format); + ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_transition.tra"), mrmc::exceptions::wrong_file_format); }