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.

91 lines
3.7 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 "MRMCConfig.h"
  9. #include "src/dtmc/labeling.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::dtmc::labeling* labeling;
  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. ASSERT_TRUE(labeling->containsProposition(phi));
  25. ASSERT_TRUE(labeling->containsProposition(psi));
  26. ASSERT_TRUE(labeling->containsProposition(smth));
  27. //Testing whether all and only the correct nodes are labeled with "phi"
  28. ASSERT_TRUE(labeling->nodeHasProposition(phi,1));
  29. ASSERT_TRUE(labeling->nodeHasProposition(phi,2));
  30. ASSERT_TRUE(labeling->nodeHasProposition(phi,3));
  31. ASSERT_TRUE(labeling->nodeHasProposition(phi,5));
  32. ASSERT_TRUE(labeling->nodeHasProposition(phi,7));
  33. ASSERT_TRUE(labeling->nodeHasProposition(phi,9));
  34. ASSERT_TRUE(labeling->nodeHasProposition(phi,10));
  35. ASSERT_TRUE(labeling->nodeHasProposition(phi,11));
  36. ASSERT_FALSE(labeling->nodeHasProposition(phi,4));
  37. ASSERT_FALSE(labeling->nodeHasProposition(phi,6));
  38. //Testing whether all and only the correct nodes are labeled with "psi"
  39. ASSERT_TRUE(labeling->nodeHasProposition(psi,6));
  40. ASSERT_TRUE(labeling->nodeHasProposition(psi,7));
  41. ASSERT_TRUE(labeling->nodeHasProposition(psi,8));
  42. ASSERT_FALSE(labeling->nodeHasProposition(psi,1));
  43. ASSERT_FALSE(labeling->nodeHasProposition(psi,2));
  44. ASSERT_FALSE(labeling->nodeHasProposition(psi,3));
  45. ASSERT_FALSE(labeling->nodeHasProposition(psi,4));
  46. ASSERT_FALSE(labeling->nodeHasProposition(psi,5));
  47. ASSERT_FALSE(labeling->nodeHasProposition(psi,9));
  48. ASSERT_FALSE(labeling->nodeHasProposition(psi,10));
  49. ASSERT_FALSE(labeling->nodeHasProposition(psi,11));
  50. //Testing whether all and only the correct nodes are labeled with "smth"
  51. ASSERT_TRUE(labeling->nodeHasProposition(smth,4));
  52. ASSERT_TRUE(labeling->nodeHasProposition(smth,5));
  53. ASSERT_FALSE(labeling->nodeHasProposition(smth,1));
  54. ASSERT_FALSE(labeling->nodeHasProposition(smth,2));
  55. ASSERT_FALSE(labeling->nodeHasProposition(smth,3));
  56. ASSERT_FALSE(labeling->nodeHasProposition(smth,6));
  57. ASSERT_FALSE(labeling->nodeHasProposition(smth,7));
  58. ASSERT_FALSE(labeling->nodeHasProposition(smth,8));
  59. ASSERT_FALSE(labeling->nodeHasProposition(smth,9));
  60. ASSERT_FALSE(labeling->nodeHasProposition(smth,10));
  61. ASSERT_FALSE(labeling->nodeHasProposition(smth,11));
  62. //Deleting the labeling
  63. delete labeling;
  64. }
  65. TEST(ReadLabFileTest, WrongHeaderTest1) {
  66. 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);
  67. }
  68. TEST(ReadLabFileTest, WrongHeaderTest2) {
  69. 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);
  70. }
  71. TEST(ReadLabFileTest, WrongPropositionTest) {
  72. 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);
  73. }