oosc jmsassert n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
OOSC - JMSAssert PowerPoint Presentation
Download Presentation
OOSC - JMSAssert

Loading in 2 Seconds...

play fullscreen
1 / 15

OOSC - JMSAssert - PowerPoint PPT Presentation


  • 124 Views
  • Uploaded on

OOSC - JMSAssert. Design By Contract. A powerful technique for writing reliable software. Specifying the software purpose with the implementation. Key elements: Invariant Preconditions Postconditions. Design By Contract.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'OOSC - JMSAssert' - kamal


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
design by contract
Design By Contract
  • A powerful technique for writing reliable software.
  • Specifying the software purpose with the implementation.
  • Key elements:
    • Invariant
    • Preconditions
    • Postconditions
design by contract1
Design 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
jms syntax invariant
JMS 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
jms syntax preconditions
JMS Syntax - Preconditions
  • Precondition - @pre
  • JavaDoc preceding the respective method
  • May reference class members and arguments
  • Multiple @pre markers are conjugated (AND)
jms syntax postconditions
JMS 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)
example
Example

Precondition

/**

* @pre !isEmpty()

* @post (top == $prev(top- 1))

* @post $ret == elems[top]

* @post !isFull

*/

public synchronized Object pop() {

return elems[--top];

}

Postconditions

jms syntax general
JMS 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
jmsassert installation
JMSAssert Installation
  • Run the jmssetup-1.02.exe installation file
  • The following lines are added to the path:

REM Next two lines are added by JMSAssert

SET 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\”
setup cont
Setup (cont.)
  • Your JavaSoft directory should look like:
  • If you use jdk 1.2.2, you will have a 1.2 directory
jmsassert how does it work
JMSAssert – 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.
jms execution
JMS 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
slide14

Execution process

Stack Demo files

Annotate source with assertions

MyStack.java

Preprocess to generate assertion files

Startup.jms

default_MyStack.jms

Jmsassert –s <file.java>

default_MyStack_StackEnum.jms

Compile Java file

javac <file.java>

MyStack.class

MyStack$StackEnum.class

Execute using jmsjava

MyStack$StackEnum.class

StackTest.class

Jmsjava Startup <file.java>

notes
Notes
  • Execute these steps form the command line!
  • Make sure your CLASSPATH environment variable contains the current directory.Add “CLASSPATH=%CLASSPATH%;.;” to autoexec.bat.