/test/language/unclassified/test_once8.e

http://github.com/tybor/Liberty · Specman e · 130 lines · 86 code · 15 blank · 29 comment · 0 complexity · 73d9e1b9c63bc9f25953b289b19bfcb5 MD5 · raw file

  1. -- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. class TEST_ONCE8
  5. --
  6. -- To memorize the result of a discussion at the last ECMA we agree with.
  7. --
  8. -- Pre--post condition of once must be checked at every calls (they
  9. -- are part of the interface).
  10. -- Dom. feb 18th 2004, just back from Orinda CA.
  11. --
  12. inherit
  13. EIFFELTEST_TOOLS
  14. create {}
  15. make
  16. feature {ANY}
  17. require_trace: STRING
  18. once
  19. create Result.make(0)
  20. end
  21. body_trace: STRING
  22. once
  23. create Result.make(0)
  24. end
  25. ensure_trace: STRING
  26. once
  27. create Result.make(0)
  28. end
  29. update_trace (actual_trace: STRING; step_mark: STRING): BOOLEAN
  30. do
  31. actual_trace.append(step_mark)
  32. Result := True
  33. end
  34. once_procedure (step_mark: STRING)
  35. require
  36. update_trace(require_trace, "RP")
  37. once
  38. body_trace.append(step_mark)
  39. ensure
  40. update_trace(ensure_trace, "EP")
  41. end
  42. make
  43. local
  44. require_trace_view, ensure_trace_view, once_function_result: STRING
  45. do
  46. setup_flags
  47. -- To ease debug:
  48. require_trace_view := require_trace
  49. ensure_trace_view := ensure_trace
  50. assert(require_trace.is_empty)
  51. assert(body_trace.is_empty)
  52. assert(ensure_trace.is_empty)
  53. once_procedure("1")
  54. assert(require_flag implies require_trace.is_equal("RP"))
  55. assert(body_trace.is_equal("1"))
  56. assert(ensure_flag implies ensure_trace.is_equal("EP"))
  57. once_procedure("2")
  58. assert(require_flag implies require_trace.is_equal("RPRP"))
  59. assert(body_trace.is_equal("1"))
  60. assert(ensure_flag implies ensure_trace.is_equal("EPEP"))
  61. require_trace.clear_count
  62. ensure_trace.clear_count
  63. once_function_result := once_function("call_1")
  64. assert(require_flag implies require_trace.is_equal("RP"))
  65. assert(ensure_flag implies ensure_trace.is_equal("EP"))
  66. assert(once_function("call_2") = once_function_result)
  67. assert(require_flag implies require_trace.is_equal("RPRP"))
  68. assert(ensure_flag implies ensure_trace.is_equal("EPEP"))
  69. end
  70. require_flag: BOOLEAN
  71. set_require_flag: BOOLEAN
  72. do
  73. require_flag := True
  74. Result := True
  75. end
  76. ensure_flag: BOOLEAN
  77. set_ensure_flag: BOOLEAN
  78. do
  79. ensure_flag := True
  80. Result := True
  81. end
  82. setup_flags
  83. require
  84. set_require_flag
  85. do
  86. ensure
  87. set_ensure_flag
  88. end
  89. once_function (step_mark: STRING): STRING
  90. require
  91. update_trace(require_trace, "RP")
  92. once
  93. Result := step_mark.twin
  94. ensure
  95. update_trace(ensure_trace, "EP")
  96. end
  97. end -- class TEST_ONCE8
  98. --
  99. -- ------------------------------------------------------------------------------------------------------------------------------
  100. -- Copyright notice below. Please read.
  101. --
  102. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  103. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  104. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  105. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  106. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  107. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  108. --
  109. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  110. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  111. --
  112. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  113. --
  114. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  115. -- ------------------------------------------------------------------------------------------------------------------------------