Commit c3a92651 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: added 50101_top_level negative tests, 5010102_abstract tests


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent bc3b6fc5
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.2, Ensure that abstract classes cannot be explicitly instantiated.
** @verdict pass reject
**
** modified by Miklos Magyari
*****************************************************************/
module NegSem_5010102_abstractClasses_001 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
public type class @abstract t_class_abstract {
public function log_sending();
}
public type class t_class_subclass extends t_class_abstract {
public function log_sending() {
log("Sending messages!!!");
}
}
testcase tc_NegSem_5010102_abstractClasses_001() runs on GeneralComp {
var t_class_abstract vl_a := t_class_abstract.create(); //not allowed
setverdict(pass);
}
control {
execute(tc_NegSem_5010102_abstractClasses_001());
}
}
\ No newline at end of file
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.0, Ensure that a class members' names are unique.
** @verdict pass reject
**
** modified by Miklos Magyari
*****************************************************************/
module NegSem_50101_top_level_002 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
public type class t_class_member_overloading {
var integer v_i := 10;
public function v_i() return integer { // not allowed
return 5;
}
}
testcase tc_NegSem_50101_top_level_002() runs on GeneralComp {
var t_class_member_overloading vl_a := t_class_member_overloading.create();
if (vl_a.v_i() == 5) {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_NegSem_50101_top_level_002());
}
}
\ No newline at end of file
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.0, Ensure that class type cannot be the contained value of an anytype value.
** @verdict pass reject
**
** modified by Miklos Magyari
*****************************************************************/
module NegSem_50101_top_level_007 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
public type class t_class_anytype_class {
//empty class
}
testcase tc_NegSem_50101_top_level_007() runs on GeneralComp {
var t_class_anytype_class vl_class := t_class_anytype_class.create();
var anytype vl_Myanytype;
vl_Myanytype.t_class_anytype_class := v_class; // not allowed
setverdict(pass);
}
control {
execute(tc_NegSem_50101_top_level_007());
}
} with {
extension "anytype t_class_anytype_class"
}
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.0, Ensure that the functions of a class shall not have a runs on, mtc or system clause.
** @verdict pass reject
**
** modified by Miklos Magyari
*****************************************************************/
module NegSem_50101_top_level_008 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
public type class t_class_with_utility_functions {
public function isRightCharstring(in charstring pl_arg_cstr) runs on GeneralComp return boolean { //not allowed
if (pl_arg_cstr == "def") {
return true;
} else {
return false;
}
}
public function isPositive(in integer pl_arg_int) mtc GeneralComp return boolean { //not allowed
if (pl_arg_int > 0) {
return true;
} else {
return false;
}
}
public function isNegative(in integer pl_arg_int) system GeneralComp return boolean { //not allowed
if (pl_arg_int < 0) {
return true;
} else {
return false;
}
}
const integer c_int := 5057;
}
testcase tc_NegSem_50101_top_level_008() runs on GeneralComp {
var t_class_with_utility_functions vl_a := t_class_with_utility_functions.create();
if (vl_a.c_int == 5057) {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_NegSem_50101_top_level_008());
}
}
\ No newline at end of file
/*****************************************************************
** @author STF 572
** @version 0.0.1
** @purpose 5.1.1.2, Ensure that use abstract classes correctly.
** @verdict pass accept
**
** modified by Miklos Magyari
*****************************************************************/
module Sem_5010102_abstractClasses_001 "TTCN-3:2018 Object-Oriented" {
type component GeneralComp {
}
public type class @abstract t_class_abstract {
public function doSomethingSpecial(integer pl_arg) return integer;
}
public type class t_class_subclass extends t_class_abstract {
public function doSomethingSpecial(integer pl_arg) return integer {
return pl_arg + 1;
}
}
testcase tc_Sem_5010102_abstractClasses_001() runs on GeneralComp {
var t_class_subclass vl_a := t_class_subclass.create();
if (vl_a.doSomethingSpecial(64) == 65) {
setverdict(pass);
} else {
setverdict(fail);
}
}
control {
execute(tc_Sem_5010102_abstractClasses_001());
}
}
\ No newline at end of file
......@@ -9,7 +9,6 @@
package org.eclipse.titan.regressiontests.designer.statictests.Basic_tests;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IMarker;
......@@ -38,15 +37,72 @@ public class OOP_Semantic_tests {
return;
Designer_plugin_tests.ignoreMarkersOnFile(DIR_PATH + OOP_NEGATIVE_BASIC_SEMANTIC);
for (String testFile : OOP_Syntax_tests.testFilesNegative) {
Designer_plugin_tests.ignoreMarkersOnFile(OOP_Syntax_tests.OOP_DIR_PATH + "negative/" + testFile);
}
}
@Test
public void OOPNegativeSemantic_Test() throws Exception {
if (parseOOP) {
Designer_plugin_tests.checkSemanticMarkersOnFile(oopNegative_ttcn_initializer(), DIR_PATH + OOP_NEGATIVE_BASIC_SEMANTIC);
Designer_plugin_tests.checkSemanticMarkersOnFile(NegSem_50101_top_level_002_ttcn_initializer(),
OOP_Syntax_tests.OOP_DIR_PATH + "negative/NegSem_50101_top_level_002.ttcn");
Designer_plugin_tests.checkSemanticMarkersOnFile(NegSem_50101_top_level_007_ttcn_initializer(),
OOP_Syntax_tests.OOP_DIR_PATH + "negative/NegSem_50101_top_level_007.ttcn");
Designer_plugin_tests.checkSemanticMarkersOnFile(NegSem_50101_top_level_008_ttcn_initializer(),
OOP_Syntax_tests.OOP_DIR_PATH + "negative/NegSem_50101_top_level_008.ttcn");
Designer_plugin_tests.checkSemanticMarkersOnFile(NegSem_5010102_abstractClasses_001_ttcn_initializer(),
OOP_Syntax_tests.OOP_DIR_PATH + "negative/NegSem_5010102_abstractClasses_001.ttcn");
}
}
private ArrayList<MarkerToCheck> NegSem_50101_top_level_002_ttcn_initializer() {
//NegSem_50101_top_level_002.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(2);
int lineNum = 16;
markersToCheck.add(new MarkerToCheck("Duplicate field name `v_i' was first declared here", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Duplicate field name `v_i' was declared here again", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
private ArrayList<MarkerToCheck> NegSem_50101_top_level_007_ttcn_initializer() {
//NegSem_50101_top_level_007.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(1);
int lineNum = 21;
markersToCheck.add(new MarkerToCheck("Class type cannot be the contained value of an any type value", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
private ArrayList<MarkerToCheck> NegSem_50101_top_level_008_ttcn_initializer() {
//NegSem_50101_top_level_008.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(3);
int lineNum = 16;
markersToCheck.add(new MarkerToCheck("Class functions cannot have a `runs on` clause", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 8;
markersToCheck.add(new MarkerToCheck("Class functions cannot have an `mtc` clause", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 7;
markersToCheck.add(new MarkerToCheck("Class functions cannot have a `system` clause", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
private ArrayList<MarkerToCheck> NegSem_5010102_abstractClasses_001_ttcn_initializer() {
//NegSem_5010102_abstractClasses_001.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(1);
int lineNum = 27;
markersToCheck.add(new MarkerToCheck("An abstract class cannot be instantiated", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(59);
......
......@@ -33,7 +33,15 @@ public class OOP_Syntax_tests {
// "Sem_50101_top_level_005.ttcn",
// "Sem_50101_top_level_006.ttcn",
"Sem_50101_top_level_007.ttcn",
"Sem_50101_top_level_008.ttcn"
"Sem_50101_top_level_008.ttcn",
"Sem_5010102_abstractClasses_001.ttcn"
);
public static List<String> testFilesNegative = Arrays.asList(
"NegSem_50101_top_level_002.ttcn",
"NegSem_50101_top_level_007.ttcn",
"NegSem_50101_top_level_008.ttcn",
"NegSem_5010102_abstractClasses_001.ttcn"
);
private static boolean parseOOP;
......@@ -49,6 +57,9 @@ public class OOP_Syntax_tests {
for (String testFile : testFilesPositive) {
Designer_plugin_tests.ignoreMarkersOnFile(OOP_DIR_PATH + "positive/" + testFile);
}
for (String testFile : testFilesNegative) {
Designer_plugin_tests.ignoreMarkersOnFile(OOP_DIR_PATH + "negative/" + testFile);
}
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment