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.

95 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/read_lab_file.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::read_lab_file(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. //Parsing the file
  21. ASSERT_NO_THROW(labeling = mrmc::parser::read_lab_file(12, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/pctl_general_input_01.lab"));
  22. //Checking whether all propositions are in the labelling
  23. char phi[] = "phi", psi[] = "psi", smth[] = "smth";
  24. if (labeling != NULL) {
  25. ASSERT_TRUE(labeling->containsAtomicProposition(phi));
  26. ASSERT_TRUE(labeling->containsAtomicProposition(psi));
  27. ASSERT_TRUE(labeling->containsAtomicProposition(smth));
  28. //Testing whether all and only the correct nodes are labeled with "phi"
  29. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,1));
  30. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,2));
  31. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,3));
  32. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,5));
  33. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,7));
  34. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,9));
  35. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,10));
  36. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,11));
  37. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,4));
  38. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,6));
  39. //Testing whether all and only the correct nodes are labeled with "psi"
  40. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,6));
  41. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,7));
  42. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,8));
  43. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,1));
  44. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,2));
  45. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,3));
  46. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,4));
  47. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,5));
  48. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,9));
  49. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,10));
  50. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,11));
  51. //Testing whether all and only the correct nodes are labeled with "smth"
  52. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,4));
  53. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,5));
  54. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,1));
  55. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,2));
  56. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,3));
  57. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,6));
  58. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,7));
  59. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,8));
  60. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,9));
  61. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,10));
  62. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,11));
  63. //Deleting the labeling
  64. delete labeling;
  65. } else {
  66. FAIL();
  67. }
  68. }
  69. TEST(ReadLabFileTest, WrongHeaderTest1) {
  70. ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header1.lab"), mrmc::exceptions::wrong_file_format);
  71. }
  72. TEST(ReadLabFileTest, WrongHeaderTest2) {
  73. ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header2.lab"), mrmc::exceptions::wrong_file_format);
  74. }
  75. TEST(ReadLabFileTest, WrongPropositionTest) {
  76. ASSERT_THROW(mrmc::parser::read_lab_file(3, MRMC_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_proposition.lab"), mrmc::exceptions::wrong_file_format);
  77. }