oosc - jmsassert. design by contract a powerful technique for writing reliable software. specifying...
TRANSCRIPT
![Page 1: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/1.jpg)
OOSC - JMSAssertOOSC - JMSAssert
![Page 2: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/2.jpg)
Design By ContractDesign By Contract A powerful technique for writing reliable
software. Specifying the software purpose with the
implementation. Key elements:
Invariant Preconditions Postconditions
![Page 3: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/3.jpg)
Design By ContractDesign By Contract Precondition – The constraints under
which the routine will function properly. Postconditions – The state of the class after
the routine execution The Contract: If you call routine R() with
the preconditions satisfied, R() will return satisfying the postconditions.
Invariant – Always holds
![Page 4: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/4.jpg)
When are condition checked?When are condition checked?
Event InvariantPre-
conditionPost-
conditionInstance Method Y Y -Constructor N Y -Private Method N Y -Static Method N Y -Instance Method Y - YConstructor Y - YPrivate Method N - YStatic Method N - Y
Method Entry
Method Exit
![Page 5: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/5.jpg)
JMS Syntax - InvariantJMS Syntax - Invariant Invariant - @inv May access all class members or its
direct/indirect bases, including private members
May appear in any JavaDoc comment Preferable in the class comment
![Page 6: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/6.jpg)
JMS Syntax - PreconditionsJMS Syntax - Preconditions Precondition - @pre JavaDoc preceding the respective method May reference class members and
arguments Multiple @pre markers are conjugated
(AND)
![Page 7: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/7.jpg)
JMS Syntax - PostconditionsJMS Syntax - Postconditions Postconditions - @post JavaDoc preceding the respective method May use $prev(expression) to access the
value at the method entry. May use $ret to denote method’s return
value Multiple @post markers are conjugated
(AND)
![Page 8: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/8.jpg)
ExampleExample/** * @pre !isEmpty() * @post (top == $prev(top- 1)) * @post $ret == elems[top] * @post !isFull*/
public synchronized Object pop() {return elems[--top];
}
Precondition
Postconditions
![Page 9: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/9.jpg)
JMS Syntax - GeneralJMS Syntax - General Order has no meaning @macro – for complicated conditions Recursion – as expected, on every call Inner classes can access outer classes’
members Anonymous classes – specify invariant in
one of its methods
![Page 10: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/10.jpg)
JMSAssert InstallationJMSAssert Installation Run the jmssetup-1.02.exe installation file The following lines are added to the path:REM Next two lines are added by JMSAssertSET CLASSPATH=%CLASSPATH%;C:\PROGRA~1\JMSASS~1.0\bin\mmsclasses.jar;SET PATH=%PATH%;C:\PROGRA~1\JMSASS~1.0\bin; Copy the “classic” directory from
“..\jdk1.3.1\jre\bin\” to the directory:“C:\Program Files\JavaSoft\JRE\1.3\bin\”
![Page 11: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/11.jpg)
Setup Setup (cont.)(cont.)
Your JavaSoft directory should look like:
If you use jdk 1.2.2, you will have a 1.2 directory
![Page 12: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/12.jpg)
JMSAssert – how does it workJMSAssert – how does it work Annotate source code with assertions Compile your code using javac (as usual) Preprocess the code using jmsassert: creates
contract files (*.jms) and a Startup.jms file. *.jms files contain java code for the assertions. Execute using: jmsjava Startup <filename>to check assertions.
jmsjava makes sure method assertions are called before/after the method invocation.
![Page 13: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/13.jpg)
JMS ExecutionJMS Execution “jmsassert” – generates help text “jmsassert –s <filename.java>” – generate
assertions for a class file “jmsassert –r –s .” – generate assertions for
all class files in the directory and sub-dirs. (use for packages)
“javac <filename.java>” – compile “jmsjava Startup <main>” - execute and check
assertions
![Page 14: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/14.jpg)
Annotate source with assertions
Preprocess to generate assertion
filesJmsassert –s <file.java>
Compile Java file
javac <file.java<
Execute using jmsjava
MyStack.java
Startup.jms
default_MyStack.jmsdefault_MyStack_StackEnum.jms
MyStack.classMyStack$StackEnum.classMyStack$StackEnum.classJmsjava Startup <file.java> StackTest.class
Stack Demo Stack Demo filesfiles
Execution Execution processprocess
![Page 15: OOSC - JMSAssert. Design By Contract A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key](https://reader036.vdocument.in/reader036/viewer/2022082711/56649f165503460f94c2c7bd/html5/thumbnails/15.jpg)
NotesNotes Execute these steps form the command line! Make sure your CLASSPATH environment
variable contains the current directory.Add “CLASSPATH=%CLASSPATH%;.;” to autoexec.bat.