Object-oriented Features of TTCN-3

Slides:



Advertisements
Similar presentations
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
Advertisements

An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Road Map Introduction to object oriented programming. Classes
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Object Oriented Programming
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
Object Oriented Software Development
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Object-Oriented Programming Chapter Chapter
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Adding Concurrency to a Programming Language Peter A. Buhr and Glen Ditchfield USENIX C++ Technical Conference, Portland, Oregon, U. S. A., August 1992.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Chapter 2 Objects and Classes
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Data Abstraction: The Walls
Andy Wang Object Oriented Programming in C++ COP 3330
OOP: Encapsulation &Abstraction
Objects as a programming concept
CIS 200 Test 01 Review.
Object-Oriented Analysis and Design
Programming with ANSI C ++
Inheritance and Polymorphism
About the Presentations
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Indexer AKEEL AHMED.
CS212: Object Oriented Analysis and Design
Interfaces and Inheritance
Compiler Design 18. Object Oriented Semantic Analysis (Symbol Tables, Type Checking) Kanat Bolazar March 30, 2010.
Introduction to Data Structures
Java Programming Language
Lecture 22 Inheritance Richard Gesick.
Packages and Interfaces
Slides by Steve Armstrong LeTourneau University Longview, TX
Andy Wang Object Oriented Programming in C++ COP 3330
Advanced Java Programming
Part B – Structured Exception Handling
More Object-Oriented Programming
Coding Concepts (Basics)
Classes and Objects.
Parameter Passing Actual vs formal parameters
Java – Inheritance.
An Introduction to Software Architecture
Data Structures and Algorithms for Information Processing
Introduction to Programming
Exception Handling.
Creating and Using Classes
Presentation transcript:

Object-oriented Features of TTCN-3 Presented by Kristóf Szabados (on behalf of STF 550) © All rights reserved

Advanced Automated Testing Evolution First TTCN-3 version in 2001 + Component extension (2005) + Information hiding (2009) … Support for more and more complex test systems is not a new challenge for TTCN-3. It is quite interesting to look at TTCN-3 from a specific point of view, that of handling complexity. The very first version of TTCN-3 was create to handle the new complexities of testing modern systems, for example when several test components need to run parallelly and in a concerted way to properly test. Than came component extension …. Information hiding … etc First version http://www.etsi.org/deliver/etsi_es/201800_201899/20187301/01.00.10_50/es_20187301v010010m.pdf 3.1.1: https://www.etsi.org/deliver/etsi_es/201800_201899/20187301/03.01.01_60/es_20187301v030101p.pdf 4.5.1: http://www.etsi.org/deliver/etsi_es/201800_201899/20187301/04.05.01_60/es_20187301v040501p.pdf User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Evolution … + Object Orientation + Exception handling + Advanced matching And some of the most important features of the new additions to and extensions of the language were also meant to further help with addressing complexity. First version http://www.etsi.org/deliver/etsi_es/201800_201899/20187301/01.00.10_50/es_20187301v010010m.pdf 3.1.1: https://www.etsi.org/deliver/etsi_es/201800_201899/20187301/03.01.01_60/es_20187301v030101p.pdf 4.5.1: http://www.etsi.org/deliver/etsi_es/201800_201899/20187301/04.05.01_60/es_20187301v040501p.pdf User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Why? Why did we need to extend TTCN-3 with Object-oriented features? User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Test are getting bigger + more and more complex ! This is the architecture of a test system. The points are TTCN-3 and ASN.1 modules. The lines are import statements connecting the modules. This network contains small world and scale-free properties. If we select any 2 nodes, the shortest path between them will contain at most 5 other nodes. The distribution of the connection follows the power law. Just like the Internet, the human brain and software systems. At the scale of tests we have nowadays, maintainability and software quality become important questions. (otherwise development will not be able to keep up) Related publication: K. Szabados, Structural Analysis of Large TTCN-3 Projects in proceedings of: Testing of Software and Communication Systems, 21st IFIP WG 6.1 International Conference, TESTCOM 2009 and 9th International Workshop, FATES 2009, Eindhoven, The Netherlands, November 2-4, 2009. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Object Orientation [public | private] type [external] class [@final |@abstract] Identifier [extends Identifier] [runsOnSpec] [systemSpec] [mtcSpec] "{" {ClassMember} "}" [finally StatementBlock] A new language extension … with quite a lot to unpack here. I will go through some of the features using examples. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Class example type class MyClass { const integer a := 2; function doSomething (integer a := 3) { log(a); log(this.a); } Classes appear as type and as expected from other OO programming languages can contain both members and functions. This way it will be possible to organize the source code in a way where data and the functions operating on it are kept together. In the example: First log logs 3, the second 2. As present in the example this.a can be used to access a member that has the same name as a formal parameter. Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Visibility type class MyClass { private const integer a := 2; function doSomething (integer a := 3) { log(a); log(this.a); } Members can have visibility. Private members can only be accessed directly by members of the class itself. Providing support for fine-grained information hiding. In the example: First log logs 3, the second 2. Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Class hierarchy type class MyExtension extends MyClass { function doSomethingElse () { log(a); log(this.a); } Classes can form a single inheritance hierarchy. That is each class can have zero or one other class it extends. (zero extensions means extending the root class type object) The extended class is called the superclass, the extending class is the subclass. In the example: First log logs 3, the second log causes an error as it can not use the private member of it superclass. Methods can be overridden, but not overloaded ! Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Class hierarchy type class @final MyExtension extends MyClass { function doSomethingElse () { log(a); } Final classes can not be subclassed. This is good way, to protect one’s library from being extended. In the example: The log logs 3 (for the default value of the parameter). Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing External Classes external type class Stack { function push(integer v); function pop() return integer; function isEmpty() return boolean; } External classes are a way to connect efficiently implemented external libraries, to TTCN-3 internal usage. Method calls to objects of external classes are delegated via the platform adapter to the corresponding method of the external class. And represented inside TTCN-3 with an object of this class, allowing the checking for the proper usage of it’s member functions in TTCN-3 code. This feature can enable the usage of efficient external collection within TTCN-3. But please note, when using external feature, the usual testing related benefits of TTCN-3 are not available (for example safe termination is not guaranteed if the external library runs into a stack overflow error) Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Abstract classes type class @abstract MyExtension { function @abstract doSomething (); } Abstract classes can contains abstract member functions. Non-abstract classes are not allowed to contain abstract functions. All abstract functions need to be defined by all non-abstract subclasses. This allows library writers to write their functionalities on an abstract level, and the user to fill in the actual type in her own test code. For example: the library only needs to know that the objects of this class can log themselves using a “logme” function … but it is up to the user of the library to provide the actual implementation of how her objects should log themselves. Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Runs on type class MyClass runs on Component1 system Component2 { function doSomething () { … } Classes can have runs on, mtc and system clauses, which restrict the component context that is allowed to create objects of that class. Member functions of a class with runs on, mtc or system clauses shall not have their own clauses, but inherit them from their class. And objects of such classes can only be created in functions that run on the described components. In the example: The member function doSomething inherits the runs on, mtc and system clauses of the class. Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Dynamic class discrimination type class B extends A {} … var A v_a := B.create(); select class (v_a) { case (B) { … } case (A) { … } } An object of a class can be created with the .create() function, which will invoke the constructor of the class (having the name “create”) It is possible to branch the execution of the code based on the dynamic class of the object. In the example: case (B) will be selected as v_a has B as dynamic type (and A for static type) Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Dynamic class discrimination type class B extends A {} … var A v_a := B.create(); if (v_a of B) { var B v_b := v_a => (B); } Dynamic class discrimination + casting In the example: v_a will be cast to type B before assigned to v_b Example code from the standard extension for a simple class. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Exception handling function f_init(in charstring name) exception (charstring, integer) … { ... if (name_was_not_registered) { raise ("Could not initialize " & name); } ... } An other hardship when creating large libraries is the handling of exceptional execution path and release –ing resources in case of errors. Exceptions can be thrown to handle exceptional behaviors. It is also possible (although optional) to list the exceptions that can be thrown inside a function in the function’s signature. Previously functions could indicate such special execution step, by returning error indication values (for example an integer), that on the receiving side is easily forgotten to be handled. When the exception list is described for the function, tools will have a chance to provide stronger checks (is there an exception that is expected, but not handled here?) In the example: When the exception is raised f_init terminates. Example code from the standard extension for throwing an exception. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Exception handling function f_operation(in charstring user1) exception (integer) … { f_init(user1); } catch (charstring e) { … } catch (integer e) { raise e; } Exceptions do not define new types, already existing types can be used. For example throwing an exception with a charstring description, or an integer value. Please note, that there is no try clause in the above code. Exception catching is not related to a specific try-catch kind of construct like in C++/Java style, but can be added to statementblock (also functions, altsteps, testcases). In the example: In both catch cases it is possible to release resources. The first catch will also terminate the function, returning. The second catch clause leaves the function raising the exception again so that it can be handled in the calling function. Example code from the standard extension for catching an exception. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Exception handling testcase t_myTest1() runs on myComponent { f_init("unknown user"); … } finally { } In TTCN-3 it will also be possible to use a finally clause. The contents of this clause get executed when the scope is left, independent of there being an execution or not. This allows for safe releasing of resources. In the example: An exception will be raised in the call to f_init. Because of the raised exception, execution continues in the finally block. In the final block component resources can be freed and as the exception is not cought before leaving the testcase, a dynamic error is reported. Example code from the standard extension for throwing an exception. User Conference on Advanced Automated Testing © All rights reserved

Object Orientation helps to manage complexity. Test are getting bigger + more and more complex ! Object Orientation was seen in many cases to help in creating more maintainable software architectures in software development. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Future directions Experience report and feedback is needed from users To see how much Object-Orientation is needed/beneficial for testing. To prioritize new Object-Orientation features. User Conference on Advanced Automated Testing © All rights reserved

Thank you for your attention STF550@etsi.org Should someone feel like having seen these constructs in C++/Java like languages … we have done a good job, in creating a new language feature that new users can pick up and start using right away. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Advanced matching type record of integer Numbers; template Numbers mw_sorted := @dynamic { for (var integer v_i := 1; v_i < lengthof(value); v_i := v_i + 1) { if (value[v_i-1] > value[v_i]) { return false; } } return true; To simplify and increase the power of TTCN-3 template we also introduced advanced matching constructs. Of which maybe dynamic matching is the most powerful. Similar to other matching mechanisms, it can be considered as a boolean function that indicates successful matching for the value to be matched by returning the value true and unsuccessful matching by returning the value false. But in this case the user is able to provide her own algorithm for evaluating the matching criteria. In the above example value is of type Numbers. The template uses dynamic matching, and matches if the elements in the record of value are in a descending order. Example code from the advanced matching standard extension for dynamic matching. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Advanced matching New ways to combine templates: Conjunct Implies Except Disjunct Handling repetition (#(2, 5)). Value retrieval from matching (->). To simplify and increase the power of TTCN-3 template we also introduced advanced matching constructs to combine existing templates. Conjunct: The conjunction matching mechanism is used when a value shall fulfil several distinct conditions. Implies: The implication matching mechanism is used when a match is checked only if specified conditions are met. Except: The exclusion matching mechanism is used when a general matching rule is to be restricted by an exception. Disjunct: The disjunction matching mechanism specifies one or more alternatives for matching multiple elements of record of, set of or array. Repetition is a specific symbol used inside record of, array, bitstring, hexstring or octetstring templates to match repeated sequences of items. In case of a successful template match, the value which matches the template can be assigned to a variable. This can be specified using the “->” symbol. User Conference on Advanced Automated Testing © All rights reserved

Advanced Automated Testing Advanced matching template integer mw_t1 := conjunct ((100 .. infinity), @dynamic f_isprime); template integer mw_t2 := (1..100) except (48, 64); template integer mw_t3 := ((1..3) -> v); // mw_t1 template matches prime numbers greater than 100 // mw_t2 template matches all integer in the range 1..100 except 48 and 64 // mw_t3 always matches (1..3) and assigns the value to v. Example code from the advanced matching standard extension. User Conference on Advanced Automated Testing © All rights reserved