File: serialize.test

package info (click to toggle)
nsf 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,208 kB
  • sloc: ansic: 32,687; tcl: 10,723; sh: 660; pascal: 176; javascript: 135; lisp: 41; makefile: 24
file content (345 lines) | stat: -rw-r--r-- 9,854 bytes parent folder | download | duplicates (2)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# -*- Tcl -*-

package prefer latest

package req nx::test
package req nx::serializer

nx::test case serialize-target {
  #
  # Create object structure with a forwarder and a slot
  #
  Object create ::xxx {
    :object property -accessor public ref
    Object create [self]::b {
      [:info parent] ref set [Object create [self]::c]
    }
  }
  #
  # check forwarder target and domain+manager of slot.
  #
  ? {nsf::method::forward::property :::xxx -per-object ref target} "::xxx::per-object-slot::ref"
  ? {nsf::var::get ::xxx::per-object-slot::ref manager} "::xxx::per-object-slot::ref"
  ? {nsf::var::get ::xxx::per-object-slot::ref domain} "::xxx"

  #puts [xxx serialize -target XXX]
  #
  # Create a serialized object, which has the target mapped to
  # XXX. The target name has intentionally no leading colons, such
  # that the object can be instantiated in a different namespace. This
  # is for example useful when importing objects in OpenACS from a
  # different system, where one has to assure that the imported
  # objects do not clash with the already existing objects, but it has
  # as well certain dangers.
  #
  set code [xxx serialize -target XXX]

  #
  # Create the object with the new target
  #
  set result [eval $code]

  ? [list set _ $result] ::XXX::per-object-slot::ref

  #
  # The target object of the forwarder + the slot manager and domain are mapped as well.
  # Otherwise, we would trigger warnings during destroy
  #

  ? {nsf::method::forward::property ::XXX -per-object ref target} "XXX::per-object-slot::ref"
  ? {nsf::var::get ::XXX::per-object-slot::ref manager} "XXX::per-object-slot::ref"
  ? {nsf::var::get ::XXX::per-object-slot::ref domain} "XXX"

}




nx::test case deepSerialize-map-filter {

  Object create ::a {
    :object property -accessor public ref:object,type=[:info class]
    Object create [self]::b {
      [:info parent] ref set [Object create [self]::c]
    }
  }

  ? {::nsf::object::exists ::a} 1
  ? {::nsf::object::exists ::a::b} 1
  ? {::nsf::object::exists ::a::b::c} 1
  ? {::a ref get} [[::a::b] info children]

  set script [::Serializer deepSerialize -map {::a::b ::x::y ::a ::x} ::a]
  # fix collateral damage (TODO: fixme, preprecate me, ...)
  set script [string map {::nsf::object::xlloc ::nsf::object::alloc} $script]

  ::a destroy

  ? {::nsf::object::exists ::a} 0
  ? {::nsf::object::exists ::a::b} 0
  ? {::nsf::object::exists ::a::b::c} 0

  eval $script

  ? {::nsf::object::exists ::a} 0
  ? {::nsf::object::exists ::a::b} 0
  ? {::nsf::object::exists ::a::b::c} 0

  ? {::nsf::object::exists ::x} 1
  ? {::nsf::object::exists ::x::y} 1
  ? {::nsf::object::exists ::x::y::c} 1
  ? {::x ref get} [::x::y info children]

  Object create ::a
  ::x::y::c eval {
    :object variable parentRef [[:info parent] info parent]
  }
  set script [::a eval {
    ::Serializer deepSerialize -map [list ::x::y [self] ::x [self]] ::x::y::c
  }]

  ? {::x::y::c eval {set :parentRef}} ::x
  ? {::nsf::object::exists ::a::c} 0
  eval $script
  ? {::nsf::object::exists ::a::c} 1
  ? {::a::c eval {set :parentRef}} ::a
}

nx::test case deepSerialize-ignoreVarsRE-filter {
  nx::Class create C {
    :object property -accessor public x
    :object property -accessor public y
    :property -accessor public a:int
    :property -accessor public b:int
    :create c1
  }

  ? {C x set 1} 1
  ? {C x get} 1
  ? {C y set 1} 1
  ? {C y get} 1

  ? {lsort [C info methods]} "a b"
  ? {lsort [C info object methods]} "x y"
  ? {c1 a set b} {expected integer but got "b" for parameter "value"}
  ? {c1 a set 1} 1
  ? {c1 b set 1} 1

  set c1(IgnoreNone1) [list [::Serializer deepSerialize c1] "a b"]
  set c1(IgnoreNone2) [list [::Serializer deepSerialize -ignoreVarsRE "" c1] "a b"]
  set c1(One)         [list [::Serializer deepSerialize -ignoreVarsRE "a" c1] "b"]
  set c1(One2)        [list [::Serializer deepSerialize -ignoreVarsRE {::a$} c1] "b"]
  set c1(IgnoreAll)   [list [::Serializer deepSerialize -ignoreVarsRE "." c1] ""]
  set names {}; foreach s [C info slots] {lappend names [$s cget -name]}
  set c1(None2)       [list [::Serializer deepSerialize -ignoreVarsRE [join $names |] c1] ""]

  c1 destroy
  foreach t [array names c1] {
    ? {nsf::object::exists c1} 0
    lassign $c1($t) script res
    eval $script
    ? {nsf::object::exists c1} 1
    ? {lsort [c1 info vars]} $res "Object c1 $t"
    c1 destroy
  }


  set C(IgnoreNone1) [list [::Serializer deepSerialize C] "x y"]
  set C(IgnoreNone2) [list [::Serializer deepSerialize -ignoreVarsRE "" C] "x y"]
  #set C(One) [list [::Serializer deepSerialize -ignoreVarsRE "x" C] "y"]
  set C(One2) [list [::Serializer deepSerialize -ignoreVarsRE {::x$} C] "y"]
  #set C(IgnoreAll) [list [::Serializer deepSerialize -ignoreVarsRE "." C] ""]
  set names {}; foreach s [C info object slots] {lappend names [$s cget -name]}
  #set C(None2) [list [::Serializer deepSerialize -ignoreVarsRE [join $names |] C] ""]

  C destroy

  foreach t [array names C] {
    ? {nsf::object::exists C} 0
    lassign $C($t) script res

    #puts stderr "=====C($t)\n$script\n===="

    eval $script
    ? {nsf::object::exists C} 1
    ? {lsort [C info vars]} $res "Class C $t"
    C destroy
  }
}

nx::test case deepSerialize-ignore-filter {
  Object create ::a {
    Object create [self]::b
    Object create [self]::c
  }

  ? {::nsf::object::exists ::a} 1
  ? {::nsf::object::exists ::a::b} 1
  ? {::nsf::object::exists ::a::c} 1

  set script [::Serializer deepSerialize -ignore ::a::b ::a]
  ::a destroy

  ? {::nsf::object::exists ::a::c} 0
  ? {::nsf::object::exists ::a::b} 0
  ? {::nsf::object::exists ::a} 0

  eval $script
  ? {::nsf::object::exists ::a} 1
  ? {::nsf::object::exists ::a::b} 0
  ? {::nsf::object::exists ::a::c} 1

  set script [::Serializer deepSerialize -ignore ::a ::a]
  ::a destroy

  ? {::nsf::object::exists ::a} 0
  eval $script
  ? {::nsf::object::exists ::a} 0
}

nx::test case serialize-slotContainer {

  nx::Class create C {
    :object property x
    :property a
  }

  ? {::nsf::object::exists ::C::slot} 1
  ? {::nsf::object::exists ::C::per-object-slot} 1
  ? {::nx::isSlotContainer ::C::slot} 1
  ? {::nx::isSlotContainer ::C::per-object-slot} 1
  ? {::nsf::object::exists ::C::slot::a} 1
  ? {::nsf::object::exists ::C::per-object-slot::x} 1
  ? {::nsf::object::property ::C hasperobjectslots} 1

  set script [C serialize]
  C destroy
  ? {::nsf::object::exists ::C} 0

  eval $script
  ? {::nsf::object::exists ::C::slot} 1
  ? {::nsf::object::exists ::C::per-object-slot} 1
  ? {::nx::isSlotContainer ::C::slot} 1
  ? {::nx::isSlotContainer ::C::per-object-slot} 1
  ? {::nsf::object::exists ::C::slot::a} 1
  ? {::nsf::object::exists ::C::per-object-slot::x} 1
  ? {::nsf::object::property ::C hasperobjectslots} 1
}

#
# check whether ::nsf::object::properties keepcallerself and
# perobjectdispatch for nx::Objects are handled correctly via serialize
#
nx::test case serialize-object-properties {

  #
  # Check on object o
  #
  nx::Object create o
  ::nsf::object::property ::o keepcallerself 1
  ::nsf::object::property ::o perobjectdispatch 1

  set script [o serialize]
  o destroy
  ? {::nsf::object::exists ::o} 0

  eval $script
  ? {::nsf::object::property ::o keepcallerself} 1
  ? {::nsf::object::property ::o perobjectdispatch} 1

  #
  # Now the same for a class
  #
  nx::Class create C
  ::nsf::object::property ::C keepcallerself 1
  ::nsf::object::property ::C perobjectdispatch 1

  set script [C serialize]
  C destroy
  ? {::nsf::object::exists ::C} 0

  eval $script
  ? {::nsf::object::property ::C keepcallerself} 1
  ? {::nsf::object::property ::C perobjectdispatch} 1

}

#
# Check handling of method properties "debug" and "deprecated"
# in serializer
#
nx::test case nx-serialize-debug-deprecated {

  #
  # Check on object o
  #
  nx::Object create o {
    :public object method -deprecated ofoo {} {return 1}
    :public object method -debug      obar {} {return 1}
    :public object alias -deprecated -debug obaz ::nsf::is
  }
  ? {::nsf::method::property o ofoo deprecated} 1
  ? {::nsf::method::property o ofoo debug} 0
  ? {::nsf::method::property o obar deprecated} 0
  ? {::nsf::method::property o obar debug} 1
  ? {::nsf::method::property o obaz deprecated} 1
  ? {::nsf::method::property o obaz debug} 1


  set script [o serialize]
  o destroy
  ? {::nsf::object::exists ::o} 0

  eval $script

  ? {::nsf::method::property o ofoo deprecated} 1
  ? {::nsf::method::property o ofoo debug} 0
  ? {::nsf::method::property o obar deprecated} 0
  ? {::nsf::method::property o obar debug} 1
  ? {::nsf::method::property o obaz deprecated} 1
  ? {::nsf::method::property o obaz debug} 1
  #
  # Now the same for a class
  #
  nx::Class create C {
    :public method -deprecated foo {} {return 1}
    :public method -debug      bar {} {return 1}
    :public alias -deprecated -debug baz ::nsf::is
  }

  ? {::nsf::method::property C foo deprecated} 1
  ? {::nsf::method::property C foo debug} 0
  ? {::nsf::method::property C bar deprecated} 0
  ? {::nsf::method::property C bar debug} 1
  ? {::nsf::method::property C baz deprecated} 1
  ? {::nsf::method::property C baz debug} 1

  set script [C serialize]
  C destroy
  ? {::nsf::object::exists ::C} 0

  eval $script
  ? {::nsf::method::property C foo deprecated} 1
  ? {::nsf::method::property C foo debug} 0
  ? {::nsf::method::property C bar deprecated} 0
  ? {::nsf::method::property C bar debug} 1
  ? {::nsf::method::property C baz deprecated} 1
  ? {::nsf::method::property C baz debug} 1
}


#
# Check serializing of info internals
#
package require XOTcl
package require xotcl::serializer
nx::test case xotcl-info-internals {
  ? {catch {::Serializer methodSerialize ::xotcl::classInfo default ""}} 0
}
#
# Local variables:
#    mode: tcl
#    tcl-indent-level: 2
#    indent-tabs-mode: nil
# End: