rubywbem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1610 @@
1
+ #
2
+ # Copyright 2006, Red Hat, Inc
3
+ # Scott Seago <sseago@redhat.com>
4
+ #
5
+ # derived from pywbem, written by Tim Potter <tpot@hp.com>, Martin Pool <mbp@hp.com>
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program; if not, write to the Free Software
14
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
+ #
16
+
17
+ #
18
+ # Test CIM object interface.
19
+ #
20
+ # Ideally this file would completely describe the Ruby interface to
21
+ # CIM objects. If a particular data structure or Ruby property is
22
+ # not implemented here, then it is not officially supported by RubyWBEM.
23
+ # Any breaking of backwards compatibility of new development should be
24
+ # picked up here.
25
+ #
26
+
27
+ require "comfychair"
28
+ require "validate"
29
+ require "wbem"
30
+
31
+ module WBEM
32
+ module Test
33
+ class ValidateTest < Comfychair::TestCase
34
+ include Validate
35
+ def validate(obj)
36
+ #"""Run a CIM XML fragment through the validator."""
37
+ self.log(obj.toxml())
38
+ assert_(validate_xml(obj.toxml(), dtd_directory = '../..'))
39
+ end
40
+ end
41
+
42
+ class DictTest < Comfychair::TestCase
43
+
44
+ def runtest_dict(obj)
45
+
46
+ # Test __getitem__
47
+ self.assert_(obj['Chicken'] == 'Ham')
48
+ self.assert_(obj['Beans'] == 42)
49
+
50
+ self.assert_(obj['Cheepy'].nil?)
51
+ begin
52
+ obj.fetch('Cheepy')
53
+ rescue IndexError
54
+ else
55
+ fail('IndexError not thrown')
56
+ end
57
+
58
+ # Test __setitem__
59
+
60
+ obj['tmp'] = 'tmp'
61
+ self.assert_(obj['tmp'] == 'tmp')
62
+
63
+ # Test has_key
64
+
65
+ self.assert_(obj.has_key?('tmp'))
66
+
67
+ # Test __delitem__
68
+
69
+ obj.delete('tmp')
70
+ self.assert_(!obj.has_key?('tmp'))
71
+
72
+ # Test __len__
73
+
74
+ self.assert_(obj.length == 2)
75
+
76
+ # Test keys
77
+
78
+ keys = obj.keys()
79
+ self.assert_(keys.include?('Chicken') && keys.include?('Beans'))
80
+ self.assert_(keys.length == 2)
81
+
82
+ # Test values
83
+
84
+ values = obj.values()
85
+ self.assert_(values.include?('Ham') && values.include?(42))
86
+ self.assert_(values.length == 2)
87
+
88
+ # Test items
89
+
90
+ items = obj.to_a()
91
+ self.assert_(items.include?(['Chicken', 'Ham']) &&
92
+ items.include?(['Beans', 42]))
93
+ self.assert_(items.length == 2)
94
+
95
+ # Test iterkeys
96
+ # not in ruby
97
+ # Test itervalues
98
+ # not in ruby
99
+ # Test iteritems
100
+ # not in ruby
101
+ end
102
+ end
103
+
104
+ #################################################################
105
+ # CIMInstanceName
106
+ #################################################################
107
+
108
+ class InitCIMInstanceName < Comfychair::TestCase
109
+ #"""A CIMInstanceName can be initialised with just a classname, or a
110
+ #classname and dict of keybindings."""
111
+
112
+ def runtest
113
+
114
+ # Initialise with classname only
115
+
116
+ obj = CIMInstanceName.new('CIM_Foo')
117
+ self.assert_(obj.keys().length == 0)
118
+
119
+ # Initialise with keybindings dict
120
+
121
+ obj = CIMInstanceName.new('CIM_Foo', {'Name'=> 'Foo', 'Chicken' => 'Ham'})
122
+ self.assert_(obj.keys().length == 2)
123
+
124
+ # Initialise with all possible keybindings types
125
+
126
+ obj = CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo',
127
+ 'Number' => 42,
128
+ 'Boolean' => false,
129
+ 'Ref' => CIMInstanceName.new('CIM_Bar')})
130
+ self.assert_(obj.keys().length == 4)
131
+
132
+ # Initialise with namespace
133
+
134
+ obj = CIMInstanceName.new('CIM_Foo',
135
+ {'InstanceID' => '1234'},
136
+ nil, 'root/cimv2')
137
+
138
+ # Initialise with host and namespace
139
+
140
+ obj = CIMInstanceName.new('CIM_Foo',
141
+ {'InstanceID' => '1234'},
142
+ 'woot.com',
143
+ 'root/cimv2')
144
+ end
145
+ end
146
+
147
+ class CopyCIMInstanceName < Comfychair::TestCase
148
+
149
+ def runtest
150
+
151
+ i = CIMInstanceName.new('CIM_Foo',
152
+ {'InstanceID' => '1234'},
153
+ 'woot.com',
154
+ 'root/cimv2')
155
+
156
+ c = i.clone
157
+
158
+ self.assert_equal(i, c)
159
+
160
+ c.classname = 'CIM_Bar'
161
+ c.keybindings = NocaseHash.new({'InstanceID' => '5678'})
162
+ c.host = nil
163
+ c.namespace = nil
164
+
165
+ self.assert_(i.classname == 'CIM_Foo')
166
+ self.assert_(i.keybindings['InstanceID'] == '1234')
167
+ self.assert_(i.host == 'woot.com')
168
+ self.assert_(i.namespace == 'root/cimv2')
169
+ end
170
+ end
171
+
172
+ class CIMInstanceNameAttrs < Comfychair::TestCase
173
+ #"""Valid attributes for CIMInstanceName are 'classname' and
174
+ #'keybindings'."""
175
+
176
+ def runtest
177
+
178
+ kb = {'Chicken' => 'Ham', 'Beans' => 42}
179
+
180
+ obj = CIMInstanceName.new('CIM_Foo', kb)
181
+
182
+ self.assert_(obj.classname == 'CIM_Foo')
183
+ self.assert_(obj.keybindings == kb)
184
+ self.assert_(obj.host.nil?)
185
+ self.assert_(obj.namespace.nil?)
186
+ end
187
+ end
188
+
189
+ class CIMInstanceNameDictInterface < DictTest
190
+ #"""Test the Python dictionary interface for CIMInstanceName."""
191
+
192
+ def runtest
193
+
194
+ kb = {'Chicken' => 'Ham', 'Beans' => 42}
195
+ obj = CIMInstanceName.new('CIM_Foo', kb)
196
+
197
+ self.runtest_dict(obj)
198
+ end
199
+ end
200
+
201
+ class CIMInstanceNameEquality < Comfychair::TestCase
202
+ #"""Test comparing CIMInstanceName objects."""
203
+
204
+ def runtest
205
+
206
+ # Basic equality tests
207
+
208
+ self.assert_equal(CIMInstanceName.new('CIM_Foo'),
209
+ CIMInstanceName.new('CIM_Foo'))
210
+
211
+ self.assert_notequal(CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}),
212
+ CIMInstanceName.new('CIM_Foo'))
213
+
214
+ self.assert_equal(CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}),
215
+ CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}))
216
+
217
+ # Classname should be case insensitive
218
+
219
+ self.assert_equal(CIMInstanceName.new('CIM_Foo'),
220
+ CIMInstanceName.new('cim_foo'))
221
+
222
+ # NocaseDict should implement case insensitive keybinding names
223
+
224
+ self.assert_equal(CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}),
225
+ CIMInstanceName.new('CIM_Foo', {'cheepy' => 'Birds'}))
226
+
227
+ self.assert_notequal(CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}),
228
+ CIMInstanceName.new('CIM_Foo', {'cheepy' => 'birds'}))
229
+
230
+ # Test a bunch of different keybinding types
231
+
232
+ obj1 = CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo',
233
+ 'Number' => 42,
234
+ 'Boolean' => false,
235
+ 'Ref' => CIMInstanceName.new('CIM_Bar')})
236
+
237
+ obj2 = CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo',
238
+ 'Number' => 42,
239
+ 'Boolean' => false,
240
+ 'Ref' => CIMInstanceName.new('CIM_Bar')})
241
+
242
+ self.assert_equal(obj1, obj2)
243
+
244
+ # Test keybinding types are not confused in comparisons
245
+
246
+ self.assert_notequal(CIMInstanceName.new('CIM_Foo', {'Foo' => '42'}),
247
+ CIMInstanceName.new('CIM_Foo', {'Foo' => 42}))
248
+
249
+ self.assert_notequal(CIMInstanceName.new('CIM_Foo', {'Bar' => true}),
250
+ CIMInstanceName.new('CIM_Foo', {'Bar' => 'TRUE'}))
251
+
252
+ # Test hostname is case insensitive
253
+
254
+ self.assert_equal(CIMInstanceName.new('CIM_Foo', {}, 'woot.com'),
255
+ CIMInstanceName.new('CIM_Foo', {}, 'Woot.Com'))
256
+ end
257
+ end
258
+
259
+ class CIMInstanceNameCompare < Comfychair::TestCase
260
+ def runtest
261
+ raise Comfychair::NotRunError
262
+ end
263
+ end
264
+
265
+ class CIMInstanceNameSort < Comfychair::TestCase
266
+ def runtest
267
+ raise Comfychair::NotRunError
268
+ end
269
+ end
270
+
271
+ class CIMInstanceNameString < Comfychair::TestCase
272
+ #"""Test string representation functions for CIMInstanceName
273
+ #objects."""
274
+
275
+ def runtest
276
+
277
+ obj = CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo', 'Secret' => 42})
278
+
279
+ # Test str() method generates output with classname and
280
+ # keybindings: e.g CIM_Foo.Secret=42,Name="Foo"
281
+
282
+ s = obj.to_s
283
+
284
+ self.assert_re_match('^CIM_Foo\.', s)
285
+ self.assert_re_match('Secret=42', s)
286
+ self.assert_re_match('Name="Foo"', s)
287
+
288
+ s = s.sub!('CIM_Foo.', '')
289
+ s = s.sub!('Secret=42', '')
290
+ s = s.sub!('Name="Foo"', '')
291
+
292
+ self.assert_(s == ',')
293
+
294
+ # not relevant for Ruby
295
+ # Test repr() function contains slightly more verbose
296
+ # output, but we're not too concerned about the format.
297
+ #
298
+ # CIMInstanceName(classname='CIM_Foo', \
299
+ # keybindings=NocaseDict({'Secret' => 42, 'Name' => 'Foo'}))
300
+
301
+ #r = repr(obj)
302
+
303
+ #self.assert_re_match('^CIMInstanceName\(classname=\'CIM_Foo\'', r)
304
+ #self.assert_re_search('keybindings=', r)
305
+ #self.assert_re_search('\'Secret\' => 42', r)
306
+ #self.assert_re_search('\'Name\' => \'Foo\'', r)
307
+
308
+ # Test str() with namespace
309
+
310
+ obj = CIMInstanceName.new('CIM_Foo', {'InstanceID' => '1234'},
311
+ nil, 'root/InterOp')
312
+
313
+ self.assert_equal(obj.to_s, 'root/InterOp:CIM_Foo.InstanceID="1234"')
314
+
315
+ # Test str() with host and namespace
316
+
317
+ obj = CIMInstanceName.new('CIM_Foo', {'InstanceID' => '1234'},
318
+ 'woot.com',
319
+ 'root/InterOp')
320
+
321
+ self.assert_equal(obj.to_s,
322
+ '//woot.com/root/InterOp:CIM_Foo.InstanceID="1234"')
323
+ end
324
+ end
325
+
326
+ class CIMInstanceNameToXML < ValidateTest
327
+ #"""Test valid XML is generated for various CIMInstanceName objects."""
328
+
329
+ def runtest
330
+
331
+ self.validate(CIMInstanceName.new('CIM_Foo'))
332
+ self.validate(CIMInstanceName.new('CIM_Foo', {'Cheepy' => 'Birds'}))
333
+ self.validate(CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo',
334
+ 'Number' => 42,
335
+ 'Boolean' => false,
336
+ 'Ref' => CIMInstanceName.new('CIM_Bar')}))
337
+ self.validate(CIMInstanceName.new('CIM_Foo', {}, nil, 'root/cimv2'))
338
+ self.validate(CIMInstanceName.new('CIM_Foo', {}, 'woot.com', 'root/cimv2'))
339
+ end
340
+ end
341
+ #################################################################
342
+ # CIMInstance
343
+ #################################################################
344
+
345
+ class InitCIMInstance < Comfychair::TestCase
346
+ #"""CIMInstance objects can be initialised in a similar manner to
347
+ #CIMInstanceName, i.e classname only, or a list of properties."""
348
+
349
+ def runtest
350
+
351
+ # Initialise with classname only
352
+
353
+ obj = CIMInstance.new('CIM_Foo')
354
+
355
+ # Initialise with keybindings dict
356
+
357
+ obj = CIMInstance.new('CIM_Foo', {'Name' => 'Foo', 'Chicken' => 'Ham'})
358
+ self.assert_(obj.keys().length == 2)
359
+
360
+ # Check that CIM type checking is done for integer and
361
+ # floating point property values
362
+
363
+ begin
364
+ obj = CIMInstance.new('CIM_Foo', {'Number' => 42})
365
+ rescue TypeError
366
+ else
367
+ self.fail('TypeError not raised')
368
+ end
369
+
370
+ obj = CIMInstance.new('CIM_Foo', {'Foo' => Uint32.new(42),
371
+ 'Bar' => Real32.new(42.0)})
372
+
373
+ # Initialise with qualifiers
374
+
375
+ obj = CIMInstance.new('CIM_Foo', {},
376
+ {'Key' => CIMQualifier.new('Key', true)})
377
+
378
+ # Initialise with path
379
+
380
+ obj = CIMInstance.new('CIM_Foo',
381
+ {'InstanceID' => '1234'},
382
+ nil, CIMInstanceName.new('CIM_Foo',
383
+ {'InstanceID' => '1234'}))
384
+ end
385
+ end
386
+
387
+ class CopyCIMInstance < Comfychair::TestCase
388
+
389
+ def runtest
390
+
391
+ i = CIMInstance.new('CIM_Foo',
392
+ {'Name' => 'Foo', 'Chicken' => 'Ham'},
393
+ {'Key' => 'Value'},
394
+ CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo'}))
395
+
396
+ c = i.clone
397
+
398
+ self.assert_equal(i, c)
399
+
400
+ c.classname = 'CIM_Bar'
401
+ c.properties = {'InstanceID' => '5678'}
402
+ c.qualifiers = {}
403
+ c.path = nil
404
+
405
+ self.assert_(i.classname == 'CIM_Foo')
406
+ self.assert_(i['Name'] == 'Foo')
407
+ self.assert_(i.qualifiers['Key'] == 'Value')
408
+ self.assert_(i.path == CIMInstanceName.new('CIM_Foo', {'Name' => 'Foo'}))
409
+ end
410
+ end
411
+
412
+ class CIMInstanceAttrs < Comfychair::TestCase
413
+ #"""Valid attributes for CIMInstance are 'classname' and
414
+ #'keybindings'."""
415
+
416
+ def runtest
417
+
418
+ props = {'Chicken' => 'Ham', 'Number' => Uint32.new(42)}
419
+
420
+ obj = CIMInstance.new('CIM_Foo', props,
421
+ {'Key' => CIMQualifier.new('Key', true)},
422
+ CIMInstanceName.new('CIM_Foo',
423
+ {'Chicken' => 'Ham'}))
424
+
425
+ self.assert_(obj.classname == 'CIM_Foo')
426
+
427
+ self.assert_(obj.properties)
428
+ self.assert_(obj.qualifiers)
429
+ self.assert_(obj.path)
430
+ end
431
+ end
432
+
433
+ class CIMInstanceDictInterface < DictTest
434
+ #"""Test the Python dictionary interface for CIMInstance."""
435
+
436
+ def runtest
437
+
438
+ props = {'Chicken' => 'Ham', 'Beans' => Uint32.new(42)}
439
+ obj = CIMInstance.new('CIM_Foo', props)
440
+
441
+ self.runtest_dict(obj)
442
+
443
+ # Test CIM type checking
444
+
445
+ begin
446
+ obj['Foo'] = 43
447
+ rescue TypeError
448
+ else
449
+ self.fail('TypeError not raised')
450
+ end
451
+
452
+ obj['Foo'] = Uint32.new(43)
453
+ end
454
+ end
455
+
456
+ class CIMInstanceEquality < Comfychair::TestCase
457
+ #"""Test comparing CIMInstance objects."""
458
+
459
+ def runtest
460
+
461
+ # Basic equality tests
462
+
463
+ self.assert_equal(CIMInstance.new('CIM_Foo'),
464
+ CIMInstance.new('CIM_Foo'))
465
+
466
+ self.assert_notequal(CIMInstance.new('CIM_Foo', {'Cheepy' => 'Birds'}),
467
+ CIMInstance.new('CIM_Foo'))
468
+
469
+ # Classname should be case insensitive
470
+
471
+ self.assert_equal(CIMInstance.new('CIM_Foo'),
472
+ CIMInstance.new('cim_foo'))
473
+
474
+ # NocaseDict should implement case insensitive keybinding names
475
+
476
+ self.assert_equal(CIMInstance.new('CIM_Foo', {'Cheepy' => 'Birds'}),
477
+ CIMInstance.new('CIM_Foo', {'cheepy' => 'Birds'}))
478
+
479
+ self.assert_notequal(CIMInstance.new('CIM_Foo', {'Cheepy' => 'Birds'}),
480
+ CIMInstance.new('CIM_Foo', {'cheepy' => 'birds'}))
481
+
482
+ # Qualifiers
483
+
484
+ self.assert_notequal(CIMInstance.new('CIM_Foo'),
485
+ CIMInstance.new('CIM_Foo', {},
486
+ {'Key' => CIMQualifier.new('Key', true)}))
487
+
488
+ # Path
489
+
490
+ self.assert_notequal(CIMInstance.new('CIM_Foo'),
491
+ CIMInstance.new('CIM_Foo', {'Cheepy' => 'Birds'}))
492
+
493
+ # Reference properties
494
+
495
+ self.assert_equal(CIMInstance.new('CIM_Foo',
496
+ {'Ref1' => CIMInstanceName.new('CIM_Bar')}),
497
+ CIMInstance.new('CIM_Foo',
498
+ {'Ref1' => CIMInstanceName.new('CIM_Bar')}))
499
+
500
+ # Null properties
501
+
502
+ self.assert_notequal(
503
+ CIMInstance.new('CIM_Foo',
504
+ {'Null' => CIMProperty.new('Null', nil, 'string')}),
505
+ CIMInstance.new('CIM_Foo',
506
+ {'Null' => CIMProperty.new('Null', '')}))
507
+
508
+ self.assert_notequal(
509
+ CIMInstance.new('CIM_Foo',
510
+ {'Null' => CIMProperty.new('Null', nil, type = 'uint32')}),
511
+ CIMInstance.new('CIM_Foo',
512
+ {'Null' => CIMProperty.new('Null', Uint32.new(0))}))
513
+
514
+ # Mix of CIMProperty and native Python types
515
+
516
+ self.assert_equal(
517
+ CIMInstance.new(
518
+ 'CIM_Foo',
519
+ {'string' => 'string',
520
+ 'uint8' => Uint8.new(0),
521
+ 'uint8array' => [Uint8.new(1), Uint8.new(2)],
522
+ 'ref' => CIMInstanceName.new('CIM_Bar')}),
523
+ CIMInstance.new(
524
+ 'CIM_Foo',
525
+ {'string' => CIMProperty.new('string', 'string'),
526
+ 'uint8' => CIMProperty.new('uint8', Uint8.new(0)),
527
+ 'uint8Array' => CIMProperty.new('uint8Array', [Uint8.new(1), Uint8.new(2)]),
528
+ 'ref' => CIMProperty.new('ref', CIMInstanceName.new('CIM_Bar'))})
529
+ )
530
+ end
531
+ end
532
+
533
+ class CIMInstanceCompare < Comfychair::TestCase
534
+ def runtest
535
+ raise Comfychair::NotRunError
536
+ end
537
+ end
538
+
539
+ class CIMInstanceSort < Comfychair::TestCase
540
+ def runtest
541
+ raise Comfychair::NotRunError
542
+ end
543
+ end
544
+
545
+ class CIMInstanceString < Comfychair::TestCase
546
+ #"""Test string representation functions for CIMInstance objects."""
547
+
548
+ def runtest
549
+
550
+ obj = CIMInstance.new('CIM_Foo', {'Name' => 'Spottyfoot',
551
+ 'Ref1' => CIMInstanceName.new('CIM_Bar')})
552
+
553
+ s = obj.to_s
554
+
555
+ self.assert_re_match('classname=CIM_Foo', s)
556
+ self.assert_(s.index('Name').nil?)
557
+ self.assert_(s.index('Ref1').nil?)
558
+
559
+ #r = repr(obj)
560
+
561
+ #self.assert_re_search('classname=\'CIM_Foo\'', r)
562
+ #self.assert_(r.find('Name') == -1)
563
+ #self.assert_(r.find('Ref1') == -1)
564
+ end
565
+ end
566
+
567
+ class CIMInstanceToXML < ValidateTest
568
+ """Test valid XML is generated for various CIMInstance objects."""
569
+
570
+ def runtest
571
+
572
+ # Simple instances, no properties
573
+
574
+ self.validate(CIMInstance.new('CIM_Foo'))
575
+
576
+ # Path
577
+
578
+ self.validate(CIMInstance.new('CIM_Foo',
579
+ {'InstanceID' => '1234'},
580
+ {},
581
+ CIMInstanceName.new('CIM_Foo',
582
+ {'InstanceID' => '1234'})))
583
+
584
+ # Multiple properties and qualifiers
585
+
586
+ self.validate(CIMInstance.new('CIM_Foo', {'Spotty' => 'Foot',
587
+ 'Age' => Uint32.new(42)},
588
+ {'Key' => CIMQualifier.new('Key', true)}))
589
+
590
+ # Test every numeric property type
591
+
592
+ [Uint8, Uint16, Uint32, Uint64, Sint8, Sint16, Sint32, Sint64,
593
+ Real32, Real64].each do |t|
594
+ self.validate(CIMInstance.new('CIM_Foo', {'Number' => t.new(42)}))
595
+ end
596
+
597
+ # Other property types
598
+
599
+ self.validate(CIMInstance.new('CIM_Foo', {'Value' => false}))
600
+
601
+ self.validate(CIMInstance.new('CIM_Foo', {'Now' => DateTime.now()}))
602
+ self.validate(CIMInstance.new('CIM_Foo', {'Now' => TimeDelta.new(60)}))
603
+
604
+ self.validate(CIMInstance.new('CIM_Foo',
605
+ {'Ref' => CIMInstanceName.new('CIM_Eep',
606
+ {'Foo' => 'Bar'})}))
607
+
608
+ # Array types. Can't have an array of references
609
+
610
+ [Uint8, Uint16, Uint32, Uint64, Sint8, Sint16, Sint32, Sint64,
611
+ Real32, Real64].each do |t|
612
+
613
+ self.validate(CIMInstance.new('CIM_Foo', {'Number' => [t.new(42), t.new(43)]}))
614
+ end
615
+
616
+ self.validate(CIMInstance.new('CIM_Foo',
617
+ {'Now' => [DateTime.now(), DateTime.now()]}))
618
+
619
+ self.validate(CIMInstance.new('CIM_Foo',
620
+ {'Then' => [TimeDelta.new(60), TimeDelta.new(61)]}))
621
+
622
+ # Null properties. Can't have a NULL property reference.
623
+
624
+ obj = CIMInstance.new('CIM_Foo')
625
+
626
+ obj.properties['Cheepy'] = CIMProperty.new('Cheepy', nil, 'string')
627
+ obj.properties['Date'] = CIMProperty.new('Date', nil, 'datetime')
628
+ obj.properties['Bool'] = CIMProperty.new('Bool', nil, 'boolean')
629
+
630
+ ['uint8', 'uint16', 'uint32', 'uint64', 'sint8', 'sint16',
631
+ 'sint32', 'sint64', 'real32', 'real64'].each do |t|
632
+ obj.properties[t] = CIMProperty.new(t, nil, t)
633
+ end
634
+ self.validate(obj)
635
+
636
+ # Null property arrays. Can't have arrays of NULL property
637
+ # references.
638
+
639
+ obj = CIMInstance.new('CIM_Foo')
640
+
641
+ obj.properties['Cheepy'] = CIMProperty.new(
642
+ 'Cheepy', nil, 'string', nil, nil, true)
643
+
644
+ obj.properties['Date'] = CIMProperty.new(
645
+ 'Date', nil, 'datetime', nil, nil, true)
646
+
647
+ obj.properties['Bool'] = CIMProperty.new(
648
+ 'Bool', nil, 'boolean', nil, nil, true)
649
+
650
+ ['uint8', 'uint16', 'uint32', 'uint64', 'sint8', 'sint16',
651
+ 'sint32', 'sint64', 'real32', 'real64'].each do |t|
652
+ obj.properties[t] = CIMProperty.new(t, nil, t, nil, nil, true)
653
+ end
654
+ self.validate(obj)
655
+ end
656
+ end
657
+ #################################################################
658
+ # CIMProperty
659
+ #################################################################
660
+
661
+
662
+ class InitCIMProperty < Comfychair::TestCase
663
+
664
+ def runtest
665
+
666
+ # Basic CIMProperty initialisations
667
+
668
+ CIMProperty.new('Spotty', 'Foot', 'string')
669
+ #CIMProperty(u'Name', u'Brad')
670
+ CIMProperty.new('Age', Uint16.new(32))
671
+ CIMProperty.new('Age', nil, 'uint16')
672
+
673
+ # Must specify a type when value is nil
674
+
675
+ begin
676
+ CIMProperty.new('Spotty', nil)
677
+ rescue TypeError
678
+ else
679
+ self.fail('TypeError not raised')
680
+ end
681
+
682
+ # Numeric types must have CIM types
683
+
684
+ begin
685
+ CIMProperty.new('Age', 42)
686
+ rescue TypeError
687
+ else
688
+ self.fail('TypeError not raised')
689
+ end
690
+
691
+ # Qualifiers
692
+
693
+ CIMProperty.new('Spotty', 'Foot', nil, nil, nil, nil,
694
+ {'Key' => CIMQualifier.new('Key', true)})
695
+
696
+ # Simple arrays
697
+
698
+ CIMProperty.new('Foo', nil, 'string')
699
+ CIMProperty.new('Foo', [1, 2, 3].collect {|x| Uint8.new(x)})
700
+ CIMProperty.new('Foo', [1, 2, 3].collect {|x| Uint8.new(x)},
701
+ nil, nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)})
702
+
703
+ # Must specify type for empty property array
704
+
705
+ begin
706
+ CIMProperty.new('Foo', [])
707
+ rescue TypeError
708
+ else
709
+ self.fail('TypeError not raised')
710
+ end
711
+
712
+ # Numeric property value arrays must be a CIM type
713
+
714
+ begin
715
+ CIMProperty.new('Foo', [1, 2, 3])
716
+ rescue TypeError
717
+ else
718
+ self.fail('TypeError not raised')
719
+ end
720
+
721
+ # Property references
722
+
723
+ CIMProperty.new('Foo', nil, type = 'reference')
724
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo'))
725
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo'),
726
+ nil, nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)})
727
+ end
728
+ end
729
+
730
+ class CopyCIMProperty < Comfychair::TestCase
731
+
732
+ def runtest
733
+
734
+ p = CIMProperty.new('Spotty', 'Foot')
735
+ c = p.clone
736
+
737
+ self.assert_equal(p, c)
738
+
739
+ c.name = '1234'
740
+ c.value = '1234'
741
+ c.qualifiers = {'Key' => CIMQualifier.new('Value', true)}
742
+
743
+ self.assert_(p.name == 'Spotty')
744
+ self.assert_(p.value == 'Foot')
745
+ self.assert_(p.qualifiers == {})
746
+ end
747
+ end
748
+
749
+ class CIMPropertyAttrs < Comfychair::TestCase
750
+
751
+ def runtest
752
+
753
+ # Attributes for single-valued property
754
+
755
+ obj = CIMProperty.new('Spotty', 'Foot', 'string')
756
+
757
+ self.assert_(obj.name == 'Spotty')
758
+ self.assert_(obj.value == 'Foot')
759
+ self.assert_(obj.prop_type == 'string')
760
+ self.assert_(obj.qualifiers == {})
761
+
762
+ # Attributes for array property
763
+
764
+ v = [1, 2, 3].collect {|x| Uint8.new(x)}
765
+
766
+ obj = CIMProperty.new('Foo', v)
767
+
768
+ self.assert_(obj.name == 'Foo')
769
+ self.assert_(obj.value == v)
770
+ self.assert_(obj.prop_type == 'uint8')
771
+ self.assert_(obj.qualifiers == {})
772
+
773
+ # Attributes for property reference
774
+
775
+ v = CIMInstanceName.new('CIM_Foo')
776
+
777
+ obj = CIMProperty.new('Foo', v, nil, nil, nil, nil, nil, 'CIM_Bar')
778
+
779
+ self.assert_(obj.name == 'Foo')
780
+ self.assert_(obj.value == v)
781
+ self.assert_(obj.prop_type == 'reference')
782
+ self.assert_(obj.reference_class == 'CIM_Bar')
783
+ self.assert_(obj.qualifiers == {})
784
+ end
785
+ end
786
+
787
+ class CIMPropertyEquality < Comfychair::TestCase
788
+
789
+ def runtest
790
+
791
+ # Compare single-valued properties
792
+
793
+ self.assert_equal(CIMProperty.new('Spotty', nil, 'string'),
794
+ CIMProperty.new('Spotty', nil, 'string'))
795
+
796
+ self.assert_equal(CIMProperty.new('Spotty', 'Foot'),
797
+ CIMProperty.new('Spotty', 'Foot'))
798
+
799
+ self.assert_notequal(CIMProperty.new('Spotty', 'Foot'),
800
+ CIMProperty.new('Spotty', Uint32.new(42)))
801
+
802
+ self.assert_equal(CIMProperty.new('Spotty', 'Foot'),
803
+ CIMProperty.new('spotty', 'Foot'))
804
+
805
+ self.assert_notequal(CIMProperty.new('Spotty', 'Foot'),
806
+ CIMProperty.new('Spotty', 'Foot',
807
+ nil, nil, nil, nil,
808
+ {'Key' =>
809
+ CIMQualifier.new('Key', true)}))
810
+
811
+ # Compare property arrays
812
+
813
+ self.assert_equal(
814
+ CIMProperty.new('Array', nil, 'uint8', nil, nil, true),
815
+ CIMProperty.new('array', nil, 'uint8', nil, nil, true))
816
+
817
+ self.assert_equal(
818
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint8.new(x)}),
819
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint8.new(x)}))
820
+
821
+ self.assert_notequal(
822
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint8.new(x)}),
823
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint16.new(x)}))
824
+
825
+ self.assert_notequal(
826
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint8.new(x)}),
827
+ CIMProperty.new('Array', [1, 2, 3].collect {|x| Uint16.new(x)},
828
+ nil, nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)}))
829
+
830
+ # Compare property references
831
+
832
+ self.assert_equal(
833
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')),
834
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')))
835
+
836
+ self.assert_equal(
837
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')),
838
+ CIMProperty.new('foo', CIMInstanceName.new('CIM_Foo')))
839
+
840
+ self.assert_notequal(
841
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')),
842
+ CIMProperty.new('foo', nil, 'reference'))
843
+
844
+ self.assert_notequal(
845
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')),
846
+ CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo'),
847
+ nil, nil, nil, nil,
848
+ {'Key' => CIMQualifier.new('Key', true)}))
849
+ end
850
+ end
851
+
852
+ class CIMPropertyCompare < Comfychair::TestCase
853
+ def runtest
854
+ raise Comfychair::NotRunError
855
+ end
856
+ end
857
+
858
+ class CIMPropertySort < Comfychair::TestCase
859
+ def runtest
860
+ raise Comfychair::NotRunError
861
+ end
862
+ end
863
+
864
+ class CIMPropertyString < Comfychair::TestCase
865
+
866
+ def runtest
867
+
868
+ r = CIMProperty.new('Spotty', 'Foot', 'string').to_s
869
+
870
+ self.assert_re_match('^WBEM::CIMProperty', r)
871
+ end
872
+ end
873
+
874
+ class CIMPropertyToXML < ValidateTest
875
+ #"""Test valid XML is generated for various CIMProperty objects."""
876
+
877
+ def runtest
878
+
879
+ # Single-valued properties
880
+
881
+ self.validate(CIMProperty.new('Spotty', nil, 'string'))
882
+ #self.validate(CIMProperty.new(u'Name', u'Brad'))
883
+ self.validate(CIMProperty.new('Age', Uint16.new(32)))
884
+ self.validate(CIMProperty.new('Age', Uint16.new(32),
885
+ nil, nil, nil, nil,
886
+ {'Key' => CIMQualifier.new('Key', true)}))
887
+
888
+ # Array properties
889
+
890
+ self.validate(CIMProperty.new('Foo', nil, 'string', nil, nil, true))
891
+ self.validate(CIMProperty.new('Foo', [], 'string'))
892
+ self.validate(CIMProperty.new('Foo', [1, 2, 3].collect {|x| Uint8.new(x)}))
893
+
894
+ self.validate(CIMProperty.new(
895
+ 'Foo', [1, 2, 3].collect {|x| Uint8.new(x)},
896
+ nil, nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)}))
897
+
898
+ # Reference properties
899
+
900
+ self.validate(CIMProperty.new('Foo', nil, 'reference'))
901
+ self.validate(CIMProperty.new('Foo', CIMInstanceName.new('CIM_Foo')))
902
+
903
+ self.validate(CIMProperty.new(
904
+ 'Foo',
905
+ CIMInstanceName.new('CIM_Foo'),
906
+ nil, nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)}))
907
+ end
908
+ end
909
+
910
+ #################################################################
911
+ # CIMQualifier
912
+ #################################################################
913
+
914
+ class InitCIMQualifier < Comfychair::TestCase
915
+ #"""Test initialising a CIMQualifier object."""
916
+
917
+ def runtest
918
+
919
+ CIMQualifier.new('Revision', '2.7.0', 'string')
920
+ CIMQualifier.new('RevisionList', ['1', '2', '3'], false)
921
+ end
922
+ end
923
+
924
+ class CopyCIMQualifier < Comfychair::TestCase
925
+
926
+ def runtest
927
+
928
+ q = CIMQualifier.new('Revision', '2.7.0', 'string')
929
+ c = q.clone
930
+
931
+ self.assert_equal(q, c)
932
+
933
+ c.name = 'Fooble'
934
+ c.value = 'eep'
935
+
936
+ self.assert_(q.name == 'Revision')
937
+ end
938
+ end
939
+
940
+ class CIMQualifierAttrs < Comfychair::TestCase
941
+ #"""Test attributes of CIMQualifier object."""
942
+
943
+ def runtest
944
+
945
+ q = CIMQualifier.new('Revision', '2.7.0')
946
+
947
+ self.assert_equal(q.name, 'Revision')
948
+ self.assert_equal(q.value, '2.7.0')
949
+
950
+ self.assert_equal(q.propagated, nil)
951
+ self.assert_equal(q.overridable, nil)
952
+ self.assert_equal(q.tosubclass, nil)
953
+ self.assert_equal(q.toinstance, nil)
954
+ self.assert_equal(q.translatable, nil)
955
+
956
+ q = CIMQualifier.new('RevisionList', ['1', '2', '3'], false)
957
+
958
+ self.assert_equal(q.name, 'RevisionList')
959
+ self.assert_equal(q.value, ['1', '2', '3'])
960
+ self.assert_equal(q.propagated, false)
961
+ end
962
+ end
963
+
964
+ class CIMQualifierEquality < Comfychair::TestCase
965
+ #"""Compare CIMQualifier objects."""
966
+
967
+ def runtest
968
+
969
+ self.assert_equal(CIMQualifier.new('Spotty', 'Foot'),
970
+ CIMQualifier.new('Spotty', 'Foot'))
971
+
972
+ self.assert_equal(CIMQualifier.new('Spotty', 'Foot'),
973
+ CIMQualifier.new('spotty', 'Foot'))
974
+
975
+ self.assert_notequal(CIMQualifier.new('Spotty', 'Foot'),
976
+ CIMQualifier.new('Spotty', 'foot'))
977
+ end
978
+ end
979
+
980
+ class CIMQualifierCompare < Comfychair::TestCase
981
+ def runtest
982
+ raise Comfychair::NotRunError
983
+ end
984
+ end
985
+
986
+ class CIMQualifierSort < Comfychair::TestCase
987
+ def runtest
988
+ raise Comfychair::NotRunError
989
+ end
990
+ end
991
+
992
+ class CIMQualifierString < Comfychair::TestCase
993
+
994
+ def runtest
995
+ s = CIMQualifier.new('RevisionList', ['1', '2', '3'], false).to_s
996
+ self.assert_re_match('RevisionList', s)
997
+ end
998
+ end
999
+
1000
+ class CIMQualifierToXML < ValidateTest
1001
+
1002
+ def runtest
1003
+
1004
+ self.validate(CIMQualifier.new('Spotty', 'Foot'))
1005
+ self.validate(CIMQualifier.new('Revision', Real32.new(2.7)))
1006
+
1007
+ self.validate(CIMQualifier.new('RevisionList',
1008
+ [1, 2, 3].collect { |x| Uint16.new(x)},
1009
+ false))
1010
+ end
1011
+ end
1012
+
1013
+ #################################################################
1014
+ # CIMClass
1015
+ #################################################################
1016
+
1017
+ class InitCIMClass < Comfychair::TestCase
1018
+
1019
+ def runtest
1020
+
1021
+ # Initialise with classname, superclass
1022
+
1023
+ CIMClass.new('CIM_Foo')
1024
+ CIMClass.new('CIM_Foo', nil, nil, nil, 'CIM_Bar')
1025
+
1026
+ # Initialise with properties
1027
+
1028
+ CIMClass.new('CIM_Foo', {'InstanceID' => CIMProperty.new('InstanceID', nil, 'string')})
1029
+
1030
+ # Initialise with methods
1031
+
1032
+ CIMClass.new('CIM_Foo', nil, nil, {'Delete' => CIMMethod.new('Delete')})
1033
+
1034
+ # Initialise with qualifiers
1035
+
1036
+ CIMClass.new('CIM_Foo', nil, {'Key' => CIMQualifier.new('Key', true)})
1037
+ end
1038
+ end
1039
+
1040
+ class CopyCIMClass < Comfychair::TestCase
1041
+
1042
+ def runtest
1043
+
1044
+ c = CIMClass.new('CIM_Foo',
1045
+ {},
1046
+ {'Key' => CIMQualifier.new('Value', true)},
1047
+ {'Delete' => CIMMethod.new('Delete')})
1048
+
1049
+ co = c.clone
1050
+
1051
+ self.assert_equal(c, co)
1052
+
1053
+ co.classname = 'CIM_Bar'
1054
+ co.cim_methods.delete('Delete')
1055
+ co.qualifiers.delete('Key')
1056
+
1057
+ self.assert_(c.classname == 'CIM_Foo')
1058
+ self.assert_(c.cim_methods['Delete'])
1059
+ self.assert_(c.qualifiers['Key'])
1060
+ end
1061
+ end
1062
+
1063
+ class CIMClassAttrs < Comfychair::TestCase
1064
+
1065
+ def runtest
1066
+
1067
+ obj = CIMClass.new('CIM_Foo', nil, nil, nil, 'CIM_Bar')
1068
+
1069
+ self.assert_(obj.classname == 'CIM_Foo')
1070
+ self.assert_(obj.superclass == 'CIM_Bar')
1071
+ self.assert_(obj.properties == {})
1072
+ self.assert_(obj.qualifiers == {})
1073
+ self.assert_(obj.cim_methods == {})
1074
+ self.assert_(obj.qualifiers == {})
1075
+ end
1076
+ end
1077
+
1078
+ class CIMClassEquality < Comfychair::TestCase
1079
+
1080
+ def runtest
1081
+
1082
+ self.assert_equal(CIMClass.new('CIM_Foo'), CIMClass.new('CIM_Foo'))
1083
+ self.assert_equal(CIMClass.new('CIM_Foo'), CIMClass.new('cim_foo'))
1084
+
1085
+ self.assert_notequal(CIMClass.new('CIM_Foo', nil, nil, nil, 'CIM_Bar'),
1086
+ CIMClass.new('CIM_Foo'))
1087
+
1088
+ properties = {'InstanceID' => CIMProperty.new('InstanceID', nil, 'string')}
1089
+
1090
+ methods = {'Delete' => CIMMethod.new('Delete')}
1091
+
1092
+ qualifiers = {'Key' => CIMQualifier.new('Key', true)}
1093
+
1094
+ self.assert_notequal(CIMClass.new('CIM_Foo'),
1095
+ CIMClass.new('CIM_Foo', properties))
1096
+
1097
+ self.assert_notequal(CIMClass.new('CIM_Foo'),
1098
+ CIMClass.new('CIM_Foo', nil, nil, methods))
1099
+
1100
+ self.assert_notequal(CIMClass.new('CIM_Foo'),
1101
+ CIMClass.new('CIM_Foo', nil, qualifiers))
1102
+ end
1103
+ end
1104
+
1105
+ class CIMClassCompare < Comfychair::TestCase
1106
+ def runtest
1107
+ raise Comfychair::NotRunError
1108
+ end
1109
+ end
1110
+
1111
+ class CIMClassSort < Comfychair::TestCase
1112
+ def runtest
1113
+ raise Comfychair::NotRunError
1114
+ end
1115
+ end
1116
+
1117
+ class CIMClassString < Comfychair::TestCase
1118
+
1119
+ def runtest
1120
+
1121
+ s = CIMClass.new('CIM_Foo').to_s
1122
+ self.assert_re_match('CIM_Foo', s)
1123
+ end
1124
+ end
1125
+
1126
+ class CIMClassToXML < ValidateTest
1127
+
1128
+ def runtest
1129
+
1130
+ self.validate(CIMClass.new('CIM_Foo'))
1131
+ self.validate(CIMClass.new('CIM_Foo', nil, nil, nil, 'CIM_Bar'))
1132
+
1133
+ self.validate(
1134
+ CIMClass.new(
1135
+ 'CIM_Foo',
1136
+ {'InstanceID' => CIMProperty.new('InstanceID', nil, 'string')}))
1137
+
1138
+ self.validate(
1139
+ CIMClass.new(
1140
+ 'CIM_Foo',
1141
+ nil, nil, {'Delete' => CIMMethod.new('Delete')}))
1142
+
1143
+
1144
+ self.validate(
1145
+ CIMClass.new(
1146
+ 'CIM_Foo',
1147
+ nil, {'Key' => CIMQualifier.new('Key', true)}))
1148
+ end
1149
+ end
1150
+
1151
+ #################################################################
1152
+ # CIMMethod
1153
+ #################################################################
1154
+
1155
+ class InitCIMMethod < Comfychair::TestCase
1156
+
1157
+ def runtest
1158
+
1159
+ CIMMethod.new('FooMethod', 'uint32')
1160
+
1161
+ CIMMethod.new('FooMethod', 'uint32',
1162
+ {'Param1' => CIMParameter.new('Param1', 'uint32'),
1163
+ 'Param2' => CIMParameter.new('Param2', 'string')})
1164
+
1165
+ CIMMethod.new('FooMethod', 'uint32',
1166
+ {'Param1' => CIMParameter.new('Param1', 'uint32'),
1167
+ 'Param2' => CIMParameter.new('Param2', 'string')},
1168
+ nil, false, {'Key' => CIMQualifier.new('Key', true)})
1169
+ end
1170
+ end
1171
+
1172
+ class CopyCIMMethod < Comfychair::TestCase
1173
+
1174
+ def runtest
1175
+
1176
+ m = CIMMethod.new('FooMethod', 'uint32',
1177
+ {'P1' => CIMParameter.new('P1', 'uint32'),
1178
+ 'P2' => CIMParameter.new('P2', 'string')},
1179
+ nil, nil,
1180
+ {'Key' => CIMQualifier.new('Key', true)})
1181
+
1182
+ c = m.clone
1183
+
1184
+ self.assert_equal(m, c)
1185
+
1186
+ c.name = 'BarMethod'
1187
+ c.return_type = 'string'
1188
+ c.parameters.delete('P1')
1189
+ c.qualifiers.delete('Key')
1190
+
1191
+ self.assert_(m.name == 'FooMethod')
1192
+ self.assert_(m.return_type == 'uint32')
1193
+ self.assert_(m.parameters['P1'])
1194
+ self.assert_(m.qualifiers['Key'])
1195
+ end
1196
+ end
1197
+
1198
+ class CIMMethodAttrs < Comfychair::TestCase
1199
+
1200
+ def runtest
1201
+
1202
+ m = CIMMethod.new('FooMethod', 'uint32',
1203
+ {'Param1' => CIMParameter.new('Param1', 'uint32'),
1204
+ 'Param2' => CIMParameter.new('Param2', 'string')}
1205
+ )
1206
+
1207
+ self.assert_(m.name == 'FooMethod')
1208
+ self.assert_(m.return_type == 'uint32')
1209
+ self.assert_(m.parameters.length == 2)
1210
+ self.assert_(m.qualifiers == {})
1211
+ end
1212
+ end
1213
+
1214
+ class CIMMethodEquality < Comfychair::TestCase
1215
+
1216
+ def runtest
1217
+
1218
+ self.assert_equal(CIMMethod.new('FooMethod', 'uint32'),
1219
+ CIMMethod.new('FooMethod', 'uint32'))
1220
+
1221
+ self.assert_equal(CIMMethod.new('FooMethod', 'uint32'),
1222
+ CIMMethod.new('fooMethod', 'uint32'))
1223
+
1224
+ self.assert_notequal(CIMMethod.new('FooMethod', 'uint32'),
1225
+ CIMMethod.new('FooMethod', 'uint32',
1226
+ nil, nil, nil,
1227
+ {'Key' => CIMQualifier.new('Key', true)}))
1228
+ end
1229
+ end
1230
+
1231
+ class CIMMethodCompare < Comfychair::TestCase
1232
+ def runtest
1233
+ raise Comfychair::NotRunError
1234
+ end
1235
+ end
1236
+
1237
+ class CIMMethodSort < Comfychair::TestCase
1238
+ def runtest
1239
+ raise Comfychair::NotRunError
1240
+ end
1241
+ end
1242
+
1243
+ class CIMMethodString < Comfychair::TestCase
1244
+
1245
+ def runtest
1246
+
1247
+ s = CIMMethod.new('FooMethod', 'uint32').to_s
1248
+
1249
+ self.assert_re_match('FooMethod', s)
1250
+ self.assert_re_match('uint32', s)
1251
+ end
1252
+ end
1253
+
1254
+ class CIMMethodToXML < ValidateTest
1255
+
1256
+ def runtest
1257
+
1258
+ self.validate(CIMMethod.new('FooMethod', 'uint32'))
1259
+
1260
+ self.validate(
1261
+ CIMMethod.new('FooMethod', 'uint32',
1262
+ {'Param1' => CIMParameter.new('Param1', 'uint32'),
1263
+ 'Param2' => CIMParameter.new('Param2', 'string')},
1264
+ nil, false,
1265
+ {'Key' => CIMQualifier.new('Key', true)}))
1266
+ end
1267
+ end
1268
+
1269
+ #################################################################
1270
+ # CIMParameter
1271
+ #################################################################
1272
+
1273
+ class InitCIMParameter < Comfychair::TestCase
1274
+
1275
+ def runtest
1276
+
1277
+ # Single-valued parameters
1278
+
1279
+ CIMParameter.new('Param1', 'uint32')
1280
+ CIMParameter.new('Param2', 'string')
1281
+ CIMParameter.new('Param2', 'string',
1282
+ nil, nil, nil, {'Key' => CIMQualifier.new('Key', true)})
1283
+
1284
+ # Array parameters
1285
+
1286
+ CIMParameter.new('ArrayParam', 'uint32', nil, true)
1287
+ CIMParameter.new('ArrayParam', 'uint32', nil, true, 10)
1288
+ CIMParameter.new('ArrayParam', 'uint32', nil, true, 10,
1289
+ {'Key' => CIMQualifier.new('Key', true)})
1290
+
1291
+ # Reference parameters
1292
+
1293
+ CIMParameter.new('RefParam', 'reference', 'CIM_Foo')
1294
+ CIMParameter.new('RefParam', 'reference', 'CIM_Foo',
1295
+ nil, nil, {'Key' => CIMQualifier.new('Key', true)})
1296
+
1297
+ # Refarray parameters
1298
+
1299
+ CIMParameter.new('RefArrayParam', 'reference', true)
1300
+ CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true)
1301
+ CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true, 10)
1302
+ CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true, 10,
1303
+ {'Key' => CIMQualifier.new('Key', true)})
1304
+ end
1305
+ end
1306
+
1307
+ class CopyCIMParameter < Comfychair::TestCase
1308
+
1309
+ def runtest
1310
+
1311
+ p = CIMParameter.new('RefParam', 'reference', 'CIM_Foo', nil, nil,
1312
+ {'Key' => CIMQualifier.new('Key', true)})
1313
+
1314
+ c = p.clone
1315
+
1316
+ self.assert_equal(p, c)
1317
+
1318
+ c.name = 'Fooble'
1319
+ c.param_type = 'string'
1320
+ c.reference_class = nil
1321
+ c.qualifiers.delete('Key')
1322
+
1323
+ self.assert_(p.name == 'RefParam')
1324
+ self.assert_(p.param_type == 'reference')
1325
+ self.assert_(p.reference_class == 'CIM_Foo')
1326
+ self.assert_(p.qualifiers['Key'])
1327
+ end
1328
+ end
1329
+
1330
+ class CIMParameterAttrs < Comfychair::TestCase
1331
+
1332
+ def runtest
1333
+
1334
+ # Single-valued parameters
1335
+
1336
+ p = CIMParameter.new('Param1', 'string')
1337
+
1338
+ self.assert_(p.name == 'Param1')
1339
+ self.assert_(p.param_type == 'string')
1340
+ self.assert_(p.qualifiers == {})
1341
+
1342
+ # Array parameters
1343
+
1344
+ p = CIMParameter.new('ArrayParam', 'uint32', nil, true)
1345
+
1346
+ self.assert_(p.name == 'ArrayParam')
1347
+ self.assert_(p.param_type == 'uint32')
1348
+ self.assert_(p.array_size == nil)
1349
+ self.assert_(p.qualifiers == {})
1350
+
1351
+ # Reference parameters
1352
+
1353
+ p = CIMParameter.new('RefParam', 'reference', 'CIM_Foo')
1354
+
1355
+ self.assert_(p.name == 'RefParam')
1356
+ self.assert_(p.reference_class == 'CIM_Foo')
1357
+ self.assert_(p.qualifiers == {})
1358
+
1359
+ # Reference array parameters
1360
+
1361
+ p = CIMParameter.new('RefArrayParam', 'reference',
1362
+ 'CIM_Foo', true, 10)
1363
+
1364
+ self.assert_(p.name == 'RefArrayParam')
1365
+ self.assert_(p.reference_class == 'CIM_Foo')
1366
+ self.assert_(p.array_size == 10)
1367
+ self.assert_(p.is_array == true)
1368
+ self.assert_(p.qualifiers == {})
1369
+ end
1370
+ end
1371
+
1372
+ class CIMParameterEquality < Comfychair::TestCase
1373
+ def runtest
1374
+
1375
+ # Single-valued parameters
1376
+ self.assert_equal(CIMParameter.new('Param1', 'uint32'),
1377
+ CIMParameter.new('Param1', 'uint32'))
1378
+
1379
+ self.assert_equal(CIMParameter.new('Param1', 'uint32'),
1380
+ CIMParameter.new('param1', 'uint32'))
1381
+
1382
+ self.assert_notequal(CIMParameter.new('Param1', 'uint32'),
1383
+ CIMParameter.new('param1', 'string'))
1384
+
1385
+ self.assert_notequal(CIMParameter.new('Param1', 'uint32'),
1386
+ CIMParameter.new('param1', 'uint32',
1387
+ nil, nil, nil,
1388
+ {'Key' => CIMQualifier.new('Key', true)}))
1389
+
1390
+ # Array parameters
1391
+ self.assert_equal(CIMParameter.new('ArrayParam', 'uint32', nil, true),
1392
+ CIMParameter.new('ArrayParam', 'uint32', nil, true))
1393
+
1394
+ self.assert_equal(CIMParameter.new('ArrayParam', 'uint32', nil, true),
1395
+ CIMParameter.new('arrayParam', 'uint32', nil, true))
1396
+
1397
+ self.assert_notequal(CIMParameter.new('ArrayParam', 'uint32', nil, true),
1398
+ CIMParameter.new('ArrayParam', 'string', nil, true))
1399
+
1400
+ self.assert_notequal(CIMParameter.new('ArrayParam', 'uint32', nil, true),
1401
+ CIMParameter.new('ArrayParam', 'string', nil, true, 10))
1402
+
1403
+ self.assert_notequal(CIMParameter.new('ArrayParam', 'uint32', nil, true),
1404
+ CIMParameter.new('ArrayParam', 'uint32', nil, true, nil,
1405
+ {'Key' => CIMQualifier.new('Key', true)}))
1406
+
1407
+ # Reference parameters
1408
+ self.assert_equal(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'),
1409
+ CIMParameter.new('RefParam', 'reference', 'CIM_Foo'))
1410
+
1411
+ self.assert_equal(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'),
1412
+ CIMParameter.new('refParam', 'reference', 'CIM_Foo'))
1413
+
1414
+ self.assert_equal(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'),
1415
+ CIMParameter.new('refParam', 'reference', 'CIM_foo'))
1416
+
1417
+ self.assert_notequal(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'),
1418
+ CIMParameter.new('RefParam', 'reference', 'CIM_Bar'))
1419
+
1420
+ self.assert_notequal(CIMParameter.new('RefParam', 'reference', 'CIM_Foo'),
1421
+ CIMParameter.new('RefParam', 'reference', 'CIM_Foo',
1422
+ nil, nil,
1423
+ {'Key' => CIMQualifier.new('Key', true)}))
1424
+
1425
+ # Reference array parameters
1426
+ self.assert_equal(CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo', true),
1427
+ CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo', true))
1428
+
1429
+ self.assert_equal(CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo', true),
1430
+ CIMParameter.new('arrayparam', 'reference', 'CIM_Foo', true))
1431
+
1432
+ self.assert_notequal(CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo',
1433
+ true),
1434
+ CIMParameter.new('arrayParam', 'reference', 'CIM_foo',
1435
+ true, 10))
1436
+
1437
+ self.assert_notequal(CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo',
1438
+ true),
1439
+ CIMParameter.new('ArrayParam', 'reference', 'CIM_Foo',
1440
+ true, nil,
1441
+ {'Key' => CIMQualifier.new('Key', true)}))
1442
+ end
1443
+ end
1444
+
1445
+ class CIMParameterCompare < Comfychair::TestCase
1446
+ def runtest
1447
+ raise Comfychair::NotRunError
1448
+ end
1449
+ end
1450
+
1451
+ class CIMParameterSort < Comfychair::TestCase
1452
+ def runtest
1453
+ raise Comfychair::NotRunError
1454
+ end
1455
+ end
1456
+
1457
+ class CIMParameterString < Comfychair::TestCase
1458
+
1459
+ def runtest
1460
+
1461
+ s = CIMParameter.new('Param1', 'uint32').to_s
1462
+
1463
+ self.assert_re_match('Param1', s)
1464
+ self.assert_re_match('uint32', s)
1465
+ end
1466
+ end
1467
+
1468
+ class CIMParameterToXML < ValidateTest
1469
+
1470
+ def runtest
1471
+
1472
+ # Single-valued parameters
1473
+
1474
+ self.validate(CIMParameter.new('Param1', 'uint32'))
1475
+
1476
+ self.validate(CIMParameter.new('Param1', 'string', nil, nil, nil,
1477
+ {'Key' => CIMQualifier.new('Key', true)}))
1478
+
1479
+ # Array parameters
1480
+
1481
+ self.validate(CIMParameter.new('ArrayParam', 'uint32', nil, true))
1482
+
1483
+ self.validate(CIMParameter.new('ArrayParam', 'uint32', nil, true, 10))
1484
+
1485
+ self.validate(CIMParameter.new('ArrayParam', 'uint32', nil, true, 10,
1486
+ {'Key' => CIMQualifier.new('Key', true)}))
1487
+
1488
+ # Reference parameters
1489
+
1490
+ self.validate(CIMParameter.new('RefParam', 'reference', 'CIM_Foo',
1491
+ nil, nil, {'Key' => CIMQualifier.new('Key', true)}))
1492
+
1493
+ # Reference array parameters
1494
+
1495
+ self.validate(CIMParameter.new('RefArrayParam', 'reference', nil, true))
1496
+
1497
+ self.validate(CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true))
1498
+
1499
+ self.validate(CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true, 10))
1500
+
1501
+ self.validate(CIMParameter.new('RefArrayParam', 'reference', 'CIM_Foo', true,
1502
+ nil, {'Key' => CIMQualifier.new('Key', true)}))
1503
+ end
1504
+ end
1505
+
1506
+ #################################################################
1507
+ # Main function
1508
+ #################################################################
1509
+
1510
+
1511
+ TESTS = [
1512
+ #############################################################
1513
+ # Property and qualifier classes
1514
+ #############################################################
1515
+
1516
+ # CIMProperty
1517
+
1518
+ InitCIMProperty,
1519
+ CopyCIMProperty,
1520
+ CIMPropertyAttrs,
1521
+ CIMPropertyEquality,
1522
+ CIMPropertyCompare,
1523
+ CIMPropertySort,
1524
+ CIMPropertyString,
1525
+ CIMPropertyToXML,
1526
+
1527
+ # CIMQualifier
1528
+
1529
+ InitCIMQualifier,
1530
+ CopyCIMQualifier,
1531
+ CIMQualifierAttrs,
1532
+ CIMQualifierEquality,
1533
+ CIMQualifierCompare,
1534
+ CIMQualifierSort,
1535
+ CIMQualifierString,
1536
+ CIMQualifierToXML,
1537
+
1538
+ #############################################################
1539
+ # Instance and instance name classes
1540
+ #############################################################
1541
+
1542
+ # CIMInstanceName
1543
+
1544
+ InitCIMInstanceName,
1545
+ CopyCIMInstanceName,
1546
+ CIMInstanceNameAttrs,
1547
+ CIMInstanceNameDictInterface,
1548
+ CIMInstanceNameEquality,
1549
+ CIMInstanceNameCompare,
1550
+ CIMInstanceNameSort,
1551
+ CIMInstanceNameString,
1552
+ CIMInstanceNameToXML,
1553
+
1554
+ # CIMInstance
1555
+
1556
+ InitCIMInstance,
1557
+ CopyCIMInstance,
1558
+ CIMInstanceAttrs,
1559
+ CIMInstanceDictInterface,
1560
+ CIMInstanceEquality,
1561
+ CIMInstanceCompare,
1562
+ CIMInstanceSort,
1563
+ CIMInstanceString,
1564
+ CIMInstanceToXML,
1565
+
1566
+ #############################################################
1567
+ # Schema classes
1568
+ #############################################################
1569
+
1570
+ # CIMClass
1571
+
1572
+ InitCIMClass,
1573
+ CopyCIMClass,
1574
+ CIMClassAttrs,
1575
+ CIMClassEquality,
1576
+ CIMClassCompare,
1577
+ CIMClassSort,
1578
+ CIMClassString,
1579
+ CIMClassToXML,
1580
+
1581
+ # CIMMethod
1582
+
1583
+ InitCIMMethod,
1584
+ CopyCIMMethod,
1585
+ CIMMethodAttrs,
1586
+ CIMMethodEquality,
1587
+ CIMMethodCompare,
1588
+ CIMMethodSort,
1589
+ CIMMethodString,
1590
+ CIMMethodToXML,
1591
+
1592
+ # CIMParameter
1593
+
1594
+ InitCIMParameter,
1595
+ CopyCIMParameter,
1596
+ CIMParameterAttrs,
1597
+ CIMParameterEquality,
1598
+ CIMParameterCompare,
1599
+ CIMParameterSort,
1600
+ CIMParameterString,
1601
+ CIMParameterToXML
1602
+
1603
+ ]
1604
+
1605
+ if __FILE__ == $0
1606
+ Comfychair.main(TESTS)
1607
+ end
1608
+ end
1609
+ end
1610
+