You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

  1. /*
  2. * MappedFileTest.cpp
  3. *
  4. * Created on: Feb 25, 2014
  5. * Author: Manuel Sascha Weiand
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include <string>
  10. #include "src/parser/MappedFile.h"
  11. #include "src/utility/cstring.h"
  12. #include "src/exceptions/FileIoException.h"
  13. TEST(MappedFileTest, NonExistingFile) {
  14. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  15. ASSERT_THROW(storm::parser::MappedFile(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  16. }
  17. TEST(MappedFileTest, BasicFunctionality) {
  18. // Open a file and test if the content is loaded as expected.
  19. storm::parser::MappedFile file(STORM_CPP_TESTS_BASE_PATH "/functional/parser/testStringFile.txt");
  20. std::string testString = "This is a test string.";
  21. char * dataPtr = file.getData();
  22. for(char const * testStringPtr = testString.c_str(); testStringPtr - testString.c_str() < 22; testStringPtr++) {
  23. ASSERT_EQ(*testStringPtr, *dataPtr);
  24. dataPtr++;
  25. }
  26. // The next character should be an end of line character (actual character varies between operating systems).
  27. ASSERT_EQ(dataPtr, storm::utility::cstring::forwardToLineEnd(dataPtr));
  28. // The newline character should be the last contained in the string.
  29. ASSERT_EQ(file.getDataEnd(), storm::utility::cstring::forwardToNextLine(dataPtr));
  30. }
  31. TEST(MappedFileTest, ExistsAndReadble) {
  32. // Test the fileExistsAndIsReadable() method under various circumstances.
  33. // File exists and is readable.
  34. ASSERT_TRUE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/functional/parser/testStringFile.txt"));
  35. // File does not exist.
  36. ASSERT_FALSE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"));
  37. // File exists but is not readable.
  38. // TODO: Find portable solution to providing a situation in which a file exists but is not readable.
  39. //ASSERT_FALSE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/functional/parser/unreadableFile.txt"));
  40. }