VirtualBox

source: kBuild/trunk/src/kmk/testcase-ifcond.kmk@ 1728

Last change on this file since 1728 was 1728, checked in by bird, 16 years ago

kmk/expreval/ifcond: fixed the target operator and string parsing; wrote the remaining tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1# $Id: testcase-ifcond.kmk 1728 2008-09-05 03:27:06Z bird $
2## @file
3# kBuild - testcase for the if conditionals.
4#
5
6#
7# Copyright (c) 2007 knut st. osmundsen <[email protected]>
8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
23# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24#
25#
26
27
28DEPTH = ../..
29include $(KBUILD_PATH)/header.kmk
30
31#
32# Note! The testcase are ordered by ascending operator precedence
33# with the exception of equal and not-equal because these
34# are kind of useful for performing tests on non-logical ops.
35#
36
37#
38# Parenthesis
39#
40$(warning unary operators: ( and ) )
41if (1)
42else
43$(error )
44endif
45
46if ((((1))))
47else
48$(error )
49endif
50
51
52#
53# Equal and Not Equal w/ some fundamental bits thrown in.
54#
55$(warning binary operators: == and != )
56
57if 1 == 1
58else
59$(error )
60endif
61
62if 2 == 3
63$(error )
64else
65endif
66
67if 2 != 3
68else
69$(error )
70endif
71
72if a != b
73else
74$(error )
75endif
76
77if asdf == asdf
78else
79$(error )
80endif
81
82if "asdf" == asdf
83else
84$(error )
85endif
86
87if 'asdf' == asdf
88else
89$(error )
90endif
91
92if 'asdf' == "asdf"
93else
94$(error )
95endif
96
97if 'asdf' == 'asdf'
98else
99$(error )
100endif
101
102if "asdf" == "asdf"
103else
104$(error )
105endif
106
107if 0x1 == 1
108else
109$(error )
110endif
111
112if 0xfff == 4095
113else
114$(error )
115endif
116
117if 0xfff == 4095
118else
119$(error )
120endif
121
122if 0d10 == 10
123else
124$(error )
125endif
126
127if 0d10 == 10
128else
129$(error )
130endif
131
132if 0xa == 012
133else
134$(error )
135endif
136
137if 0b1110 == 016
138else
139$(error )
140endif
141
142
143#
144# Logical OR
145#
146$(warning binary operator: || )
147if 1
148else
149$(error busted)
150endif
151
152if 1 || 1
153else
154$(error )
155endif
156
157if 0 || 0
158$(error )
159else
160endif
161
162if 1 || 0
163else
164$(error )
165endif
166
167if 0 || 1
168else
169$(error )
170endif
171
172if 0 || 0 || 0 || 0 || 0 || 0 || 0
173$(error )
174else
175endif
176
177if 0 || 0 || 0 || 1 || 0 || 0 || 0
178else
179$(error )
180endif
181
182if "asdf" || 0
183else
184$(error )
185endif
186
187if 0 || "asdf"
188else
189$(error )
190endif
191
192if 'asdf' || 0
193else
194$(error )
195endif
196
197if "" || 0
198$(error )
199endif
200if "" || 1
201else
202$(error )
203endif
204if '' || 0
205$(error )
206endif
207if '' || 1
208else
209$(error )
210endif
211
212if "" || ''
213$(error )
214endif
215if "1" || ''
216else
217$(error )
218endif
219if "1" || '1'
220else
221$(error )
222endif
223if "" || '1'
224else
225$(error )
226endif
227
228
229#
230# Logical AND
231#
232$(warning binary operator: && )
233if 1 && 1
234else
235$(error )
236endif
237if 1 && 0
238$(error )
239endif
240if 1234 && 0
241$(error )
242endif
243if 123434 && 0 && 123435 && 1
244$(error )
245endif
246
247if "" && 1
248$(error )
249endif
250if ("asdf" && 1) != 1
251$(error )
252endif
253if "1" && 'asdf'
254else
255$(error )
256endif
257if "1" && 'asdf' && 0
258$(error )
259endif
260
261if 0 || 1 && 0
262$(error )
263endif
264
265
266#
267# Bitwise OR
268#
269$(warning binary operator: | )
270if 1 | 0
271else
272$(error )
273endif
274if 1 | 1
275else
276$(error )
277endif
278if 11234 | 343423
279else
280$(error )
281endif
282if (1|2)!=3
283$(error )
284endif
285if 1|2 != 3
286else
287$(error )
288endif
289if (1|2|4|8)!=0xf
290$(error )
291endif
292
293
294#
295# Bitwise XOR
296#
297$(warning binary operator: ^ )
298if 1 ^ 1
299$(error )
300endif
301
302if (2 ^ 1) != 3
303$(error )
304endif
305
306if 7 != (2 ^ 1 ^ 4)
307$(error )
308endif
309
310if (2 ^ 1 | 2) != 3
311$(error )
312endif
313
314
315#
316# Bitwise AND
317#
318$(warning binary operator: & )
319if (4097 & 1) != 1
320$(error )
321endif
322if (0xfff & 0x0f0) != 0xf0
323$(error )
324endif
325if (0x1e3 & 0x100 | 3) != 0x103
326$(error )
327endif
328
329
330#
331# Greater than
332#
333$(warning binary operator: > )
334if 1 > 0
335else
336$(error )
337endif
338
339if 1024 > 1023
340else
341$(error )
342endif
343
344if 999 > 1023
345$(error )
346endif
347
348if (5 > 4 | 2) != 3
349$(error )
350endif
351
352if (1 & 8 > 4) != 1
353$(error )
354endif
355
356if (8 > 4 ^ 16) != 17
357$(error )
358endif
359
360if "b" > 'a'
361else
362$(error )
363endif
364if "abcdef" > 'ffdas'
365$(error )
366endif
367if abcdef > ffdas
368$(error )
369endif
370
371
372#
373# Greater or equal than
374#
375$(warning binary operator: >= )
376if 20 > 0
377else
378$(error )
379endif
380
381if 20 >= 20
382else
383$(error )
384endif
385
386if 19 >= 20
387$(error )
388endif
389
390if (1 & 8 >= 4) != 1
391$(error )
392endif
393
394if "x" >= 'x'
395else
396$(error )
397endif
398if "abdc" >= 'abcd'
399else
400$(error )
401endif
402if "ffdaaa" >= 'ffdasd'
403$(error )
404endif
405if asdf >= asdf
406else
407$(error )
408endif
409
410
411#
412# Less than
413#
414if 1 < 1
415$(error )
416endif
417if -123 < -134
418$(error )
419endif
420if 123 <= 7777
421else
422$(error )
423endif
424
425if "b" < 'a'
426$(error )
427endif
428if b < a
429$(error )
430endif
431if 'foobar' < 'a$'
432$(error )
433endif
434if hhhh < ggggg
435$(error )
436endif
437if qwerty < qwerty0
438else
439$(error )
440endif
441
442
443#
444# Less or equal than
445#
446$(warning binary operator: >> )
447if 1 <= 0
448$(error )
449endif
450if 1 <= 1
451else
452$(error )
453endif
454if 123 <= 123 != 1
455$(error )
456endif
457if 560 <= 456
458$(error )
459endif
460
461if "a" <= 'a'
462else
463$(error )
464endif
465if "abcdef" <= 'abcdef'
466else
467$(error )
468endif
469if q12345z6 <= q12345z
470$(error )
471endif
472if QWERTY <= ABCDE
473$(error )
474endif
475
476
477#
478# Shift right
479#
480$(warning binary operator: >> )
481if 1 >> 0 != 1
482$(error )
483endif
484if 1024 >> 2 != 256
485$(error )
486endif
487if 102435 >> 4 > 1234 != 1
488$(error )
489endif
490
491
492#
493# Shift left
494#
495$(warning binary operator: << )
496if 1 << 0 != 1
497$(error )
498endif
499if 1 << 1 != 2
500$(error )
501endif
502if 1 << 4 != 16
503$(error )
504endif
505if 1 << 10 != 1024
506$(error )
507endif
508if 34 << 10 != 0x8800
509$(error )
510endif
511if 1099511627776 << 21 != 2305843009213693952
512$(error )
513endif
514if 1 << 61 != 2305843009213693952
515$(error )
516endif
517
518if 2 << 60 > 123434323 != 1
519$(error )
520endif
521
522
523#
524# Subtraction
525#
526$(warning binary operator: - )
527if 1-1 != 0
528$(error )
529endif
530if 1023-511 != 512
531$(error )
532endif
533if 4 - 3 << 3 != 8
534$(error )
535endif
536
537
538#
539# Addition
540#
541$(warning binary operator: + )
542if 1+1 != 2
543$(error )
544endif
545if 1234+1000 != 2234
546$(error )
547endif
548if 2 + 2 << 4 != 64
549$(error )
550endif
551
552
553#
554# Modulus
555#
556$(warning binary operator: % )
557if 0%2 != 0
558$(error )
559endif
560if 10%7 != 3
561$(error )
562endif
563if 10 + 100%70 - 3 != 37
564$(error )
565endif
566
567
568#
569# Division
570#
571$(warning binary operator: / )
572if 0/1 != 0
573$(error )
574endif
575if 1000/2 != 500
576$(error )
577endif
578if 1000/2 + 4 != 504
579$(error )
580endif
581if 5 + 1000/4 != 255
582$(error )
583endif
584
585
586#
587# Multiplication
588#
589$(warning binary operator: * )
590if 1*1 != 1
591$(error )
592endif
593if 10*10 != 100
594$(error )
595endif
596if 1024*64 != 65536
597$(error )
598endif
599if 10*10 - 10 != 90
600$(error )
601endif
602if 1000 - 10*10 != 900
603$(error )
604endif
605
606
607#
608# Logical NOT
609#
610$(warning unary operator: ! )
611if !1
612$(error )
613endif
614
615if !42 == 0
616else
617$(error )
618endif
619
620if !0 == 1
621else
622$(error )
623endif
624
625if !!0 == 0
626else
627$(error )
628endif
629
630if !0 * 123 != 123
631$(error )
632endif
633if !!!0 * 512 != 512
634$(error )
635endif
636
637
638#
639# Bitwise NOT
640#
641$(warning unary operator: ~ )
642if ~0xfff != 0xfffffffffffff000
643$(error )
644endif
645
646
647#
648# Pluss
649#
650$(warning unary operator: + )
651if +2 != 2
652$(error )
653endif
654if 1++++++++++++2134 != 2135
655$(error )
656endif
657
658
659#
660# Minus (negation)
661#
662$(warning unary operator: - )
663if --2 != 2
664$(error )
665endif
666
667if 1 - -2 != 3
668$(error )
669endif
670
671
672#
673# target
674#
675trg_deps_only: foobar
676trg_with_cmds: foobar
677 echo $@
678
679$(warning unary operator: target ) # This flushes stuff in read.c
680
681if target trg_with_cmds
682else
683$(error target trg_with_cmds)
684endif
685if target(trg_deps_only)
686$(error target trg_deps_only)
687endif
688if target ( foobar )
689$(error target foobar)
690endif
691
692
693#
694# defined
695#
696$(warning unary operator: defined )
697var_defined := 1
698var_not_defined :=
699
700if defined var_defined
701else
702$(error )
703endif
704if defined(var_defined)
705else
706$(error )
707endif
708if defined (var_defined)
709else
710$(error )
711endif
712if !defined(var_defined)
713$(error )
714endif
715if defined (var_not_defined)
716$(error )
717endif
718
719
720#
721# bool
722#
723
724
725#
726# string
727#
728
729
730
731#
732# Quick check of $(if-expr ) and $(expr ).
733#
734$(warning $$(if-expr ,,) )
735ifeq ($(if-expr 0 || 2,42,500),42)
736else
737$(error )
738endif
739ifeq ($(if-expr 5+3 == 231,42,500),42)
740$(error )
741endif
742
743$(warning $$(expr ) )
744ifeq ($(expr 5+3),8)
745else
746$(error expr:$(expr 5+3) expected 8)
747endif
748ifeq ($(expr 25*25),625)
749else
750$(error expr:$(expr 25*25) expected 625)
751endif
752ifeq ($(expr 100/3),3)
753$(error )
754endif
755
756
757
758all_recursive:
759 $(ECHO) "if works fine"
760
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette