diff --git a/source/core/types/ut_suite_item.tps b/source/core/types/ut_suite_item.tps index b287d77d8..6b3b9c686 100644 --- a/source/core/types/ut_suite_item.tps +++ b/source/core/types/ut_suite_item.tps @@ -36,7 +36,7 @@ create or replace type ut_suite_item force under ut_event_item ( /** * Full path of the invocation of the item (including the items name itself) */ - path varchar2(4000 byte), + path varchar2(1000 byte), /** * The type of the rollback behavior */ diff --git a/source/core/ut_suite_manager.pkb b/source/core/ut_suite_manager.pkb index d5338a4c9..e2098caf9 100644 --- a/source/core/ut_suite_manager.pkb +++ b/source/core/ut_suite_manager.pkb @@ -16,6 +16,7 @@ create or replace package body ut_suite_manager is limitations under the License. */ + gc_suitpath_error_message constant varchar2(100) := 'Suitepath exceeds 1000 CHAR on: '; type t_path_item is record ( object_name varchar2(250), @@ -477,12 +478,21 @@ create or replace package body ut_suite_manager is ) is l_annotated_objects ut_annotated_objects; l_suite_items ut_suite_items; + + l_bad_suitepath_obj ut_varchar2_list := ut_varchar2_list(); + ex_string_too_small exception; + pragma exception_init (ex_string_too_small,-06502); begin loop fetch a_annotated_objects bulk collect into l_annotated_objects limit 10; for i in 1 .. l_annotated_objects.count loop - ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items ); + begin + ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items ); + exception + when ex_string_too_small then + ut_utils.append_to_list(l_bad_suitepath_obj,a_owner_name||'.'||l_annotated_objects( i ).object_name); + end; ut_suite_cache_manager.save_object_cache( a_owner_name, l_annotated_objects( i ).object_name, @@ -493,7 +503,14 @@ create or replace package body ut_suite_manager is exit when a_annotated_objects%notfound; end loop; close a_annotated_objects; - + + --Check for any invalid suitepath objects + if l_bad_suitepath_obj.count > 0 then + raise_application_error( + ut_utils.gc_value_too_large, + ut_utils.to_string(gc_suitpath_error_message||ut_utils.table_to_clob(l_bad_suitepath_obj,',')) + ); + end if; end; procedure refresh_cache( diff --git a/source/core/ut_utils.pkb b/source/core/ut_utils.pkb index 3d4836ce0..b29e7fa60 100644 --- a/source/core/ut_utils.pkb +++ b/source/core/ut_utils.pkb @@ -77,48 +77,66 @@ create or replace package body ut_utils is $end end; - function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2 is - l_len integer := coalesce(length(a_value),0); - l_result varchar2(32767); - begin - if l_len = 0 then + function to_string( + a_value varchar2, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2 is + l_result varchar2(32767); + c_length constant integer := coalesce( length( a_value ), 0 ); + c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 ); + c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len; + begin + if c_length = 0 then l_result := gc_null_string; - elsif l_len <= gc_max_input_string_length then - l_result := surround_with(a_value, a_qoute_char); + elsif c_length <= c_max_input_string_length then + l_result := surround_with(a_value, a_quote_char); else - l_result := surround_with(substr(a_value,1,gc_overflow_substr_len),a_qoute_char) || gc_more_data_string; + l_result := surround_with(substr(a_value, 1, c_overflow_substr_len ), a_quote_char) || gc_more_data_string; end if ; return l_result; end; - function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2 is - l_len integer := coalesce(dbms_lob.getlength(a_value), 0); - l_result varchar2(32767); + function to_string( + a_value clob, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2 is + l_result varchar2(32767); + c_length constant integer := coalesce(dbms_lob.getlength(a_value), 0); + c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 ); + c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len; begin if a_value is null then l_result := gc_null_string; - elsif l_len = 0 then + elsif c_length = 0 then l_result := gc_empty_string; - elsif l_len <= gc_max_input_string_length then - l_result := surround_with(a_value,a_qoute_char); + elsif c_length <= c_max_input_string_length then + l_result := surround_with(a_value,a_quote_char); else - l_result := surround_with(dbms_lob.substr(a_value, gc_overflow_substr_len),a_qoute_char) || gc_more_data_string; + l_result := surround_with(dbms_lob.substr(a_value, c_overflow_substr_len), a_quote_char) || gc_more_data_string; end if; return l_result; end; - function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2 is - l_len integer := coalesce(dbms_lob.getlength(a_value), 0); - l_result varchar2(32767); + function to_string( + a_value blob, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2 is + l_result varchar2(32767); + c_length constant integer := coalesce(dbms_lob.getlength(a_value), 0); + c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 ); + c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len; begin if a_value is null then l_result := gc_null_string; - elsif l_len = 0 then + elsif c_length = 0 then l_result := gc_empty_string; - elsif l_len <= gc_max_input_string_length then - l_result := surround_with(rawtohex(a_value),a_qoute_char); + elsif c_length <= c_max_input_string_length then + l_result := surround_with(rawtohex(a_value),a_quote_char); else - l_result := to_string( rawtohex(dbms_lob.substr(a_value, gc_overflow_substr_len)) ); + l_result := to_string( rawtohex(dbms_lob.substr(a_value, c_overflow_substr_len)) ); end if ; return l_result; end; diff --git a/source/core/ut_utils.pks b/source/core/ut_utils.pks index fb7e26f08..fdf92765b 100644 --- a/source/core/ut_utils.pks +++ b/source/core/ut_utils.pks @@ -102,14 +102,17 @@ create or replace package ut_utils authid definer is pragma exception_init (ex_failure_for_all, -24381); ex_dml_for_all exception; - gc_dml_for_all constant pls_integer := -20215; - pragma exception_init (ex_dml_for_all, -20215); + gc_dml_for_all constant pls_integer := -20216; + pragma exception_init (ex_dml_for_all, -20216); + + ex_value_too_large exception; + gc_value_too_large constant pls_integer := -20217; + pragma exception_init (ex_value_too_large, -20217); gc_max_storage_varchar2_len constant integer := 4000; gc_max_output_string_length constant integer := 4000; - gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string gc_more_data_string constant varchar2(5) := '[...]'; - gc_overflow_substr_len constant integer := gc_max_input_string_length - length(gc_more_data_string); + gc_more_data_string_len constant integer := length( gc_more_data_string ); gc_number_format constant varchar2(100) := 'TM9'; gc_date_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ss'; gc_timestamp_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff'; @@ -151,11 +154,23 @@ create or replace package ut_utils authid definer is procedure debug_log(a_message clob); - function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2; - - function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2; - - function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2; + function to_string( + a_value varchar2, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2; + + function to_string( + a_value clob, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2; + + function to_string( + a_value blob, + a_quote_char varchar2 := '''', + a_max_output_len in number := gc_max_output_string_length + ) return varchar2; function to_string(a_value boolean) return varchar2; diff --git a/test/core/test_suite_manager.pkb b/test/core/test_suite_manager.pkb index 59ed002d3..bd6c97779 100644 --- a/test/core/test_suite_manager.pkb +++ b/test/core/test_suite_manager.pkb @@ -3,6 +3,35 @@ create or replace package body test_suite_manager is ex_obj_doesnt_exist exception; pragma exception_init(ex_obj_doesnt_exist, -04043); + procedure create_dummy_long_test_package is + pragma autonomous_transaction; + begin + execute immediate q'[create or replace package ut3.dummy_long_test_package as + + --%suitepath(verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtext) + --%suite(dummy_test_suite) + + --%test(dummy_test) + procedure some_dummy_test_procedure; + end;]'; + + execute immediate q'[create or replace package ut3.dummy_long_test_package1 as + + --%suitepath(verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtext) + --%suite(dummy_test_suite1) + + --%test(dummy_test) + procedure some_dummy_test_procedure; + end;]'; + end; + + procedure drop_dummy_long_test_package is + pragma autonomous_transaction; + begin + execute immediate q'[drop package ut3.dummy_long_test_package]'; + execute immediate q'[drop package ut3.dummy_long_test_package1]'; + end; + procedure compile_dummy_packages is pragma autonomous_transaction; begin @@ -1451,5 +1480,18 @@ end;]'; execute immediate q'[drop package ut3.some_test_package]'; end; + procedure add_new_long_test_package is + l_actual ut3.ut_object_names; + l_expected_message varchar2(500); + begin + l_expected_message := q'[ORA-20217: 'Suitepath exceeds 1000 CHAR on: UT3.DUMMY_LONG_TEST_PACKAGE,UT3.DUMMY_LONG_TEST_PACKAGE1'%]'; + l_actual := ut3.ut_suite_manager.get_schema_ut_packages(ut3.ut_varchar2_rows('UT3')); + ut.fail('Expected exception for suitpaths over 1k for two packages'); + exception + when others then + ut.expect(dbms_utility.format_error_stack()).to_be_like(l_expected_message); + ut.expect(SQLCODE).to_equal(ut3.ut_utils.gc_value_too_large); + end; + end test_suite_manager; / diff --git a/test/core/test_suite_manager.pks b/test/core/test_suite_manager.pks index d200fcd2f..aad29fad0 100644 --- a/test/core/test_suite_manager.pks +++ b/test/core/test_suite_manager.pks @@ -3,6 +3,10 @@ create or replace package test_suite_manager is --%suite(suite_manager) --%suitepath(utplsql.core) + procedure create_dummy_long_test_package; + + procedure drop_dummy_long_test_package; + --%beforeall procedure compile_dummy_packages; --%afterall @@ -162,5 +166,10 @@ create or replace package test_suite_manager is --%endcontext + --%test(Adds suitepath to cache over 1k characters long) + --%beforetest(create_dummy_long_test_package) + --%aftertest(drop_dummy_long_test_package) + procedure add_new_long_test_package; + end test_suite_manager; /