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.

98 lines
4.0 KiB

  1. /*
  2. * read_lab_file_test.cpp
  3. *
  4. * Created on: 12.09.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #include "gtest/gtest.h"
  8. #include "mrmc-config.h"
  9. #include "src/models/AtomicPropositionsLabeling.h"
  10. #include "src/parser/readLabFile.h"
  11. #include "src/exceptions/file_IO_exception.h"
  12. #include "src/exceptions/wrong_file_format.h"
  13. TEST(ReadLabFileTest, NonExistingFileTest) {
  14. //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
  15. ASSERT_THROW(mrmc::parser::LabParser(0,MRMC_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), mrmc::exceptions::file_IO_exception);
  16. }
  17. TEST(ReadLabFileTest, ParseTest) {
  18. //This test is based on a test case from the original MRMC.
  19. mrmc::models::AtomicPropositionsLabeling* labeling = NULL;
  20. mrmc::parser::LabParser* parser;
  21. //Parsing the file
  22. ASSERT_NO_THROW(parser = new mrmc::parser::LabParser(12, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/pctl_general_input_01.lab"));
  23. labeling = parser->getLabeling();
  24. //Checking whether all propositions are in the labelling
  25. char phi[] = "phi", psi[] = "psi", smth[] = "smth";
  26. if (labeling != NULL) {
  27. ASSERT_TRUE(labeling->containsAtomicProposition(phi));
  28. ASSERT_TRUE(labeling->containsAtomicProposition(psi));
  29. ASSERT_TRUE(labeling->containsAtomicProposition(smth));
  30. //Testing whether all and only the correct nodes are labeled with "phi"
  31. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,1));
  32. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,2));
  33. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,3));
  34. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,5));
  35. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,7));
  36. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,9));
  37. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,10));
  38. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,11));
  39. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,4));
  40. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,6));
  41. //Testing whether all and only the correct nodes are labeled with "psi"
  42. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,6));
  43. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,7));
  44. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,8));
  45. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,1));
  46. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,2));
  47. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,3));
  48. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,4));
  49. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,5));
  50. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,9));
  51. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,10));
  52. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,11));
  53. //Testing whether all and only the correct nodes are labeled with "smth"
  54. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,4));
  55. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,5));
  56. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,1));
  57. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,2));
  58. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,3));
  59. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,6));
  60. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,7));
  61. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,8));
  62. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,9));
  63. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,10));
  64. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,11));
  65. //Deleting the labeling
  66. delete labeling;
  67. delete parser;
  68. } else {
  69. FAIL();
  70. }
  71. }
  72. TEST(ReadLabFileTest, WrongHeaderTest1) {
  73. ASSERT_THROW(mrmc::parser::LabParser(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header1.lab"), mrmc::exceptions::wrong_file_format);
  74. }
  75. TEST(ReadLabFileTest, WrongHeaderTest2) {
  76. ASSERT_THROW(mrmc::parser::LabParser(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header2.lab"), mrmc::exceptions::wrong_file_format);
  77. }
  78. TEST(ReadLabFileTest, WrongPropositionTest) {
  79. ASSERT_THROW(mrmc::parser::LabParser(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_proposition.lab"), mrmc::exceptions::wrong_file_format);
  80. }