Commit 367b7881 authored by balaskoa's avatar balaskoa
Browse files

fuzzy tests have been added to Regression_Test_java


Signed-off-by: default avatarbalaskoa <Jeno.Balasko@ericsson.com>
parent 8f07cad0
/******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
// This module contains functions and altsteps for testing fuzzy parameters
module FuzzyFunctions {
import from FuzzyTypes all;
// Functions with fuzzy parameters
// -------------------------------
//
// These functions add, multiply or concatenate their fuzzy parameter
// with itself a specified amount of times, and return the result.
// Functions with fuzzy parameters of structured types perform these
// operations on their elements or fields.
// Functions with fuzzy template parameters perform matching on a
// list of values.
//
// Some of the functions are multi-leveled, testing the use of fuzzy
// parameters passed as another function's fuzzy parameter.
// Some of the multi-leveled functions have a lazy parameter instead of
// a fuzzy one, to test the conversions between fuzzy and lazy parameters.
function f_fuzzy_usage_int(in @fuzzy integer p_fuzzy, in integer p_usages) return integer {
var integer v_sum := 0;
for (var integer i := 0; i < p_usages; i := i + 1) {
v_sum := v_sum + p_fuzzy;
}
return v_sum;
}
function f_fuzzy_usage_float(in @fuzzy float p_fuzzy, in integer p_usages) return float {
var float v_sum := 0.0;
for (var integer i := 0; i < p_usages; i := i + 1) {
v_sum := v_sum + p_fuzzy;
}
return v_sum;
}
function f_wrapped_fuzzy_usage_float(in @fuzzy float p_fuzzy, in integer p_outer_usages, in integer p_inner_usages) return float {
var float v_prod := 1.0;
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
v_prod := v_prod * f_fuzzy_usage_float(p_fuzzy, p_inner_usages);
}
return v_prod;
}
function f_fuzzy_usage_cstr(in @fuzzy charstring p_fuzzy, in integer p_usages) return charstring {
var charstring v_res := "";
for (var integer i := 0; i < p_usages; i := i + 1) {
v_res := v_res & p_fuzzy;
}
return v_res;
}
function f_lazy_usage_bstr(in @lazy bitstring p_lazy, in integer p_usages) return bitstring {
var bitstring v_res := ''B;
for (var integer i := 0; i < p_usages; i := i + 1) {
v_res := v_res & p_lazy;
}
return v_res;
}
function f_wrapped_fuzzy_usage_bstr(in @fuzzy bitstring p_fuzzy, in integer p_outer_usages, in integer p_inner_usages) return bitstring {
var bitstring v_res := ''B;
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_fuzzy would be treated as lazy)
v_res := v_res & p_fuzzy;
v_res := v_res & f_lazy_usage_bstr(p_fuzzy, p_inner_usages);
}
return v_res;
}
function f_fuzzy_usage_hstr(in @fuzzy hexstring p_fuzzy, in integer p_usages) return hexstring {
var hexstring v_res := ''H;
for (var integer i := 0; i < p_usages; i := i + 1) {
v_res := v_res & p_fuzzy;
}
return v_res;
}
function f_wrapped_lazy_usage_hstr(in @lazy hexstring p_lazy, in integer p_outer_usages, in integer p_inner_usages) return hexstring {
var hexstring v_res := ''H;
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_lazy would be treated as fuzzy)
v_res := v_res & p_lazy;
v_res := v_res & f_fuzzy_usage_hstr(p_lazy, p_inner_usages);
}
return v_res;
}
function f_fuzzy_usage_ostr(in @fuzzy octetstring p_fuzzy, in integer p_usages) return octetstring {
var octetstring v_res := ''O;
for (var integer i := 0; i < p_usages; i := i + 1) {
v_res := v_res & p_fuzzy;
}
return v_res;
}
function f_wrapped_lazy_usage_ostr(in @lazy octetstring p_lazy, in integer p_outer_usages, in integer p_inner_usages) return octetstring {
var octetstring v_res := ''O;
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_lazy would be treated as fuzzy)
v_res := v_res & p_lazy;
v_res := v_res & f_fuzzy_usage_ostr(p_lazy, p_inner_usages);
}
return v_res;
}
function f_double_wrapped_fuzzy_usage_ostr(in @fuzzy octetstring p_fuzzy, in integer p_outer_usages, in integer p_middle_usages, in integer p_inner_usages) return octetstring {
var octetstring v_res := ''O;
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_fuzzy would be treated as lazy)
v_res := v_res & p_fuzzy;
v_res := v_res & f_wrapped_lazy_usage_ostr(p_fuzzy, p_middle_usages, p_inner_usages);
}
return v_res;
}
function f_lazy_usage_ustr(in @lazy universal charstring p_lazy, in integer p_usages) return universal charstring {
var universal charstring v_res := "";
for (var integer i := 0; i < p_usages; i := i + 1) {
v_res := v_res & p_lazy;
}
return v_res;
}
function f_wrapped_fuzzy_usage_ustr(in @fuzzy universal charstring p_fuzzy, in integer p_outer_usages, in integer p_inner_usages) return universal charstring {
var universal charstring v_res := "";
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_fuzzy would be treated as lazy)
v_res := v_res & p_fuzzy;
v_res := v_res & f_lazy_usage_ustr(p_fuzzy, p_inner_usages);
}
return v_res;
}
function f_double_wrapped_lazy_usage_ustr(in @lazy universal charstring p_lazy, in integer p_outer_usages, in integer p_middle_usages, in integer p_inner_usages) return universal charstring {
var universal charstring v_res := "";
for (var integer i := 0; i < p_outer_usages; i := i + 1) {
// chaining these concatenations does not currently work (p_lazy would be treated as fuzzy)
v_res := v_res & p_lazy;
v_res := v_res & f_wrapped_fuzzy_usage_ustr(p_lazy, p_middle_usages, p_inner_usages);
}
return v_res;
}
function f_wrapped_fuzzy_usage_rec(in @fuzzy Rec p_fuzzy, in integer p_rec_usages, in integer p_int_usages, in integer p_str_usages) return Rec {
var Rec v_res := { num := 0, str := "" };
for (var integer i := 0; i < p_rec_usages; i := i + 1) {
v_res.num := v_res.num + f_fuzzy_usage_int(p_fuzzy.num, p_int_usages);
v_res.str := v_res.str & f_fuzzy_usage_cstr(p_fuzzy.str, p_str_usages);
}
return v_res;
}
function f_fuzzy_usage_int_temp(in template @fuzzy integer pt_fuzzy, in IntList p_values) return integer {
var integer v_nof_matches := 0;
for (var integer i := 0; i < lengthof(p_values); i := i + 1) {
if (match(p_values[i], pt_fuzzy)) {
v_nof_matches := v_nof_matches + 1;
}
}
return v_nof_matches;
}
function f_wrapped_fuzzy_usage_list_temp(in template @fuzzy IntList pt_fuzzy, in IntList p_values) return integer {
var integer v_nof_matches := 0;
for (var integer i := 0; i < lengthof(pt_fuzzy); i := i + 1) {
v_nof_matches := v_nof_matches + f_fuzzy_usage_int_temp(pt_fuzzy[i], p_values);
}
return v_nof_matches;
}
// Altstep with fuzzy parameters
altstep as_fuzzy_bool(in @fuzzy boolean p_fuzzy) runs on CT {
var template integer vt_msg := (1..10);
[p_fuzzy] pt.receive(vt_msg) { }
[not p_fuzzy] pt.receive(vt_msg) { }
[p_fuzzy] pt.receive { }
[not p_fuzzy] pt.receive { }
}
// Functions used as fuzzy parameters
// ----------------------------------
//
// These functions are used as the expressions of fuzzy parameters.
// Each function returns its value or template parameter, and
// increases a counter, to help test how many times a fuzzy
// parameter's expression was evaluated.
function f_fuzzy_return_int(in integer p_ret) runs on CT return integer {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_float(in float p_ret) runs on CT return float {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_cstr(in charstring p_ret) runs on CT return charstring {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_bstr(in bitstring p_ret) runs on CT return bitstring {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_hstr(in hexstring p_ret) runs on CT return hexstring {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_ostr(in octetstring p_ret) runs on CT return octetstring {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_ustr(in universal charstring p_ret) runs on CT return universal charstring {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_bool(in boolean p_ret) runs on CT return boolean {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_rec(in Rec p_ret) runs on CT return Rec {
ct_calls := ct_calls + 1;
return p_ret;
}
function f_fuzzy_return_int_temp(in template integer pt_ret) runs on CT return template integer {
ct_calls := ct_calls + 1;
return pt_ret;
}
function f_fuzzy_return_list_temp(in template IntList pt_ret) runs on CT return template IntList {
ct_calls := ct_calls + 1;
return pt_ret;
}
function f_fuzzy_return_uni_temp(in template Uni pt_ret) runs on CT return template Uni {
ct_calls := ct_calls + 1;
return pt_ret;
}
} // end of module
/******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
// This module contains test cases for fuzzy parameters
module FuzzyTestcases {
import from FuzzyTypes all;
import from FuzzyFunctions all;
testcase tc_fuzzy_int() runs on CT {
var integer v_usages := 0;
var integer v_exp_res := 0;
var integer v_res := f_fuzzy_usage_int(f_fuzzy_return_int(1), v_usages);
if (ct_calls != v_usages) {
setverdict(fail, "Expected ", v_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_usages := 3;
v_exp_res := 6;
v_res := f_fuzzy_usage_int(f_fuzzy_return_int(2), v_usages);
if (ct_calls != v_usages) {
setverdict(fail, "Expected ", v_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_wrapped_float() runs on CT {
var integer v_outer_usages := 0;
var integer v_inner_usages := 0;
var float v_exp_res := 1.0;
var float v_res := f_wrapped_fuzzy_usage_float(f_fuzzy_return_float(0.6), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_inner_usages) {
setverdict(fail, "Expected ", v_outer_usages * v_inner_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 3;
v_inner_usages := 4;
v_exp_res := 1000.0;
v_res := f_wrapped_fuzzy_usage_float(f_fuzzy_return_float(2.5), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_inner_usages) {
setverdict(fail, "Expected ", v_outer_usages * v_inner_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
// non-standard
testcase tc_fuzzy_in_fuzzy_cstr() runs on CT {
var integer v_outer_usages := 0;
var integer v_inner_usages := 0;
var charstring v_exp_res := "";
var charstring v_res := f_fuzzy_usage_cstr(f_fuzzy_usage_cstr(f_fuzzy_return_cstr("ab"), v_inner_usages), v_outer_usages);
if (ct_calls != v_outer_usages) {
setverdict(fail, "Expected ", v_outer_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 2;
v_inner_usages := 3;
v_exp_res := "abababababab"; // "ab" x 6
v_res := f_fuzzy_usage_cstr(f_fuzzy_usage_cstr(f_fuzzy_return_cstr("ab"), v_inner_usages), v_outer_usages);
if (ct_calls != v_outer_usages) {
setverdict(fail, "Expected ", v_outer_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_lazy_wrapped_in_fuzzy_bstr() runs on CT {
var integer v_outer_usages := 0;
var integer v_inner_usages := 0;
var bitstring v_exp_res := ''B;
var bitstring v_res := f_wrapped_fuzzy_usage_bstr(f_fuzzy_return_bstr('10'B), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * 2) {
setverdict(fail, "Expected ", v_outer_usages * 2, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 3;
v_inner_usages := 4;
v_exp_res := '101010101010101010101010101010'B; // '10'B x 15
v_res := f_wrapped_fuzzy_usage_bstr(f_fuzzy_return_bstr('10'B), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * 2) {
setverdict(fail, "Expected ", v_outer_usages * 2, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_wrapped_in_lazy_hstr() runs on CT {
var integer v_outer_usages := 0;
var integer v_inner_usages := 0;
var hexstring v_exp_res := ''H;
var hexstring v_res := f_wrapped_lazy_usage_hstr(f_fuzzy_return_hstr('12EF'H), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_inner_usages) {
setverdict(fail, "Expected ", v_outer_usages * v_inner_usages, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 3;
v_inner_usages := 2;
v_exp_res := 'AC3AC3AC3AC3AC3AC3AC3AC3AC3'H; // 'AC3'H x 9
v_res := f_wrapped_lazy_usage_hstr(f_fuzzy_return_hstr('AC3'H), v_outer_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_inner_usages + 1) {
setverdict(fail, "Expected ", v_outer_usages * v_inner_usages + 1, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_wrapped_in_lazy_wrapped_in_fuzzy_ostr() runs on CT {
var integer v_outer_usages := 0;
var integer v_middle_usages := 0;
var integer v_inner_usages := 0;
var octetstring v_exp_res := ''O;
var octetstring v_res := f_double_wrapped_fuzzy_usage_ostr(f_fuzzy_return_ostr('12EF'O), v_outer_usages, v_middle_usages, v_inner_usages);
if (ct_calls != v_outer_usages * (v_middle_usages * v_inner_usages + 1)) {
setverdict(fail, "Expected ", v_outer_usages * (v_middle_usages * v_inner_usages + 1), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 2;
v_middle_usages := 2;
v_inner_usages := 3;
v_exp_res := 'DADADADADADADADADADADADADADADADADADA'O; // 'DE'O x 18
v_res := f_double_wrapped_fuzzy_usage_ostr(f_fuzzy_return_ostr('DA'O), v_outer_usages, v_middle_usages, v_inner_usages);
if (ct_calls != v_outer_usages * (v_middle_usages * v_inner_usages + 2)) {
setverdict(fail, "Expected ", v_outer_usages * (v_middle_usages * v_inner_usages + 2), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_lazy_wrapped_in_fuzzy_wrapped_in_lazy_ustr() runs on CT {
var integer v_outer_usages := 0;
var integer v_middle_usages := 0;
var integer v_inner_usages := 0;
var universal charstring v_exp_res := "";
var universal charstring v_res := f_double_wrapped_lazy_usage_ustr(f_fuzzy_return_ustr(char(0, 1, 2, 3)), v_outer_usages, v_middle_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_middle_usages * 2) {
setverdict(fail, "Expected ", v_outer_usages * v_middle_usages * 2, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_outer_usages := 2;
v_middle_usages := 3;
v_inner_usages := 2;
v_exp_res := "áááááááááááááááááááá"; // "á" x 20
v_res := f_double_wrapped_lazy_usage_ustr(f_fuzzy_return_ustr("á"), v_outer_usages, v_middle_usages, v_inner_usages);
if (ct_calls != v_outer_usages * v_middle_usages * 2 + 1) {
setverdict(fail, "Expected ", v_outer_usages * v_middle_usages * 2 + 1, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_wrapped_rec() runs on CT {
var integer v_rec_usages := 0;
var integer v_int_usages := 0;
var integer v_str_usages := 0;
var Rec v_rec := { num := 5, str := "xy" };
var Rec v_exp_res := { num := 0, str := "" };
var Rec v_res := f_wrapped_fuzzy_usage_rec(f_fuzzy_return_rec(v_rec), v_rec_usages, v_int_usages, v_str_usages);
if (ct_calls != v_rec_usages * (v_int_usages + v_str_usages)) {
setverdict(fail, "Expected ", v_rec_usages * (v_int_usages + v_str_usages), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_rec_usages := 2;
v_int_usages := 4;
v_str_usages := 3;
v_exp_res := { num := 40, str := "xyxyxyxyxyxy" };
v_res := f_wrapped_fuzzy_usage_rec(f_fuzzy_return_rec(v_rec), v_rec_usages, v_int_usages, v_str_usages);
if (ct_calls != v_rec_usages * (v_int_usages + v_str_usages)) {
setverdict(fail, "Expected ", v_rec_usages * (v_int_usages + v_str_usages), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_int_temp() runs on CT {
var template integer vt_int := (0..infinity);
var IntList v_values := { };
var integer v_exp_res := 0;
var integer v_res := f_fuzzy_usage_int_temp(f_fuzzy_return_int_temp(vt_int), v_values);
if (ct_calls != lengthof(v_values)) {
setverdict(fail, "Expected ", lengthof(v_values), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
v_values := { 1, -6, 199, 0, -3000 };
v_exp_res := 3;
v_res := f_fuzzy_usage_int_temp(f_fuzzy_return_int_temp(vt_int), v_values);
if (ct_calls != lengthof(v_values)) {
setverdict(fail, "Expected ", lengthof(v_values), " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_wrapped_list_temp() runs on CT {
var template IntList vt_list := { };
var IntList v_values := { };
var integer v_exp_res := 0;
var integer v_res := f_wrapped_fuzzy_usage_list_temp(f_fuzzy_return_list_temp(vt_list), v_values);
if (ct_calls != (lengthof(v_values) + 1) * lengthof(vt_list) + 1) {
setverdict(fail, "Expected ", (lengthof(v_values) + 1) * lengthof(vt_list) + 1, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
ct_calls := 0;
vt_list := { ?, (1, (100..200)), (-infinity..0), -2 };
v_values := { 1, -6, 199, 0, -3000 };
v_exp_res := 10;
v_res := f_wrapped_fuzzy_usage_list_temp(f_fuzzy_return_list_temp(vt_list), v_values);
if (ct_calls != (lengthof(v_values) + 1) * lengthof(vt_list) + 1) {
setverdict(fail, "Expected ", (lengthof(v_values) + 1) * lengthof(vt_list) + 1, " calls, got ", ct_calls);
}
if (v_res != v_exp_res) {
setverdict(fail, "Expected result: ", v_exp_res, ", got: ", v_res);
}
setverdict(pass);
}
testcase tc_fuzzy_altstep_bool() runs on CT {
connect(self:pt, self:pt);
pt.send(3);
timer tmr;
tmr.start(0.5);
alt {
[] tmr.timeout {
setverdict(fail, "First test timed out.");
}
[] as_fuzzy_bool(f_fuzzy_return_bool(false));
}
if (ct_calls != 2) {
setverdict(fail, "Expected 2 calls, got ", ct_calls);
}
ct_calls := 0;
pt.send(-6);
tmr.stop;
tmr.start(0.5);
alt {
[] tmr.timeout {
setverdict(fail, "Second test timed out.");
}
[] as_fuzzy_bool(f_fuzzy_return_bool(true));
}
if (ct_calls != 3) {
setverdict(fail, "Expected 3 calls, got ", ct_calls);
}
setverdict(pass);
}
// Testcase with fuzzy parameters
testcase tc_fuzzy_testcase_uni(in template @fuzzy Uni pt_fuzzy) runs on CT {
var Uni v_values[4] := {
{ i := 10 },
{ os := 'AB12F9'O },
{ i := -991 },
{ ucs := "eeeeee" }
};
var integer v_nof_matches := 0;
for (var integer i := 0; i < lengthof(v_values); i := i + 1) {
if (match(v_values[i], pt_fuzzy)) {
v_nof_matches := v_nof_matches + 1;