1
1
Class UnitTest .iscru .util .StreamUtils .TestStreamLike Extends %UnitTest .TestCase
2
2
{
3
3
4
+ /// Name of the persistent class for testing streamLike stored procedure
5
+ Parameter TEMPCLASSNAME = {..%ClassName (1 ) _ " .TempClass" };
6
+
7
+ Method OnBeforeAllTests () As %Status
8
+ {
9
+ do ..dropTempClass (..#TEMPCLASSNAME)
10
+
11
+ // create and compile a persistent class with just one stream property
12
+ quit ..createTempClass (..#TEMPCLASSNAME)
13
+ }
14
+
15
+ Method OnAfterAllTests () As %Status
16
+ {
17
+ quit ..dropTempClass (..#TEMPCLASSNAME)
18
+ }
19
+
4
20
Method TestWithoutPPGCache ()
5
21
{
6
- do ..internal ($$$NO)
22
+ do ..internal ($$$NO, $$$NO )
7
23
}
8
24
9
25
Method TestWithPPGCache ()
10
26
{
11
- do ..internal ($$$YES)
27
+ do ..internal ($$$YES, $$$NO )
12
28
}
13
29
14
- Method internal ( cacheToPPG As %Boolean ) [ Private ]
30
+ Method TestStoredProcWithoutPPGCache ()
15
31
{
16
- // temp global name
17
- #dim global As %String = " ^||" _ $classname ()
18
-
19
- do ..populateGlobal (global )
32
+ do ..internal ($$$NO, $$$YES)
33
+ }
34
+
35
+ Method TestStoredProcWithPPGCache ()
36
+ {
37
+ do ..internal ($$$YES, $$$YES)
38
+ }
39
+
40
+ Method internal (cacheToPPG As %Boolean , testStoredProc As %Boolean ) [ Private ]
41
+ {
42
+ if testStoredProc && '$$$comClassDefined(..#TEMPCLASSNAME)
43
+ {
44
+ $$$ThrowStatus($$$ERROR($$$GeneralError, " Persistent class " _ ..#TEMPCLASSNAME _ " not compiled" ))
45
+ }
20
46
21
- // now each node of the global contains a list:
47
+ // populate temp global, assuming each node has a list of items :
22
48
// edgesStr*, stuffingStringCount*, pattern, escape char, case insensitive flag, expected result
23
49
// * - edgesStr and stuffingStringCount are arguments for ..createStream() method
50
+ #dim globalName As %String = ..populateGlobal ()
24
51
25
- // loop through the items and test streamLike()
26
- for i = 1 :1 :@global
52
+ // loop through the nodes and test streamLike() method or stored procedure (testStoredProc=1 )
53
+ for i = 1 :1 :@globalName
27
54
{
28
- #dim list As %List = @global @(i )
55
+ #dim list As %List = @globalName @(i )
29
56
#dim result As %Boolean
30
57
#dim expected As %Boolean
31
- do ..getResultAndExpected (cacheToPPG , list , .result , .expected )
58
+ do ..doTest (cacheToPPG , testStoredProc , ..#TEMPCLASSNAME , list , .result , .expected )
32
59
33
60
do $$$AssertEquals(result , expected , expected _ " = " _ result )
34
61
}
35
62
36
- kill @global
63
+ kill @globalName
37
64
}
38
65
39
- /// do ##class(UnitTest.iscru.util.StreamUtils.TestStreamLike).debugTest(0)
40
- ClassMethod debugTest (cacheToPPG As %Boolean )
66
+ /// do ##class(UnitTest.iscru.util.StreamUtils.TestStreamLike).debugTest(0, 0 )
67
+ ClassMethod debugTest (cacheToPPG As %Boolean , testStoredProc As %Boolean )
41
68
{
42
- // temp global name
43
- #dim global As %String = " ^||" _ $classname ()
69
+ if testStoredProc
70
+ {
71
+ do ..dropTempClass (..#TEMPCLASSNAME)
72
+ #dim sc As %Status = ..createTempClass (..#TEMPCLASSNAME)
73
+ $$$ThrowOnError(sc )
74
+ }
44
75
45
- do ..populateGlobal (global )
76
+ #dim globalName As %String = ..populateGlobal ()
46
77
47
- for i = 1 :1 :@global
78
+ for i = 1 :1 :@globalName
48
79
{
49
- #dim list As %List = @global @(i )
80
+ #dim list As %List = @globalName @(i )
50
81
#dim result As %Boolean
51
82
#dim expected As %Boolean
52
- do ..getResultAndExpected (cacheToPPG , list , .result , .expected )
83
+ do ..doTest (cacheToPPG , testStoredProc , ..#TEMPCLASSNAME , list , .result , .expected )
53
84
if (expected '= result ) write expected _ " '= " _ result _ " / " zw list
54
85
}
55
86
56
- kill @global
87
+ kill @globalName
88
+ if testStoredProc do ..dropTempClass (..#TEMPCLASSNAME)
57
89
}
58
90
59
- ClassMethod populateGlobal (global As %String ) [ Private ]
91
+ /// Return name of the global.
92
+ /// Each node of the global contains a list:
93
+ /// edgesStr*, stuffingStringCount*, pattern, escape char, case insensitive flag, expected result
94
+ /// * - edgesStr and stuffingStringCount are arguments for ..createStream() method.
95
+ ClassMethod populateGlobal () As %String [ Private ]
60
96
{
61
- kill @ global
97
+ #dim global As %String = " ^|| " _ $classname ()
62
98
63
- // each node of the global will contain a list:
64
- // edgesStr*, stuffingStringCount*, pattern, escape char, case insensitive flag, expected result
65
- // * - edgesStr and stuffingStringCount are arguments for ..createStream() method
66
-
99
+ kill @global
100
+
67
101
// I. test with no escape char, case insensitive
68
102
// 1) stream = "abcabc"
69
103
set @global @($i (@global )) = $lb (" abcabc" , 0 , " ABCABC" , " " , $$$YES, $$$YES)
@@ -173,6 +207,8 @@ ClassMethod populateGlobal(global As %String) [ Private ]
173
207
set @global @($i (@global )) = $lb (" abcabc" , 0 , $c (0 ), " " , $$$YES, $$$NO)
174
208
set @global @($i (@global )) = $lb (" abcabc" , 0 , $c (0 ), " ~" , $$$NO, $$$NO)
175
209
set @global @($i (@global )) = $lb (" abcabc" , 0 , $c (0 ), " ~" , $$$YES, $$$NO)
210
+
211
+ quit global
176
212
}
177
213
178
214
/// If <var>stuffingStringCount</var> equals zero then return <var>edgesStr</var> wrapped in a %Stream.TmpCharacter.
@@ -198,18 +234,88 @@ ClassMethod createStream(edgesStr As %String, stuffingStringCount As %Integer(MI
198
234
quit s
199
235
}
200
236
201
- /// Call ##class(iscru.util.StreamUtils).streamLike() with data from <var>list</var>.
202
- /// We assume that <var>list</var> contains the following items:
237
+ /// Using data from <var>list</var>: test either ##class(iscru.util.StreamUtils).streamLike() method
238
+ /// or iscru_util.FunctionSet_streamLike stored procedure (if <var>testStoredProc</var> equals 1)
239
+ /// assuming that <var>list</var> contains the following items:
203
240
/// edgesStr*, stuffingStringCount*, pattern, escape char, case insensitive flag, expected result<br/>
204
241
/// * - edgesStr and stuffingStringCount are arguments for ..createStream() method.
205
- ClassMethod getResultAndExpected (cacheToPPG As %Boolean , list As %List , Output result As %Boolean , Output expected As %Boolean ) [ Private ]
242
+ ClassMethod doTest (cacheToPPG As %Boolean , testStoredProc As %Boolean , className As %String , list As %List , Output result As %Boolean , Output expected As %Boolean ) [ Private ]
206
243
{
207
244
#dim stream As %Stream.Object = ..createStream ($list (list , 1 ), $list (list , 2 ))
208
245
#dim pattern As %String = $list (list , 3 )
209
246
#dim escape As %String = $list (list , 4 )
210
247
#dim caseInsens As %Boolean = +$list (list , 5 )
211
248
set expected = +$list (list , 6 )
212
- set result = ##class (iscru.util.StreamUtils ).streamLike (stream , pattern , escape , caseInsens , cacheToPPG )
249
+
250
+ if 'testStoredProc
251
+ {
252
+ // test streamLike() method
253
+ set result = ##class (iscru.util.StreamUtils ).streamLike (stream , pattern , escape , caseInsens , cacheToPPG )
254
+ }
255
+ else
256
+ {
257
+ // test iscru_util.FunctionSet_streamLike stored procedure
258
+
259
+ // truncate table and add just one row
260
+ do $classmethod (className , " %KillExtent" )
261
+ #dim obj As %Persistent = $classmethod (className , " %New" )
262
+ do obj .stream .CopyFrom (stream )
263
+ #dim sc As %Status = obj .%Save ()
264
+ kill stream , obj
265
+ $$$ThrowOnError(sc )
266
+
267
+ // query table
268
+ #dim tableName As %String = $$$comClassKeyGet(className , $$$cCLASSsqlschemaname) _ " ." _ $$$comClassKeyGet(className , $$$cCLASSsqltablename)
269
+ #dim sql As %String = " SELECT 1 FROM " _ tableName _ " WHERE 1 = iscru_util.FunctionSet_streamLike(stream, ?, ?, ?, ?)"
270
+ #dim statement As %SQL.Statement = ##class (%SQL.Statement ).%New ()
271
+ set sc = statement .%Prepare (sql )
272
+ $$$ThrowOnError(sc )
273
+
274
+ #dim stResult As %SQL.StatementResult = statement .%Execute (pattern , escape , caseInsens , cacheToPPG )
275
+ #dim SQLCODE As %Integer = stResult .%SQLCODE
276
+ if (SQLCODE < 0 ) $$$ThrowStatus($$$ERROR($$$SQLError, SQLCODE , stResult .%Message ))
277
+
278
+ set result = stResult .%Next ()
279
+ }
280
+ }
281
+
282
+ /// Create persistent class with the given name. Add just one stream property to the class.
283
+ ClassMethod createTempClass (className As %String ) [ Private ]
284
+ {
285
+ #dim c As %Dictionary.ClassDefinition = ##class (%Dictionary.ClassDefinition ).%New ()
286
+ set c .Name = className
287
+ set c .ProcedureBlock = $$$YES
288
+ set c .Super = " %Persistent"
289
+
290
+ #dim p As %Dictionary.PropertyDefinition = ##class (%Dictionary.PropertyDefinition ).%New ()
291
+ set p .Name = " stream"
292
+ set p .Type = " %GlobalCharacterStream"
293
+ do c .Properties .Insert (p )
294
+
295
+ #dim sc As %Status = c .%Save ()
296
+ if $$$ISERR(sc ) quit sc
297
+
298
+ set sc = $System .OBJ .Compile (c .Name )
299
+ if $$$ISERR(sc ) quit sc
300
+
301
+ quit $$$OK
302
+ }
303
+
304
+ /// Delete data and drop persistent class.
305
+ ClassMethod dropTempClass (className As %String ) [ Private ]
306
+ {
307
+ try
308
+ {
309
+ // if there is a compiled class with the given name then kill data using %KillExtent() method
310
+ if $$$comClassDefined(className ) do $classmethod (className , " %KillExtent" )
311
+
312
+ // drop the class
313
+ if ##class (%Dictionary.ClassDefinition ).%ExistsId (className ) do ##class (%Dictionary.ClassDefinition ).%DeleteId (className )
314
+ }
315
+ catch
316
+ {}
317
+
318
+ quit $$$OK
213
319
}
214
320
215
321
}
0 commit comments