-
Notifications
You must be signed in to change notification settings - Fork 8
/
p_stack_tests.sql
171 lines (165 loc) · 5.65 KB
/
p_stack_tests.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
create or replace procedure assert_eq( tActual in varchar2, tExpected in varchar2 ) is
tExpectedReplaced varchar2( 4000 ) := replace( tExpected, '<USER>', user );
begin
if tActual = tExpectedReplaced or tActual is null and tExpectedReplaced is null then
return;
end if;
raise_application_error( -20001, 'assertion failed: ' || chr( 10 ) || tActual || chr( 10 ) || tExpectedReplaced );
end;
/
create or replace package APCKG is
procedure PROC;
end;
/
create or replace package body APCKG is
procedure PROC is
procedure "INNER/proc" is
begin
assert_eq( p_stack.whoAmI, '5: <USER>.PACKAGE BODY APCKG.PROCEDURE PROC.PROCEDURE "INNER/proc"' );
assert_eq( p_stack.getSubprogram( p_stack.whoAmI ), 'INNER/proc' );
assert_eq( p_stack.getConcatenatedSubprograms( p_stack.whoAmI ), 'APCKG.PROC."INNER/proc"' );
assert_eq( p_stack.whoCalledMe, '11: <USER>.PACKAGE BODY APCKG.PROCEDURE PROC' );
end;
begin
"INNER/proc";
end;
end;
/
begin
APCKG.PROC;
end;
/
drop package APCKG;
/
declare
procedure inner_proc is
begin
assert_eq( p_stack.whoAmI, '4: <USER>.ANONYMOUS BLOCK.PROCEDURE INNER_PROC' );
end;
begin
inner_proc;
end;
/
declare
procedure outer_proc is
procedure inner_proc is
tCallStack varchar2( 4000 );
tCallLine varchar2( 4000 );
begin
tCallStack := p_stack.getCallStack;
assert_eq( p_stack.getDynamicDepth( tCallStack ), 4 );
tCallLine := p_stack.getCallStackLine( tCallStack, 1 );
assert_eq( p_stack.getLexicalDepth( tCallLine ), 1 );
assert_eq( p_stack.getProgramType( tCallLine ), 'PACKAGE BODY' );
assert_eq( p_stack.getProgram( tCallLine ), 'P_STACK' );
assert_eq( p_stack.getSubprogramType( tCallLine ), 'FUNCTION' );
assert_eq( p_stack.getSubprogram( tCallLine ), 'GETCALLSTACK' );
assert_eq( p_stack.getConcatenatedSubprograms( tCallLine ), 'P_STACK.GETCALLSTACK' );
tCallLine := p_stack.getCallStackLine( tCallStack, 2 );
assert_eq( p_stack.getUnitLine( tCallLine ), 7 );
assert_eq( p_stack.getOwner( tCallLine ), '<USER>' );
assert_eq( p_stack.getLexicalDepth( tCallLine ), 2 );
assert_eq( p_stack.getProgramType( tCallLine ), 'ANONYMOUS BLOCK' );
assert_eq( p_stack.getProgram( tCallLine ), '' );
assert_eq( p_stack.getSubprogramType( tCallLine ), 'PROCEDURE' );
assert_eq( p_stack.getSubprogram( tCallLine ), 'INNER_PROC' );
assert_eq( p_stack.getConcatenatedSubprograms( tCallLine ), 'ANONYMOUS BLOCK.OUTER_PROC.INNER_PROC' );
tCallLine := p_stack.getCallStackLine( tCallStack, 3 );
assert_eq( p_stack.getOwner( tCallLine ), '<USER>' );
assert_eq( p_stack.getLexicalDepth( tCallLine ), 1 );
assert_eq( p_stack.getProgramType( tCallLine ), 'ANONYMOUS BLOCK' );
assert_eq( p_stack.getProgram( tCallLine ), '' );
assert_eq( p_stack.getSubprogramType( tCallLine ), 'PROCEDURE' );
assert_eq( p_stack.getSubprogram( tCallLine ), 'OUTER_PROC' );
assert_eq( p_stack.getConcatenatedSubprograms( tCallLine ), 'ANONYMOUS BLOCK.OUTER_PROC' );
tCallLine := p_stack.getCallStackLine( tCallStack, 4 );
assert_eq( p_stack.getOwner( tCallLine ), '<USER>' );
assert_eq( p_stack.getLexicalDepth( tCallLine ), 0 );
assert_eq( p_stack.getProgramType( tCallLine ), 'ANONYMOUS BLOCK' );
assert_eq( p_stack.getProgram( tCallLine ), '' );
assert_eq( p_stack.getSubprogramType( tCallLine ), 'ANONYMOUS BLOCK' );
assert_eq( p_stack.getSubprogram( tCallLine ), '' );
assert_eq( p_stack.getConcatenatedSubprograms( tCallLine ), 'ANONYMOUS BLOCK' );
tCallLine := p_stack.getCallStackLine( tCallStack, 5 );
assert_eq( p_stack.getUnitLine( tCallLine ), null );
assert_eq( p_stack.getOwner( tCallLine ), null );
assert_eq( p_stack.getLexicalDepth( tCallLine ), 0 );
assert_eq( p_stack.getProgramType( tCallLine ), 'PACKAGE' );
assert_eq( p_stack.getProgram( tCallLine ), null );
assert_eq( p_stack.getSubprogramType( tCallLine ), null );
assert_eq( p_stack.getSubprogram( tCallLine ), null );
assert_eq( p_stack.getConcatenatedSubprograms( tCallLine ), null );
end;
begin
inner_proc;
end;
begin
outer_proc;
end;
/
create or replace package JAVA_PKG is
procedure begin_test;
procedure test_java is
language java name 'TestClass.Method1()';
procedure end_test;
end;
/
create or replace package body JAVA_PKG is
procedure begin_test is
begin
assert_eq( p_stack.whoAmI, '4: <USER>.PACKAGE BODY JAVA_PKG.PROCEDURE BEGIN_TEST' );
end;
procedure test_java_1 is
language java name 'TestClass.Method1()';
procedure test_java_2 is
language java name 'TestClass.Method2(java.lang.String)';
procedure end_test is
begin
assert_eq( p_stack.whoAmI, '12: <USER>.PACKAGE BODY JAVA_PKG.PROCEDURE END_TEST' );
end;
end;
/
begin
JAVA_PKG.begin_test;
JAVA_PKG.end_test;
end;
/
drop package JAVA_PKG;
/
create or replace package EMPTY_DECLARE_PKG is
procedure GOOD;
procedure BAD;
end;
/
create or replace package body EMPTY_DECLARE_PKG is
procedure GOOD is
tCallStack varchar2( 4000 );
begin
declare
t number;
begin
null;
end;
tCallStack := p_stack.getCallStack(2);
assert_eq( p_stack.getConcatenatedSubprograms( tCallStack ), 'EMPTY_DECLARE_PKG.GOOD' );
end;
procedure BAD is
tCallStack varchar2( 4000 );
begin
declare
begin
null;
end;
tCallStack := p_stack.getCallStack(2);
assert_eq( p_stack.getConcatenatedSubprograms( tCallStack ), 'EMPTY_DECLARE_PKG.BAD' );
end;
end;
/
begin
EMPTY_DECLARE_PKG.GOOD;
EMPTY_DECLARE_PKG.BAD;
end;
/
drop package EMPTY_DECLARE_PKG;
/
drop procedure assert_eq;