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