Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MappedFileTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <string>
5
9#include "storm/io/file.h"
10
11TEST(MappedFileTest, NonExistingFile) {
12 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
13 STORM_SILENT_ASSERT_THROW(storm::parser::MappedFile(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"), storm::exceptions::FileIoException);
14}
15
16TEST(MappedFileTest, BasicFunctionality) {
17 // Open a file and test if the content is loaded as expected.
18 storm::parser::MappedFile file(STORM_TEST_RESOURCES_DIR "/txt/testStringFile.txt");
19 std::string testString = "This is a test string.";
20 char const* dataPtr = file.getData();
21 for (char const* testStringPtr = testString.c_str(); testStringPtr - testString.c_str() < 22; testStringPtr++) {
22 ASSERT_EQ(*testStringPtr, *dataPtr);
23 dataPtr++;
24 }
25 // The next character should be an end of line character (actual character varies between operating systems).
26 ASSERT_EQ(dataPtr, storm::utility::cstring::forwardToLineEnd(dataPtr));
27
28 // The newline character should be the last contained in the string.
30}
31
32TEST(MappedFileTest, ExistsAndReadble) {
33 // Test the fileExistsAndIsReadable() method under various circumstances.
34
35 // File exists and is readable.
36 ASSERT_TRUE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/txt/testStringFile.txt"));
37
38 // File does not exist.
39 ASSERT_FALSE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"));
40
41 // File exists but is not readable.
42 // TODO: Find portable solution to providing a situation in which a file exists but is not readable.
43 // ASSERT_FALSE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/parser/unreadableFile.txt"));
44}
TEST(MappedFileTest, NonExistingFile)
Opens a file and maps it to memory providing a char* containing the file content.
Definition MappedFile.h:21
char const * getData() const
Returns a pointer to the beginning of the mapped file data.
char const * getDataEnd() const
Returns a pointer to the end of the mapped file data.
bool fileExistsAndIsReadable(std::string const &filename)
Tests whether the given file exists and is readable.
Definition file.h:66
char const * forwardToLineEnd(char const *buffer)
Encapsulates the usage of function @strcspn to forward to the end of the line (next char is the newli...
Definition cstring.cpp:74
char const * forwardToNextLine(char const *buffer)
Encapsulates the usage of function @strchr to forward to the next line.
Definition cstring.cpp:81
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:26