|
| 1 | +create or replace package body test_coverage is |
| 2 | + |
| 3 | + g_run_id integer; |
| 4 | + |
| 5 | + function get_mock_run_id return integer is |
| 6 | + v_result integer; |
| 7 | + begin |
| 8 | + select min(runid) - 1 into v_result |
| 9 | + from ut3.plsql_profiler_runs; |
| 10 | + return v_result; |
| 11 | + end; |
| 12 | + |
| 13 | + procedure create_dummy_coverage_package is |
| 14 | + begin |
| 15 | + execute immediate q'[create or replace package DUMMY_COVERAGE is |
| 16 | + procedure do_stuff; |
| 17 | + end;]'; |
| 18 | + execute immediate q'[create or replace package body DUMMY_COVERAGE is |
| 19 | + procedure do_stuff is |
| 20 | + begin |
| 21 | + if 1 = 2 then |
| 22 | + dbms_output.put_line('should not get here'); |
| 23 | + else |
| 24 | + dbms_output.put_line('should get here'); |
| 25 | + end if; |
| 26 | + end; |
| 27 | + end;]'; |
| 28 | + end; |
| 29 | + |
| 30 | + procedure create_dummy_coverage_test is |
| 31 | + begin |
| 32 | + execute immediate q'[create or replace package TEST_DUMMY_COVERAGE is |
| 33 | + --%suite(dummy coverage test) |
| 34 | + |
| 35 | + --%test |
| 36 | + procedure test_do_stuff; |
| 37 | + end;]'; |
| 38 | + execute immediate q'[create or replace package body TEST_DUMMY_COVERAGE is |
| 39 | + procedure test_do_stuff is |
| 40 | + begin |
| 41 | + dummy_coverage.do_stuff; |
| 42 | + end; |
| 43 | + end;]'; |
| 44 | + end; |
| 45 | + |
| 46 | + procedure mock_coverage_data(a_run_id integer) is |
| 47 | + c_unit_id constant integer := 1; |
| 48 | + begin |
| 49 | + insert into ut3.plsql_profiler_runs ( runid, run_owner, run_date, run_comment) |
| 50 | + values(a_run_id, user, sysdate, 'unit testing utPLSQL'); |
| 51 | + |
| 52 | + insert into ut3.plsql_profiler_units ( runid, unit_number, unit_type, unit_owner, unit_name) |
| 53 | + values(a_run_id, c_unit_id, 'PACKAGE BODY', 'UT3_TESTER', 'DUMMY_COVERAGE'); |
| 54 | + |
| 55 | + insert into ut3.plsql_profiler_data ( runid, unit_number, line#, total_occur, total_time) |
| 56 | + select a_run_id, c_unit_id, 4, 1, 1 from dual union all |
| 57 | + select a_run_id, c_unit_id, 5, 0, 0 from dual union all |
| 58 | + select a_run_id, c_unit_id, 7, 1, 1 from dual; |
| 59 | + end; |
| 60 | + |
| 61 | + procedure setup_dummy_coverage is |
| 62 | + pragma autonomous_transaction; |
| 63 | + begin |
| 64 | + create_dummy_coverage_package(); |
| 65 | + create_dummy_coverage_test(); |
| 66 | + g_run_id := get_mock_run_id(); |
| 67 | + ut3.ut_coverage_helper.mock_coverage_id(g_run_id); |
| 68 | + mock_coverage_data(g_run_id); |
| 69 | + commit; |
| 70 | + end; |
| 71 | + |
| 72 | + procedure cleanup_dummy_coverage is |
| 73 | + pragma autonomous_transaction; |
| 74 | + begin |
| 75 | + execute immediate q'[drop package test_dummy_coverage]'; |
| 76 | + execute immediate q'[drop package dummy_coverage]'; |
| 77 | + delete from ut3.plsql_profiler_data where runid = g_run_id; |
| 78 | + delete from ut3.plsql_profiler_units where runid = g_run_id; |
| 79 | + delete from ut3.plsql_profiler_runs where runid = g_run_id; |
| 80 | + commit; |
| 81 | + end; |
| 82 | + |
| 83 | +end; |
| 84 | +/ |
0 commit comments