Browse Source

Edited src/parser/read_lab_file.cpp, fixed String tokenization in WIN32

Edited MRMCConfig.h.in to include the base path for Test/ Directory
Refactored the test files to use the new test/ base path macro
With credits to Thomas ;)
tempestpy_adaptions
PBerger 12 years ago
parent
commit
87f768ca41
  1. 4
      CMakeLists.txt
  2. 3
      MRMCConfig.h.in
  3. 6
      src/dtmc/labeling.h
  4. 14
      src/parser/read_lab_file.cpp
  5. 9
      src/sparse/static_sparse_matrix.h
  6. 11
      test/parser/read_lab_file_test.cpp
  7. 11
      test/parser/read_tra_file_test.cpp

4
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"

3
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@
#define MRMC_CPP_VERSION_MINOR @MRMC_CPP_VERSION_MINOR@
#define MRMC_CPP_TESTS_BASE_PATH "@MRMC_CPP_TESTS_BASE_PATH@"

6
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<std::string, AtomicProposition*>::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) {

14
src/parser/read_lab_file.cpp

@ -19,6 +19,12 @@
#include <pantheios/pantheios.hpp>
#include <pantheios/inserters/integer.hpp>
#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;
}

9
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;

11
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);
}

11
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<double> *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);
}
Loading…
Cancel
Save