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

OOP: added tests for method override


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 37122e56
......@@ -190,6 +190,36 @@ type class FuncClass extends BaseFunctionClass {
}
}
// private methods can be overridden in subclass
// protected and public classes can only be overriden with the same formal param list
type class ClassWithPrivate {
private function f_override(in float pl_float) return integer {
return 1;
}
function f_override2(in float pl_float) return integer {
return 1;
}
public function f_override3(in float pl_float) return integer {
return 1;
}
}
type class ClassWithPrivateExt extends ClassWithPrivate {
public function f_override(charstring pl_chr) return charstring {
return pl_chr;
}
public function f_override2(charstring pl_chr) return charstring {
return pl_chr;
}
public function f_override3(charstring pl_chr) return charstring {
return pl_chr;
}
}
// function with class parameter
function f_class_param(FuncClass pl_fun) {
var integer vl_int := pl_fun.f_dummy(1); // type mismatch
......
......@@ -16,7 +16,7 @@
*
******************************************************************************/
module classes {
module Sem_5010104_finalClasses_001 language "TTCN-3:2018 Object-Oriented" {
type component CT {
port PT pt_PT;
......@@ -253,6 +253,20 @@ type class CastingClass extends BaseFunctionClass {
}
}
// private methods can be overridden in subclass
type class ClassWithPrivate {
private function f_override(in float pl_float) return integer {
return 1;
}
}
type class ClassWithPrivateExt extends ClassWithPrivate {
public function f_override(charstring pl_chr) return charstring {
return pl_chr;
}
}
testcase tc_basicSyntax() runs on CT {
var object vl_obj := MinimalClass.create;
......
......@@ -45,7 +45,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(29);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(31);
int lineNum = 28;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 9;
......@@ -64,9 +64,7 @@ public class OOP_Semantic_tests {
}
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Trait method cannot have a function body", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Trait classes cannot have a constructor", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 16;
lineNum += 20;
markersToCheck.add(new MarkerToCheck("Reference to non-existent field `nonexist' in union template for type `@classesNegativeSemantic.MyUnion'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Local Definiton `vl_b' collides with definition inherited from class type `@classesNegativeSemantic.SubClass'", lineNum, IMarker.SEVERITY_ERROR));
......@@ -84,14 +82,20 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("A class cannot be both abstract and trait", ++lineNum, IMarker.SEVERITY_ERROR));
lineNum += 12;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 5;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
lineNum += 15;
markersToCheck.add(new MarkerToCheck("`super' reference is only valid inside class bodies", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `charstring'", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", ++lineNum, IMarker.SEVERITY_ERROR));
lineNum += 15;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Definition is overridden with different formal parameters", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 4;
markersToCheck.add(new MarkerToCheck("Formal parameter list differs from previous definition", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 7;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `integer' was expected instead of `float'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 11;
markersToCheck.add(new MarkerToCheck("Unknown field reference", lineNum, IMarker.SEVERITY_ERROR));
......
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