Skip to content

Commit 1c794b7

Browse files
committed
Add Demo SQL and Type-Test
1 parent 6dceff6 commit 1c794b7

File tree

12 files changed

+372
-14
lines changed

12 files changed

+372
-14
lines changed

docs/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ Core Core Documentation
88
Demo Demonstration Documentation
99
README.md README Markdown file for "github.io"
1010
_config.yml YAML Configuration File for this Website
11+
12+
13+
Local Documentation URL
14+
-----------------------
15+
file://README.htm
16+
(Double-click on the README.htm file)

docs/demo/Package-Test.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p><a href="README.htm">Demos and Examples</a></p>
22
<h1 id="test-a-plsql-package">Test a PL/SQL Package</h1>
33
<hr />
4-
<p>A majority of wtPLSQL testing is the test runner packages. In this example, a test runner package will be created to test the DBMS_OUTPUT package. For brevity, only PUT_LINE and GET_LINE will be tested.</p>
4+
<p>A majority of wtPLSQL testing is done with the test runner packages. In this example, a test runner package will be created to test the DBMS_OUTPUT package. For brevity, only PUT_LINE and GET_LINE will be tested.</p>
55
<h2 id="test-runner-package-specification">Test Runner Package Specification</h2>
66
<p>The specification for a test runner package is brutally simple. It only needs one procedure.</p>
77
<p>Run this:</p>

docs/demo/Test-Runner.htm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ <h1 id="create-a-simple-test-runner-package">Create a Simple Test Runner Package
88
procedure wtplsql_run;
99
end simple_test_runner;
1010
/
11-
12-
create or replace package body simple_test_runner
11+
</code></pre>
12+
<p>Then, run this:</p>
13+
<pre><code>create or replace package body simple_test_runner
1314
as
1415
procedure wtplsql_run is begin
1516
wt_assert.eq(msg_in =&gt; &#39;Ad-Hoc Test&#39;
@@ -32,7 +33,7 @@ <h2 id="execute-and-display">Execute and Display</h2>
3233
<pre><code>set serveroutput on size unlimited format word_wrapped
3334

3435
begin
35-
wt_text_report.dbms_out;
36+
wt_text_report.dbms_out(USER,&#39;SIMPLE_TEST_RUNNER&#39;);
3637
end;
3738
/
3839
</code></pre>
@@ -46,7 +47,7 @@ <h2 id="execute-and-display">Execute and Display</h2>
4647
Maximum Interval msec: 56 Test Yield: 100.00%
4748
Total Run Time (sec): 0.2
4849
</code></pre>
49-
<p>This is latest test result summary from all test runner packages for the login user. The interval time shown here is the elapsed time from starting the test runner package until the first assertion was executed. The total run time is the elapsed time from start to finish for the test runner package. The report confirms that one assertion was executed for SIMPLE_TEST_RUNNER and it passed. All tests passed, so the test yield is 100%.</p>
50+
<p>This is the test result summary from the last execution of the SIMPLE_TEST_RUNNER package. The interval time shown here is the elapsed time from starting the test runner package until the first assertion was executed. The total run time is the elapsed time from start to finish for the test runner package. The report confirms that one assertion was executed for SIMPLE_TEST_RUNNER and it passed. All tests passed, so the test yield is 100%.</p>
5051
<h2 id="wt_text_report-display-levels">WT_TEXT_REPORT Display Levels</h2>
5152
<p>This example shows all result details for the SIMPLE_TEST_RUNNER only.</p>
5253
<p>Run this:</p>
@@ -72,8 +73,8 @@ <h2 id="wt_text_report-display-levels">WT_TEXT_REPORT Display Levels</h2>
7273
-----------------------------------------------------------
7374
PASS 56ms Ad-Hoc Test. EQ - Expected &quot;1&quot; and got &quot;1&quot;
7475
</code></pre>
75-
<p>This shows the latest test result summary with test results details. A detail level of 30 shows summary and detailed test results for a test runner package. In this case, the summary is the same and the detailed results of the EQ assertion are shown. These detail levels are explained in the <a href="../Reference.htm">Reference Page</a>.</p>
76-
<p>The detailed results shown are the same as the ad-hoc result, with a &quot;56ms&quot; added. The detailed results from the test runner package includes the elapsed time between assertions, or elapsed time from test runner package startup to the first assertion.</p>
76+
<p>This shows the latest test result summary with test results details. A detail level of 30 shows summary and detailed test results for a test runner package. In this case, the summary and the detailed results of the EQ assertion are shown. These detail levels are explained in the <a href="../Reference.htm#wt_text_report-detail-levels">Reference Page</a>.</p>
77+
<p>The detailed results shown are the same as the ad-hoc result, with a &quot;56ms&quot; added. The 56 in the detailed results shows the elapsed time between assertions, or elapsed time from test runner package startup to the first assertion.</p>
7778
<h2 id="test-cases">Test Cases</h2>
7879
<p>For wtPLSQL, a test case is a collection of assertions. Assertion results can be grouped by test case. There can be zero or more test cases in a test runner package.</p>
7980
<p>Run this:</p>
@@ -141,7 +142,7 @@ <h2 id="dbout-annotation">DBOUT Annotation</h2>
141142
end simple_test_runner;
142143
/
143144
</code></pre>
144-
<p>With the addition of the DBOUT annotation, the profiling information is available for the SIMPLE_TEST_RUNNER package.</p>
145+
<p>With the addition of the DBOUT annotation, the profiling information is available for the SIMPLE_TEST_RUNNER package. The DBOUT takes the form of &quot;owner.object_name:object_type&quot;. &quot;owner&quot; will default to &quot;USER&quot;. &quot;object_name&quot; is required. &quot;object_type&quot; is required if more than one object has that name. Package bodies will always require the &quot;:PACKAGE BODY&quot; because the package specification is always another database object with the same name.</p>
145146
<p>Run this:</p>
146147
<pre><code>begin
147148
wtplsql.test_run(&#39;SIMPLE_TEST_RUNNER&#39;);

docs/demo/Test-Runner.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end simple_test_runner;
2929
/
3030
```
3131

32-
SIMPLE_TEST_RUNNER is a minimal test runner. It is a package that contains the (public) WTPLSQL_RUN procedure and 1 assertion. It does the same assertion as the ad-hoc assertion in the [Simple Test](Simple-Test.md) page.
32+
SIMPLE_TEST_RUNNER is a minimal test runner. It is a package that contains the (public) WTPLSQL_RUN procedure and 1 assertion. It does the same assertion as the ad-hoc assertion in the [Demos and Examples](README.md) page.
3333

3434
## Execute and Display
3535

@@ -103,9 +103,9 @@ And get this:
103103
PASS 56ms Ad-Hoc Test. EQ - Expected "1" and got "1"
104104
```
105105

106-
This shows the latest test result summary with test results details. A detail level of 30 shows summary and detailed test results for a test runner package. In this case, the summary is the same and the detailed results of the EQ assertion are shown. These detail levels are explained in the [Reference Page](../Reference.md).
106+
This shows the latest test result summary with test results details. A detail level of 30 shows summary and detailed test results for a test runner package. In this case, the summary and the detailed results of the EQ assertion are shown. These detail levels are explained in the [Reference Page](../Reference.md#wt_text_report-detail-levels).
107107

108-
The detailed results shown are the same as the ad-hoc result, with a "56ms" added. The detailed results from the test runner package includes the elapsed time between assertions, or elapsed time from test runner package startup to the first assertion.
108+
The detailed results shown are the same as the ad-hoc result, with a "56ms" added. The 56 in the detailed results shows the elapsed time between assertions, or elapsed time from test runner package startup to the first assertion.
109109

110110
## Test Cases
111111

@@ -192,7 +192,7 @@ end simple_test_runner;
192192
/
193193
```
194194

195-
With the addition of the DBOUT annotation, the profiling information is available for the SIMPLE_TEST_RUNNER package.
195+
With the addition of the DBOUT annotation, the profiling information is available for the SIMPLE_TEST_RUNNER package. The DBOUT takes the form of "owner.object_name:object_type". "owner" will default to "USER". "object_name" is required. "object_type" is required if more than one object has that name. Package bodies will always require the ":PACKAGE BODY" because the package specification is always another database object with the same name.
196196

197197
Run this:
198198

docs/demo/Type-Test.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[Demos and Examples](README.md)
2+
3+
# Test a PL/SQL Type
4+
5+
---
6+
7+
## PL/SQL Types
8+
* Attributes
9+
* VArray
10+
* Nested Table
11+
* Object
12+
13+
## Test a PL/SQL Object Type
14+
15+
Create a simple object type to test.
16+
17+
Run this:
18+
19+
```
20+
create or replace type simple_test_obj_type authid definer
21+
as object
22+
(l_minimum number
23+
,l_observations number
24+
,CONSTRUCTOR FUNCTION simple_test_obj_type
25+
(SELF IN OUT NOCOPY simple_test_obj_type)
26+
return self as result
27+
,member procedure add_observation
28+
(SELF IN OUT NOCOPY simple_test_obj_type
29+
,in_observation number)
30+
);
31+
/
32+
```
33+
34+
And run this:
35+
36+
```
37+
create or replace type body simple_test_obj_type is
38+
CONSTRUCTOR FUNCTION simple_test_obj_type
39+
(SELF IN OUT NOCOPY simple_test_obj_type)
40+
return self as result
41+
is
42+
begin
43+
l_minimum := null;
44+
l_observations := 0;
45+
return;
46+
end simple_test_obj_type;
47+
member procedure add_observation
48+
(SELF IN OUT NOCOPY simple_test_obj_type
49+
,in_observation number)
50+
is
51+
begin
52+
If l_minimum is null then l_minimum := in_observation;
53+
else l_minimum := least(l_minimum, in_observation);
54+
end if;
55+
l_observations := l_observations + 1;
56+
end add_observation;
57+
end;
58+
```
59+
60+
## Testing Private Object Methods and Self-Testing
61+
62+
An Oracle object type can have private methods. These methods are not available outside the object. They are inherited from a super-type.
63+
64+
[Private Object Methods on StackOverFlow](https://stackoverflow.com/questions/1580205/pl-sql-private-object-method)
65+
66+
Testing these private methods requires a mock object type of the super-type that exposes the private methods for testing.
67+
68+
Self-testing object types has the drawback of requires a CONSTRUCTOR FUNCTION with no parameters. This limits testing of the object to that one constructor.
69+
70+
---
71+
[Demos and Examples](README.md)

docs/demo/md-to-htm.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ for %%f in (*.md) do (
55
REM echo %%~nf.htm
66
pandoc -f gfm -t html --lua-filter=md-to-htm.lua -o %%~nf.htm %%~nf.md
77
)
8+
9+
pause

docs/demo/md-to-htm.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# links-to-html.lua
1+
# md-to-htm.lua
2+
-- Adapted from answer by JW https://stackoverflow.com/users/4321/jw
3+
-- at https://stackoverflow.com/questions/40993488
24
function Link(el)
35
el.target = string.gsub(el.target, "%.md", ".htm")
46
return el

docs/md-to-htm.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ for %%f in (*.md) do (
55
REM echo %%~nf.htm
66
pandoc -f gfm -t html --lua-filter=md-to-htm.lua -o %%~nf.htm %%~nf.md
77
)
8+
9+
pause

docs/md-to-htm.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# links-to-html.lua
1+
# md-to-htm.lua
2+
-- Adapted from answer by JW https://stackoverflow.com/users/4321/jw
3+
-- at https://stackoverflow.com/questions/40993488
24
function Link(el)
35
el.target = string.gsub(el.target, "%.md", ".htm")
46
return el

src/demo/Package-Test.sql

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
create or replace package test_dbms_output authid definer
3+
as
4+
procedure wtplsql_run;
5+
end test_dbms_output;
6+
/
7+
8+
create or replace package body test_dbms_output
9+
as
10+
procedure wtplsql_run
11+
as
12+
begin
13+
dbms_output.enable(128000);
14+
end wtplsql_run;
15+
end test_dbms_output;
16+
/
17+
18+
create or replace package body test_dbms_output
19+
as
20+
procedure test_put_get_line
21+
is
22+
c_test1 constant varchar2(100) := 'Test 1';
23+
l_buffer varchar2(4000) := '';
24+
l_status number := null;
25+
begin
26+
dbms_output.put_line(c_test1);
27+
dbms_output.get_line(l_buffer,l_status);
28+
wt_assert.eq('Test 1',l_buffer,c_test1);
29+
end test_put_get_line;
30+
procedure wtplsql_run
31+
as
32+
begin
33+
dbms_output.enable(128000);
34+
test_put_get_line;
35+
end wtplsql_run;
36+
end test_dbms_output;
37+
/
38+
39+
begin
40+
wtplsql.test_run('TEST_DBMS_OUTPUT');
41+
wt_text_report.dbms_out(USER,'TEST_DBMS_OUTPUT',30);
42+
end;
43+
/
44+
45+
create or replace package body test_dbms_output
46+
as
47+
procedure test_put_get_line
48+
is
49+
c_test1 constant varchar2(100) := 'Test 1';
50+
l_buffer varchar2(4000) := '';
51+
l_status number := null;
52+
begin
53+
dbms_output.put_line(c_test1);
54+
raise_application_error(20000, 'Fault insertion exception');
55+
dbms_output.get_line(l_buffer,l_status);
56+
wt_assert.eq('Test 1',l_buffer,c_test1);
57+
end test_put_get_line;
58+
procedure wtplsql_run
59+
as
60+
begin
61+
dbms_output.enable(128000);
62+
test_put_get_line;
63+
end wtplsql_run;
64+
end test_dbms_output;
65+
/
66+
67+
begin
68+
wtplsql.test_run('TEST_DBMS_OUTPUT');
69+
end;
70+
/
71+
72+
begin
73+
wt_text_report.dbms_out(USER,'TEST_DBMS_OUTPUT',30);
74+
end;
75+
/
76+
77+
create or replace package body test_dbms_output
78+
as
79+
-- Global variables to capture buffer contents
80+
g_buffer_contents_va DBMSOUTPUT_LINESARRAY;
81+
g_num_lines number;
82+
--
83+
procedure setup
84+
is
85+
begin
86+
-- Capture buffer contents
87+
dbms_output.get_lines(g_buffer_contents_va, g_num_lines);
88+
end setup;
89+
--
90+
procedure test_put_get_line
91+
is
92+
c_test1 constant varchar2(100) := 'Test 1';
93+
l_buffer varchar2(4000) := '';
94+
l_status number := null;
95+
begin
96+
dbms_output.put_line(c_test1);
97+
raise_application_error(-20000, 'Fault insertion exception');
98+
dbms_output.get_line(l_buffer,l_status);
99+
wt_assert.eq('Test 1',l_buffer,c_test1);
100+
end test_put_get_line;
101+
--
102+
procedure teardown
103+
is
104+
l_junk_va DBMSOUTPUT_LINESARRAY;
105+
l_num number;
106+
begin
107+
-- Clear buffer contents
108+
dbms_output.get_lines(l_junk_va, l_num);
109+
-- Restore the buffer
110+
for i in 1 .. g_num_lines
111+
loop
112+
dbms_output.put_line(g_buffer_contents_va(i));
113+
end loop;
114+
end teardown;
115+
--
116+
procedure wtplsql_run
117+
is
118+
l_error_message varchar2(4000);
119+
begin
120+
dbms_output.enable(128000);
121+
dbms_output.put_line('This should be preserved.');
122+
setup;
123+
test_put_get_line;
124+
teardown;
125+
exception when others then
126+
l_error_message := substr(dbms_utility.format_error_stack ||
127+
dbms_utility.format_error_backtrace,1,4000);
128+
teardown;
129+
raise_application_error(-20000, l_error_message);
130+
end wtplsql_run;
131+
--
132+
end test_dbms_output;
133+
/
134+
135+
begin
136+
wtplsql.test_run('TEST_DBMS_OUTPUT');
137+
end;
138+
/
139+
140+
begin
141+
wt_text_report.dbms_out(USER,'TEST_DBMS_OUTPUT',30);
142+
end;
143+
/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy