-
Notifications
You must be signed in to change notification settings - Fork 138
/
gdbmhash.t
454 lines (395 loc) · 9.25 KB
/
gdbmhash.t
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#! perl
# Copyright (C) 2005-2007, The Perl Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Test;
use Parrot::Config;
=head1 NAME
t/dynpmc/gdbmhash.t - test the GDBMHash PMC
=head1 SYNOPSIS
% perl -Ilib t/dynpmc/gdbmhash.t
=head1 DESCRIPTION
Tests the C<GDBMHash> PMC.
=cut
if ( $PConfig{has_gdbm} ) {
plan tests => 13;
}
else {
plan skip_all => "No gdbm library available";
}
# PIR fragment for setting up a GDBM Hash
my $new_hash_1 = << 'CODE';
.sub test :main
.local pmc gdbmhash_lib
gdbmhash_lib = loadlib "gdbmhash"
.local pmc hash_1
hash_1 = new "GDBMHash"
CODE
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "typeof" );
.local string type
type = typeof hash_1
print type
print "\n"
.end
CODE
GDBMHash
OUTPUT
unlink('gdbm_hash_1');
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "check whether interface is done" );
.local int bool1
does bool1, hash_1, "scalar"
print bool1
print "\n"
does bool1, hash_1, "hash"
print bool1
print "\n"
does bool1, hash_1, "no_interface"
print bool1
print "\n"
.end
CODE
0
1
0
OUTPUT
unlink('gdbm_hash_1');
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "get_integer" );
.local int hash_size
hash_size = hash_1
print "An unitialized GDBMHash has size "
print hash_size
print ".\n"
hash_1 = "gdbm_hash_1"
hash_size = hash_1
print "An GDBMHash for a new file has size "
print hash_size
print ".\n"
hash_1["key1"] = "val1"
hash_size = hash_1
print "After one assignment GDBMHash has size "
print hash_size
print ".\n"
hash_1["key2"] = "val2"
hash_size = hash_1
print "After two assignments GDBMHash has size "
print hash_size
print ".\n"
hash_1["key3"] = "val3"
hash_1["key4"] = "val4"
hash_1["key5"] = "val5"
hash_1["key6"] = "val6"
hash_1["key7"] = "val7"
hash_1["key8"] = "val8"
hash_1["key9"] = "val9"
hash_1["key10"] = "val10"
hash_1["key11"] = "val11"
hash_1["key12"] = "val12"
hash_1["key13"] = "val13"
hash_1["key14"] = "val14"
hash_1["key15"] = "val15"
hash_size = hash_1
print "After 15 assignments GDBMHash has size "
print hash_size
print ".\n"
.end
CODE
An unitialized GDBMHash has size 0.
An GDBMHash for a new file has size 0.
After one assignment GDBMHash has size 1.
After two assignments GDBMHash has size 2.
After 15 assignments GDBMHash has size 15.
OUTPUT
unlink('gdbm_hash_1');
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "get_bool" );
print "An uninitialized GDBMHash is"
if hash_1 goto HASH1_IS_1
print " not"
HASH1_IS_1:
print ".\n"
hash_1 = "gdbm_hash_1"
print "An GDBMHash for a new file is"
if hash_1 goto HASH1_IS_2
print " not"
HASH1_IS_2:
print ".\n"
hash_1["key1"] = "val1"
print "After one insert the GDBMHash is"
if hash_1 goto HASH1_IS_3
print " not"
HASH1_IS_3:
print ".\n"
.end
CODE
An uninitialized GDBMHash is not.
An GDBMHash for a new file is not.
After one insert the GDBMHash is.
OUTPUT
unlink('gdbm_hash_1');
# The value is a STRING, with umlaut
# The key used for insertion is a STRING.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "modify an entry" );
hash_1 = "gdbm_hash_1"
.local pmc val_pmc
hash_1["Schluessel"] = "Wert urspruenglich\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
hash_1["Schluessel"] = "Wert geaendert\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
hash_1["Schluessel"] = "Wert nocheinmal geaendert\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
hash_1["Schluessel"] = "Wert urspruenglich\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
.end
CODE
Wert urspruenglich
Wert geaendert
Wert nocheinmal geaendert
Wert urspruenglich
OUTPUT
unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a STRING.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "exists_keyed" );
hash_1 = "gdbm_hash_1"
hash_1["Schluessel"] = "Wert\n"
.local int exist_flag
exist_flag = exists hash_1["a"]
print exist_flag
print "\n"
exist_flag = exists hash_1["Schluessel"]
print exist_flag
print "\n"
.local pmc key_out
key_out = new 'String'
key_out = "b"
exist_flag = exists hash_1[key_out]
print exist_flag
print "\n"
key_out = "Schluessel"
exist_flag = exists hash_1[key_out]
print exist_flag
print "\n"
.end
CODE
0
1
0
1
OUTPUT
unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a STRING.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set STRING with STRING key" );
hash_1 = "gdbm_hash_1"
hash_1["Schluessel"] = "Wert\n"
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
val_pmc = hash_1["Schluessel"]
print val_pmc
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
print val_string
val_pmc = hash_1[key_out]
print val_pmc
.end
CODE
Wert
Wert
Wert
Wert
OUTPUT
unlink('gdbm_hash_1');
# The value is a STRING.
# The key used for insertion is a PMC.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set STRING with a PMC key" );
hash_1 = "gdbm_hash_1"
.local pmc key_pmc
key_pmc = new 'String'
key_pmc = "Schluessel"
hash_1[key_pmc] = "Wert\n"
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
val_pmc = hash_1["Schluessel"]
print val_pmc
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
print val_string
val_pmc = hash_1[key2]
print val_pmc
.end
CODE
Wert
Wert
Wert
Wert
OUTPUT
unlink('gdbm_hash_1');
# The value is a PMC.
# The key used for insertion is a STRING.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set PMC with STRING key" );
hash_1 = "gdbm_hash_1"
.local pmc val
val = new 'String'
val = "Wert\n"
hash_1["Schluessel"] = val
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
val_pmc = hash_1["Schluessel"]
print val_pmc
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
print val_string
val_pmc = hash_1[key_out]
print val_pmc
.end
CODE
Wert
Wert
Wert
Wert
OUTPUT
unlink('gdbm_hash_1');
# The value is a PMC.
# The key used for insertion is a PMC.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set PMC with a PMC key" );
hash_1 = "gdbm_hash_1"
.local pmc val
val = new 'String'
val = "Wert\n"
.local pmc key_pmc
key_pmc = new 'String'
key_pmc = "Schluessel"
hash_1[key_pmc] = val
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
val_pmc = hash_1["Schluessel"]
print val_pmc
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
print val_string
val_pmc = hash_1[key2]
print val_pmc
.end
CODE
Wert
Wert
Wert
Wert
OUTPUT
unlink('gdbm_hash_1');
# The value is an INTVAL
# The key used for insertion is a STRING.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set INTVAL with STRING key" );
hash_1 = "gdbm_hash_1"
hash_1["Schluessel"] = -11012005
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
print "\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
print "\n"
.local pmc key_out
key_out = new 'String'
key_out = "Schluessel"
val_string = hash_1[key_out]
print val_string
print "\n"
val_pmc = hash_1[key_out]
print val_pmc
print "\n"
.end
CODE
-11012005
-11012005
-11012005
-11012005
OUTPUT
unlink('gdbm_hash_1');
# The value is a FLOATVAL.
# The key used for insertion is a PMC.
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "set FLOATVAL with a PMC key" );
hash_1 = "gdbm_hash_1"
.local pmc key_pmc
key_pmc = new 'String'
key_pmc = "Schluessel"
hash_1[key_pmc] = -1101.2005
.local pmc val_pmc
.local string val_string
val_string = hash_1["Schluessel"]
print val_string
print "\n"
val_pmc = hash_1["Schluessel"]
print val_pmc
print "\n"
.local pmc key2
key2 = new 'String'
key2 = "Schluessel"
val_string = hash_1[key2]
print val_string
print "\n"
val_pmc = hash_1[key2]
print val_pmc
print "\n"
.end
CODE
-1101.2
-1101.2
-1101.2
-1101.2
OUTPUT
unlink('gdbm_hash_1');
pir_output_is( $new_hash_1 . << 'CODE', << 'OUTPUT', "delete_keyed" );
hash_1 = "gdbm_hash_1"
.local int exist_flag
.local int hash_size
exist_flag = exists hash_1["a"]
print '"a" exists: '
print exist_flag
print "\n"
hash_1["a"] = "A"
exist_flag = exists hash_1["a"]
print '"a" exists: '
print exist_flag
print "\n"
delete hash_1["a"]
exist_flag = exists hash_1["a"]
print '"a" exists: '
print exist_flag
print "\n"
.end
CODE
"a" exists: 0
"a" exists: 1
"a" exists: 0
OUTPUT
unlink('gdbm_hash_1');
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: