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.

46 lines
1.7 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/exceptions/FileIoException.h"
  12. TEST(MappedFileTest, NonExistingFile) {
  13. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  14. ASSERT_THROW(storm::parser::MappedFile(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  15. }
  16. TEST(MappedFileTest, BasicFunctionality) {
  17. // Open a file and test if the content is loaded as expected.
  18. storm::parser::MappedFile file(STORM_CPP_TESTS_BASE_PATH "/functional/parser/testStringFile.txt");
  19. std::string testString = "This is a test string.\n";
  20. ASSERT_EQ(testString.length(), file.getDataEnd() - file.getData());
  21. char const * testStringPtr = testString.c_str();
  22. for(char* dataPtr = file.getData(); dataPtr < file.getDataEnd(); dataPtr++) {
  23. ASSERT_EQ(*testStringPtr, *dataPtr);
  24. testStringPtr++;
  25. }
  26. }
  27. TEST(MappedFileTest, ExistsAndReadble) {
  28. // Test the fileExistsAndIsReadable() method under various circumstances.
  29. // File exists and is readable.
  30. ASSERT_TRUE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/functional/parser/testStringFile.txt"));
  31. // File does not exist.
  32. ASSERT_FALSE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"));
  33. // File exists but is not readable.
  34. // TODO: Find portable solution to providing a situation in which a file exists but is not readable.
  35. //ASSERT_FALSE(storm::parser::MappedFile::fileExistsAndIsReadable(STORM_CPP_TESTS_BASE_PATH "/functional/parser/unreadableFile.txt"));
  36. }