|
| 1 | +create or replace package body ut_block_helper is |
| 2 | + /* |
| 3 | + utPLSQL - Version 3 |
| 4 | + Copyright 2016 - 2017 utPLSQL Project |
| 5 | + |
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"): |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | + |
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + |
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | + type t_proftab_row is record ( |
| 20 | + line binary_integer, |
| 21 | + calls number(38,0) |
| 22 | + ); |
| 23 | + |
| 24 | + type t_proftab_rows is table of t_proftab_row; |
| 25 | + |
| 26 | + type t_block_row is record( |
| 27 | + line binary_integer |
| 28 | + ,blocks binary_integer |
| 29 | + ,covered_blocks binary_integer); |
| 30 | + |
| 31 | + type t_block_rows is table of t_block_row; |
| 32 | + |
| 33 | + procedure coverage_start(a_run_comment varchar2,a_coverage_id out integer) is |
| 34 | + begin |
| 35 | + a_coverage_id := dbms_plsql_code_coverage.start_coverage(run_comment => a_run_comment); |
| 36 | + end; |
| 37 | + |
| 38 | + procedure coverage_stop is |
| 39 | + begin |
| 40 | + dbms_plsql_code_coverage.stop_coverage(); |
| 41 | + end; |
| 42 | + |
| 43 | + function block_results(a_object_owner varchar2, a_object_name varchar2) return t_block_rows is |
| 44 | + c_raw_coverage sys_refcursor; |
| 45 | + l_coverage_rows t_block_rows; |
| 46 | + l_coverage_id integer := ut_coverage_helper.get_coverage_id; |
| 47 | + begin |
| 48 | + open c_raw_coverage for q'[select ccb.line |
| 49 | + ,count(ccb.block) totalblocks |
| 50 | + ,sum(ccb.covered) |
| 51 | + from dbmspcc_units ccu |
| 52 | + left outer join dbmspcc_blocks ccb |
| 53 | + on ccu.run_id = ccb.run_id |
| 54 | + and ccu.object_id = ccb.object_id |
| 55 | + where ccu.run_id = :a_coverage_id |
| 56 | + and ccu.owner = :a_object_owner |
| 57 | + and ccu.name = :a_object_name |
| 58 | + group by ccb.line |
| 59 | + order by 1]' using l_coverage_id,a_object_owner,a_object_name; |
| 60 | + |
| 61 | + fetch c_raw_coverage bulk collect into l_coverage_rows; |
| 62 | + close c_raw_coverage; |
| 63 | + |
| 64 | + return l_coverage_rows; |
| 65 | + end; |
| 66 | + |
| 67 | + function get_raw_coverage_data_block(a_object_owner varchar2, a_object_name varchar2) return ut_coverage_helper.t_unit_line_calls is |
| 68 | + l_tmp_data t_block_rows; |
| 69 | + l_results ut_coverage_helper.t_unit_line_calls; |
| 70 | + |
| 71 | + begin |
| 72 | + l_tmp_data := block_results(a_object_owner => a_object_owner, a_object_name => a_object_name); |
| 73 | + for i in 1 .. l_tmp_data.count loop |
| 74 | + l_results(l_tmp_data(i).line).blocks := l_tmp_data(i).blocks; |
| 75 | + l_results(l_tmp_data(i).line).covered_blocks := l_tmp_data(i).covered_blocks; |
| 76 | + l_results(l_tmp_data(i).line).partcovered := case |
| 77 | + when (l_tmp_data(i).covered_blocks > 0) and |
| 78 | + (l_tmp_data(i).blocks > l_tmp_data(i).covered_blocks) then |
| 79 | + 1 |
| 80 | + else |
| 81 | + 0 |
| 82 | + end; |
| 83 | + end loop; |
| 84 | + return l_results; |
| 85 | + end; |
| 86 | + |
| 87 | + |
| 88 | +end; |
| 89 | +/ |
0 commit comments