|
| 1 | +create or replace package body coverage_helper is |
| 2 | + |
| 3 | + function get_mock_run_id return integer is |
| 4 | + v_result integer; |
| 5 | + begin |
| 6 | + select nvl(min(runid),0) - 1 into v_result |
| 7 | + from ut3.plsql_profiler_runs; |
| 8 | + return v_result; |
| 9 | + end; |
| 10 | + |
| 11 | + function get_mock_block_run_id return integer is |
| 12 | + v_result integer; |
| 13 | + begin |
| 14 | + select nvl(min(run_id),0) - 1 into v_result |
| 15 | + from dbmspcc_runs; |
| 16 | + return v_result; |
| 17 | + end; |
| 18 | + |
| 19 | + procedure mock_coverage_data(a_run_id integer,a_user in varchar2) is |
| 20 | + c_unit_id constant integer := 1; |
| 21 | + begin |
| 22 | + insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment) |
| 23 | + values(a_run_id, a_user, sysdate, 'unit testing utPLSQL'); |
| 24 | + |
| 25 | + insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name) |
| 26 | + values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE'); |
| 27 | + |
| 28 | + insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time) |
| 29 | + select a_run_id, c_unit_id, 4, 1, 1 from dual union all |
| 30 | + select a_run_id, c_unit_id, 5, 0, 0 from dual union all |
| 31 | + select a_run_id, c_unit_id, 7, 1, 1 from dual; |
| 32 | + end; |
| 33 | + |
| 34 | + procedure cleanup_dummy_coverage(a_run_id in integer) is |
| 35 | + pragma autonomous_transaction; |
| 36 | + begin |
| 37 | + delete from ut3.plsql_profiler_data where runid = a_run_id; |
| 38 | + delete from ut3.plsql_profiler_units where runid = a_run_id; |
| 39 | + delete from ut3.plsql_profiler_runs where runid = a_run_id; |
| 40 | + commit; |
| 41 | + end; |
| 42 | + |
| 43 | + procedure create_dummy_coverage_package is |
| 44 | + pragma autonomous_transaction; |
| 45 | + begin |
| 46 | + execute immediate q'[create or replace package UT3.DUMMY_COVERAGE is |
| 47 | + procedure do_stuff; |
| 48 | + |
| 49 | + procedure grant_myself; |
| 50 | + end;]'; |
| 51 | + execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE is |
| 52 | + procedure do_stuff is |
| 53 | + begin |
| 54 | + if 1 = 2 then |
| 55 | + dbms_output.put_line('should not get here'); |
| 56 | + else |
| 57 | + dbms_output.put_line('should get here'); |
| 58 | + end if; |
| 59 | + end; |
| 60 | + |
| 61 | + procedure grant_myself is |
| 62 | + begin |
| 63 | + execute immediate 'grant debug,execute on UT3.DUMMY_COVERAGE to ut3$user#'; |
| 64 | + end; |
| 65 | + end;]'; |
| 66 | + |
| 67 | + end; |
| 68 | + |
| 69 | + procedure create_dummy_coverage_test is |
| 70 | + pragma autonomous_transaction; |
| 71 | + begin |
| 72 | + execute immediate q'[create or replace package UT3.TEST_DUMMY_COVERAGE is |
| 73 | + --%suite(dummy coverage test) |
| 74 | + --%suitepath(coverage_testing) |
| 75 | + |
| 76 | + --%test |
| 77 | + procedure test_do_stuff; |
| 78 | + |
| 79 | + procedure grant_myself; |
| 80 | + end;]'; |
| 81 | + execute immediate q'[create or replace package body UT3.TEST_DUMMY_COVERAGE is |
| 82 | + procedure test_do_stuff is |
| 83 | + begin |
| 84 | + dummy_coverage.do_stuff; |
| 85 | + end; |
| 86 | + |
| 87 | + procedure grant_myself is |
| 88 | + begin |
| 89 | + execute immediate 'grant debug,execute on UT3.TEST_DUMMY_COVERAGE to ut3$user#'; |
| 90 | + end; |
| 91 | + end;]'; |
| 92 | + |
| 93 | + end; |
| 94 | + |
| 95 | + procedure grant_exec_on_cov is |
| 96 | + pragma autonomous_transaction; |
| 97 | + begin |
| 98 | + execute immediate 'begin UT3.DUMMY_COVERAGE.grant_myself(); end;'; |
| 99 | + execute immediate 'begin UT3.TEST_DUMMY_COVERAGE.grant_myself(); end;'; |
| 100 | + end; |
| 101 | + |
| 102 | + procedure drop_dummy_coverage_pkg is |
| 103 | + pragma autonomous_transaction; |
| 104 | + begin |
| 105 | + begin execute immediate q'[drop package ut3.test_dummy_coverage]'; exception when others then null; end; |
| 106 | + begin execute immediate q'[drop package ut3.dummy_coverage]'; exception when others then null; end; |
| 107 | + end; |
| 108 | + |
| 109 | + |
| 110 | + --12.2 Setup |
| 111 | + procedure create_dummy_12_2_cov_pck is |
| 112 | + pragma autonomous_transaction; |
| 113 | + begin |
| 114 | + execute immediate q'[create or replace package UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG is |
| 115 | + procedure do_stuff(i_input in number); |
| 116 | + |
| 117 | + procedure grant_myself; |
| 118 | + end;]'; |
| 119 | + execute immediate q'[create or replace package body UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG is |
| 120 | + procedure do_stuff(i_input in number) is |
| 121 | + begin |
| 122 | + if i_input = 2 then |
| 123 | + dbms_output.put_line('should not get here'); |
| 124 | + else |
| 125 | + dbms_output.put_line('should get here'); |
| 126 | + end if; |
| 127 | + end; |
| 128 | + |
| 129 | + procedure grant_myself is |
| 130 | + begin |
| 131 | + execute immediate 'grant debug,execute on UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG to ut3$user#'; |
| 132 | + end; |
| 133 | + |
| 134 | + end;]'; |
| 135 | + end; |
| 136 | + |
| 137 | + procedure create_dummy_12_2_cov_test is |
| 138 | + pragma autonomous_transaction; |
| 139 | + begin |
| 140 | + execute immediate q'[create or replace package UT3.TEST_BLOCK_DUMMY_COVERAGE is |
| 141 | + --%suite(dummy coverage test) |
| 142 | + --%suitepath(coverage_testing) |
| 143 | + |
| 144 | + --%test |
| 145 | + procedure test_do_stuff; |
| 146 | + |
| 147 | + procedure grant_myself; |
| 148 | + |
| 149 | + end;]'; |
| 150 | + execute immediate q'[create or replace package body UT3.TEST_BLOCK_DUMMY_COVERAGE is |
| 151 | + procedure test_do_stuff is |
| 152 | + begin |
| 153 | + dummy_coverage_package_with_an_amazingly_long_name_that_you_would_not_think_of_in_real_life_project_because_its_simply_too_long.do_stuff(1); |
| 154 | + ut.expect(1).to_equal(1); |
| 155 | + end; |
| 156 | + |
| 157 | + procedure grant_myself is |
| 158 | + begin |
| 159 | + execute immediate 'grant debug,execute on UT3.TEST_BLOCK_DUMMY_COVERAGE to ut3$user#'; |
| 160 | + end; |
| 161 | + end;]'; |
| 162 | + end; |
| 163 | + |
| 164 | + procedure mock_block_coverage_data(a_run_id integer,a_user in varchar2) is |
| 165 | + c_unit_id constant integer := 1; |
| 166 | + begin |
| 167 | + insert into dbmspcc_runs ( run_id, run_owner, run_timestamp, run_comment) |
| 168 | + values(a_run_id, a_user, sysdate, 'unit testing utPLSQL'); |
| 169 | + |
| 170 | + insert into dbmspcc_units ( run_id, object_id, type, owner, name,last_ddl_time) |
| 171 | + values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG',sysdate); |
| 172 | + |
| 173 | + insert into dbmspcc_blocks ( run_id, object_id, line,block,col,covered,not_feasible) |
| 174 | + select a_run_id, c_unit_id,4,1,1,1,0 from dual union all |
| 175 | + select a_run_id, c_unit_id,4,2,2,0,0 from dual union all |
| 176 | + select a_run_id, c_unit_id,5,3,0,1,0 from dual union all |
| 177 | + select a_run_id, c_unit_id,7,4,1,1,0 from dual; |
| 178 | + end; |
| 179 | + |
| 180 | + procedure mock_profiler_coverage_data(a_run_id integer,a_user in varchar2) is |
| 181 | + c_unit_id constant integer := 1; |
| 182 | + begin |
| 183 | + insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment) |
| 184 | + values(a_run_id, a_user, sysdate, 'unit testing utPLSQL'); |
| 185 | + |
| 186 | + insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name) |
| 187 | + values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3', 'DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG'); |
| 188 | + |
| 189 | + insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time) |
| 190 | + select a_run_id, c_unit_id, 4, 1, 1 from dual union all |
| 191 | + select a_run_id, c_unit_id, 5, 0, 0 from dual union all |
| 192 | + select a_run_id, c_unit_id, 6, 1, 0 from dual union all |
| 193 | + select a_run_id, c_unit_id, 7, 1, 1 from dual; |
| 194 | + end; |
| 195 | + |
| 196 | + procedure cleanup_dummy_coverage(a_block_id in integer, a_prof_id in integer) is |
| 197 | + pragma autonomous_transaction; |
| 198 | + begin |
| 199 | + begin execute immediate q'[drop package ut3.test_block_dummy_coverage]'; exception when others then null; end; |
| 200 | + begin execute immediate q'[drop package ut3.dummy_coverage_package_with_an_amazingly_long_name_that_you_would_not_think_of_in_real_life_project_because_its_simply_too_long]'; exception when others then null; end; |
| 201 | + delete from dbmspcc_blocks where run_id = a_block_id; |
| 202 | + delete from dbmspcc_units where run_id = a_block_id; |
| 203 | + delete from dbmspcc_runs where run_id = a_block_id; |
| 204 | + cleanup_dummy_coverage(a_prof_id); |
| 205 | + commit; |
| 206 | + end; |
| 207 | + |
| 208 | + procedure grant_exec_on_12_2_cov is |
| 209 | + pragma autonomous_transaction; |
| 210 | + begin |
| 211 | + execute immediate 'begin UT3.DUMMY_COVERAGE_PACKAGE_WITH_AN_AMAZINGLY_LONG_NAME_THAT_YOU_WOULD_NOT_THINK_OF_IN_REAL_LIFE_PROJECT_BECAUSE_ITS_SIMPLY_TOO_LONG.grant_myself(); end;'; |
| 212 | + execute immediate 'begin UT3.TEST_BLOCK_DUMMY_COVERAGE.grant_myself(); end;'; |
| 213 | + end; |
| 214 | +end; |
| 215 | +/ |
0 commit comments