6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_4271_test.py

268 lines
7.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-23 20:41:55 +01:00
"""
ID: issue-4595
ISSUE: https://github.com/FirebirdSQL/firebird/issues/4595
TITLE: Engine crashes in case of re-creation of an erratic package body
2022-01-23 20:41:55 +01:00
DESCRIPTION:
JIRA: CORE-4271
FBTEST: bugs.core_4271
2022-01-23 20:41:55 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-23 20:41:55 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-23 20:41:55 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-23 20:41:55 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set list on;
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
set term ^;
create or alter package pkg_sequence
as
begin
procedure initialize(min_value int, max_value int, step int);
function get_current_value returns int;
function next_value returns int;
function is_end returns boolean;
end
^
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
recreate package body pkg_sequence
as
begin
function get_max returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'MAX_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_max(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'MAX_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_min returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'MIN_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_min(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'MIN_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_step returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'STEP_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_step(avalue int) returns int
as
begin
rdb$set_context('USER_SESSION', 'STEP_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_current_value returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'CURRENT_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_current_value(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'CURRENT_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function next_value returns int as
begin
if (not is_end()) then
set_current_value(get_current_value() + get_step());
return get_current_value();
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function is_end returns boolean as
begin
return get_current_value() > get_max();
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
procedure initialize(min_value int, max_value int, step int)
as
begin
set_min(min_value);
set_max(max_value);
set_step(step);
set_current_value(min_value);
end
end
^
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
execute block returns ( out int) as
begin
execute procedure pkg_sequence.initialize(10, 140, 5);
out = pkg_sequence.get_current_value();
suspend;
while (not pkg_sequence.is_end()) do
begin
out = pkg_sequence.next_value();
suspend;
end
end
^
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
recreate package body pkg_sequence
as
begin
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_max returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'MAX_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_max(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'MAX_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_min returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'MIN_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_min(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'MIN_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_step returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'STEP_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_step(avalue int) returns int as
begin
rdb$set_context('USER_SESSION', 'STEP_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function get_current_value returns int as
begin
return cast(rdb$get_context('USER_SESSION', 'CURRENT_VALUE') as int);
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function set_current_value(avalue int) returns int
as
begin
rdb$set_context('USER_SESSION', 'CURRENT_VALUE', avalue);
return avalue;
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function next_value returns int as
begin
if (not is_end()) then
set_current_value(get_current_value() + get_step());
return get_current_value();
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
function is_end returns boolean as
begin
return get_current_value() > get_max();
end
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
procedure initialize(min_value int, max_value int, step int) as
begin
set_min(min_value);
set_max(max_value);
set_step(step);
set_current_value(min_value);
end
end
^
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
execute block returns (out int) as
begin
execute procedure pkg_sequence.initialize(10, 140, 5);
out = pkg_sequence.get_current_value();
suspend;
2022-01-23 20:41:55 +01:00
2021-04-26 20:07:00 +02:00
while (not pkg_sequence.is_end()) do
begin
out = pkg_sequence.next_value();
suspend;
end
end
2022-01-23 20:41:55 +01:00
^
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-23 20:41:55 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-23 20:41:55 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
OUT 10
OUT 15
OUT 20
OUT 25
OUT 30
OUT 35
OUT 40
OUT 45
OUT 50
OUT 55
OUT 60
OUT 65
OUT 70
OUT 75
OUT 80
OUT 85
OUT 90
OUT 95
OUT 100
OUT 105
OUT 110
OUT 115
OUT 120
OUT 125
OUT 130
OUT 135
OUT 140
OUT 145
OUT 10
OUT 15
OUT 20
OUT 25
OUT 30
OUT 35
OUT 40
OUT 45
OUT 50
OUT 55
OUT 60
OUT 65
OUT 70
OUT 75
OUT 80
OUT 85
OUT 90
OUT 95
OUT 100
OUT 105
OUT 110
OUT 115
OUT 120
OUT 125
OUT 130
OUT 135
OUT 140
OUT 145
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-23 20:41:55 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute(combine_output = True)
2022-01-23 20:41:55 +01:00
assert act.clean_stdout == act.clean_expected_stdout