Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MappedFileTest.cpp
Go to the documentation of this file.
1/*
2 * MappedFileTest.cpp
3 *
4 * Created on: Feb 25, 2014
5 * Author: Manuel Sascha Weiand
6 */
7
8#include "storm-config.h"
9#include "test/storm_gtest.h"
10
11#include <string>
15#include "storm/io/file.h"
16
17TEST(MappedFileTest, NonExistingFile) {
18 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
19 STORM_SILENT_ASSERT_THROW(storm::parser::MappedFile(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"), storm::exceptions::FileIoException);
20}
21
22TEST(MappedFileTest, BasicFunctionality) {
23 // Open a file and test if the content is loaded as expected.
24 storm::parser::MappedFile file(STORM_TEST_RESOURCES_DIR "/txt/testStringFile.txt");
25 std::string testString = "This is a test string.";
26 char const* dataPtr = file.getData();
27 for (char const* testStringPtr = testString.c_str(); testStringPtr - testString.c_str() < 22; testStringPtr++) {
28 ASSERT_EQ(*testStringPtr, *dataPtr);
29 dataPtr++;
30 }
31 // The next character should be an end of line character (actual character varies between operating systems).
32 ASSERT_EQ(dataPtr, storm::utility::cstring::forwardToLineEnd(dataPtr));
33
34 // The newline character should be the last contained in the string.
36}
37
38TEST(MappedFileTest, ExistsAndReadble) {
39 // Test the fileExistsAndIsReadable() method under various circumstances.
40
41 // File exists and is readable.
42 ASSERT_TRUE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/txt/testStringFile.txt"));
43
44 // File does not exist.
45 ASSERT_FALSE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"));
46
47 // File exists but is not readable.
48 // TODO: Find portable solution to providing a situation in which a file exists but is not readable.
49 // ASSERT_FALSE(storm::io::fileExistsAndIsReadable(STORM_TEST_RESOURCES_DIR "/parser/unreadableFile.txt"));
50}
TEST(MappedFileTest, NonExistingFile)
Opens a file and maps it to memory providing a char* containing the file content.
Definition MappedFile.h:33
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:99