xref: /PHP-8.2/ext/com_dotnet/tests/variants.phpt (revision 56f90492)
1--TEST--
2COM: General variant tests
3--EXTENSIONS--
4com_dotnet
5--SKIPIF--
6<?php
7if (4 != PHP_INT_SIZE) print "skip x86 only"; ?>
8--FILE--
9<?php
10error_reporting(E_ALL);
11
12$v = new VARIANT();
13if (VT_EMPTY != variant_get_type($v)) {
14    echo "VT_EMPTY: bork\n";
15}
16
17$values = array(VT_I4 => 42, VT_R8 => 3.5, VT_BSTR => "hello", VT_BOOL => false);
18$binary_ops = array('add', 'cat', 'sub', 'mul', 'and', 'div',
19    'eqv', 'idiv', 'imp', 'mod', 'or', 'pow', 'xor');
20
21foreach ($values as $t => $val) {
22    $v = new VARIANT($val);
23    if ($t != variant_get_type($v)) {
24        printf("Bork: [%d] %d: %s\n", $t, variant_get_type($v), $val);
25        print $v . "\n";
26    }
27    $results = array();
28
29    foreach ($values as $op2) {
30        echo "--\n";
31        foreach ($binary_ops as $op) {
32            try {
33                echo "$op: " . call_user_func('variant_' . $op, $v, $op2) . "\n";
34            } catch (com_exception $e) {
35                echo "$op:\n";
36                echo "\tvariant_$op($v, $op2)\n";
37                echo "\texception " . $e->getMessage();
38                printf("\n\tcode %08x\n\n", $e->getCode());
39            }
40        }
41    }
42}
43
44echo "OK!";
45?>
46--EXPECT--
47--
48add: 84
49cat: 4242
50sub: 0
51mul: 1764
52and: 42
53div: 1
54eqv: -1
55idiv: 1
56imp: -1
57mod: 0
58or: 42
59pow: 1.50130937545297E+68
60xor: 0
61--
62add: 45.5
63cat: 423.5
64sub: 38.5
65mul: 147
66and: 0
67div: 12
68eqv: -47
69idiv: 10
70imp: -43
71mod: 2
72or: 46
73pow: 480145.116863642
74xor: 46
75--
76add:
77	variant_add(42, hello)
78	exception Type mismatch
79	code 80020005
80
81cat: 42hello
82sub:
83	variant_sub(42, hello)
84	exception Type mismatch
85	code 80020005
86
87mul:
88	variant_mul(42, hello)
89	exception Type mismatch
90	code 80020005
91
92and:
93	variant_and(42, hello)
94	exception Type mismatch
95	code 80020005
96
97div:
98	variant_div(42, hello)
99	exception Type mismatch
100	code 80020005
101
102eqv:
103	variant_eqv(42, hello)
104	exception Type mismatch
105	code 80020005
106
107idiv:
108	variant_idiv(42, hello)
109	exception Type mismatch
110	code 80020005
111
112imp:
113	variant_imp(42, hello)
114	exception Type mismatch
115	code 80020005
116
117mod:
118	variant_mod(42, hello)
119	exception Type mismatch
120	code 80020005
121
122or:
123	variant_or(42, hello)
124	exception Type mismatch
125	code 80020005
126
127pow:
128	variant_pow(42, hello)
129	exception Type mismatch
130	code 80020005
131
132xor:
133	variant_xor(42, hello)
134	exception Type mismatch
135	code 80020005
136
137--
138add: 42
139cat: 42False
140sub: 42
141mul: 0
142and: 0
143div:
144	variant_div(42, )
145	exception Division by zero
146	code 80020012
147
148eqv: -43
149idiv:
150	variant_idiv(42, )
151	exception Division by zero
152	code 80020012
153
154imp: -43
155mod:
156	variant_mod(42, )
157	exception Division by zero
158	code 80020012
159
160or: 42
161pow: 1
162xor: 42
163--
164add: 45.5
165cat: 3.542
166sub: -38.5
167mul: 147
168and: 0
169div: 8.33333333333333E-02
170eqv: -47
171idiv: 0
172imp: -5
173mod: 4
174or: 46
175pow: 7.09345573078604E+22
176xor: 46
177--
178add: 7
179cat: 3.53.5
180sub: 0
181mul: 12.25
182and: 4
183div: 1
184eqv: -1
185idiv: 1
186imp: -1
187mod: 0
188or: 4
189pow: 80.2117802289664
190xor: 0
191--
192add:
193	variant_add(3.5, hello)
194	exception Type mismatch
195	code 80020005
196
197cat: 3.5hello
198sub:
199	variant_sub(3.5, hello)
200	exception Type mismatch
201	code 80020005
202
203mul:
204	variant_mul(3.5, hello)
205	exception Type mismatch
206	code 80020005
207
208and:
209	variant_and(3.5, hello)
210	exception Type mismatch
211	code 80020005
212
213div:
214	variant_div(3.5, hello)
215	exception Type mismatch
216	code 80020005
217
218eqv:
219	variant_eqv(3.5, hello)
220	exception Type mismatch
221	code 80020005
222
223idiv:
224	variant_idiv(3.5, hello)
225	exception Type mismatch
226	code 80020005
227
228imp:
229	variant_imp(3.5, hello)
230	exception Type mismatch
231	code 80020005
232
233mod:
234	variant_mod(3.5, hello)
235	exception Type mismatch
236	code 80020005
237
238or:
239	variant_or(3.5, hello)
240	exception Type mismatch
241	code 80020005
242
243pow:
244	variant_pow(3.5, hello)
245	exception Type mismatch
246	code 80020005
247
248xor:
249	variant_xor(3.5, hello)
250	exception Type mismatch
251	code 80020005
252
253--
254add: 3.5
255cat: 3.5False
256sub: 3.5
257mul: 0
258and: 0
259div:
260	variant_div(3.5, )
261	exception Division by zero
262	code 80020012
263
264eqv: -5
265idiv:
266	variant_idiv(3.5, )
267	exception Division by zero
268	code 80020012
269
270imp: -5
271mod:
272	variant_mod(3.5, )
273	exception Division by zero
274	code 80020012
275
276or: 4
277pow: 1
278xor: 4
279--
280add:
281	variant_add(hello, 42)
282	exception Type mismatch
283	code 80020005
284
285cat: hello42
286sub:
287	variant_sub(hello, 42)
288	exception Type mismatch
289	code 80020005
290
291mul:
292	variant_mul(hello, 42)
293	exception Type mismatch
294	code 80020005
295
296and:
297	variant_and(hello, 42)
298	exception Type mismatch
299	code 80020005
300
301div:
302	variant_div(hello, 42)
303	exception Type mismatch
304	code 80020005
305
306eqv:
307	variant_eqv(hello, 42)
308	exception Type mismatch
309	code 80020005
310
311idiv:
312	variant_idiv(hello, 42)
313	exception Type mismatch
314	code 80020005
315
316imp:
317	variant_imp(hello, 42)
318	exception Type mismatch
319	code 80020005
320
321mod:
322	variant_mod(hello, 42)
323	exception Type mismatch
324	code 80020005
325
326or:
327	variant_or(hello, 42)
328	exception Type mismatch
329	code 80020005
330
331pow:
332	variant_pow(hello, 42)
333	exception Type mismatch
334	code 80020005
335
336xor:
337	variant_xor(hello, 42)
338	exception Type mismatch
339	code 80020005
340
341--
342add:
343	variant_add(hello, 3.5)
344	exception Type mismatch
345	code 80020005
346
347cat: hello3.5
348sub:
349	variant_sub(hello, 3.5)
350	exception Type mismatch
351	code 80020005
352
353mul:
354	variant_mul(hello, 3.5)
355	exception Type mismatch
356	code 80020005
357
358and:
359	variant_and(hello, 3.5)
360	exception Type mismatch
361	code 80020005
362
363div:
364	variant_div(hello, 3.5)
365	exception Type mismatch
366	code 80020005
367
368eqv:
369	variant_eqv(hello, 3.5)
370	exception Type mismatch
371	code 80020005
372
373idiv:
374	variant_idiv(hello, 3.5)
375	exception Type mismatch
376	code 80020005
377
378imp:
379	variant_imp(hello, 3.5)
380	exception Type mismatch
381	code 80020005
382
383mod:
384	variant_mod(hello, 3.5)
385	exception Type mismatch
386	code 80020005
387
388or:
389	variant_or(hello, 3.5)
390	exception Type mismatch
391	code 80020005
392
393pow:
394	variant_pow(hello, 3.5)
395	exception Type mismatch
396	code 80020005
397
398xor:
399	variant_xor(hello, 3.5)
400	exception Type mismatch
401	code 80020005
402
403--
404add: hellohello
405cat: hellohello
406sub:
407	variant_sub(hello, hello)
408	exception Type mismatch
409	code 80020005
410
411mul:
412	variant_mul(hello, hello)
413	exception Type mismatch
414	code 80020005
415
416and:
417	variant_and(hello, hello)
418	exception Type mismatch
419	code 80020005
420
421div:
422	variant_div(hello, hello)
423	exception Type mismatch
424	code 80020005
425
426eqv:
427	variant_eqv(hello, hello)
428	exception Type mismatch
429	code 80020005
430
431idiv:
432	variant_idiv(hello, hello)
433	exception Type mismatch
434	code 80020005
435
436imp:
437	variant_imp(hello, hello)
438	exception Type mismatch
439	code 80020005
440
441mod:
442	variant_mod(hello, hello)
443	exception Type mismatch
444	code 80020005
445
446or:
447	variant_or(hello, hello)
448	exception Type mismatch
449	code 80020005
450
451pow:
452	variant_pow(hello, hello)
453	exception Type mismatch
454	code 80020005
455
456xor:
457	variant_xor(hello, hello)
458	exception Type mismatch
459	code 80020005
460
461--
462add:
463	variant_add(hello, )
464	exception Type mismatch
465	code 80020005
466
467cat: helloFalse
468sub:
469	variant_sub(hello, )
470	exception Type mismatch
471	code 80020005
472
473mul:
474	variant_mul(hello, )
475	exception Type mismatch
476	code 80020005
477
478and:
479	variant_and(hello, )
480	exception Type mismatch
481	code 80020005
482
483div:
484	variant_div(hello, )
485	exception Type mismatch
486	code 80020005
487
488eqv:
489	variant_eqv(hello, )
490	exception Type mismatch
491	code 80020005
492
493idiv:
494	variant_idiv(hello, )
495	exception Type mismatch
496	code 80020005
497
498imp:
499	variant_imp(hello, )
500	exception Type mismatch
501	code 80020005
502
503mod:
504	variant_mod(hello, )
505	exception Type mismatch
506	code 80020005
507
508or:
509	variant_or(hello, )
510	exception Type mismatch
511	code 80020005
512
513pow:
514	variant_pow(hello, )
515	exception Type mismatch
516	code 80020005
517
518xor:
519	variant_xor(hello, )
520	exception Type mismatch
521	code 80020005
522
523--
524add: 42
525cat: False42
526sub: -42
527mul: 0
528and: 0
529div: 0
530eqv: -43
531idiv: 0
532imp: -1
533mod: 0
534or: 42
535pow: 0
536xor: 42
537--
538add: 3.5
539cat: False3.5
540sub: -3.5
541mul: 0
542and: 0
543div: 0
544eqv: -5
545idiv: 0
546imp: -1
547mod: 0
548or: 4
549pow: 0
550xor: 4
551--
552add:
553	variant_add(0, hello)
554	exception Type mismatch
555	code 80020005
556
557cat: Falsehello
558sub:
559	variant_sub(0, hello)
560	exception Type mismatch
561	code 80020005
562
563mul:
564	variant_mul(0, hello)
565	exception Type mismatch
566	code 80020005
567
568and:
569	variant_and(0, hello)
570	exception Type mismatch
571	code 80020005
572
573div:
574	variant_div(0, hello)
575	exception Type mismatch
576	code 80020005
577
578eqv:
579	variant_eqv(0, hello)
580	exception Type mismatch
581	code 80020005
582
583idiv:
584	variant_idiv(0, hello)
585	exception Type mismatch
586	code 80020005
587
588imp:
589	variant_imp(0, hello)
590	exception Type mismatch
591	code 80020005
592
593mod:
594	variant_mod(0, hello)
595	exception Type mismatch
596	code 80020005
597
598or:
599	variant_or(0, hello)
600	exception Type mismatch
601	code 80020005
602
603pow:
604	variant_pow(0, hello)
605	exception Type mismatch
606	code 80020005
607
608xor:
609	variant_xor(0, hello)
610	exception Type mismatch
611	code 80020005
612
613--
614add: 0
615cat: FalseFalse
616sub: 0
617mul: 0
618and: 0
619div:
620	variant_div(0, )
621	exception Out of present range
622	code 8002000a
623
624eqv: -1
625idiv:
626	variant_idiv(0, )
627	exception Division by zero
628	code 80020012
629
630imp: -1
631mod:
632	variant_mod(0, )
633	exception Division by zero
634	code 80020012
635
636or: 0
637pow: 1
638xor: 0
639OK!
640