1--TEST--
2Test strncasecmp() function : usage variations - binary safe - all ASCII chars
3--FILE--
4<?php
5/* Prototype  : int strncasecmp ( string $str1, string $str2, int $len );
6 * Description: Binary safe case-insensitive string comparison of the first n characters
7 * Source code: Zend/zend_builtin_functions.c
8*/
9
10/* Test strncasecmp() function with binary values passed to 'str1' & 'str2' */
11
12echo "*** Test strncasecmp() function: with binary inputs ***\n";
13
14/* A binary function should work with all 256 characters that a character(8-bit) can take */
15echo "\n-- Checking with all 256 characters given, in binary format --\n";
16/* loop through to get all 256 character's equivelent binary value, and check working of strncasecmp() */
17$count = 1;
18for($ASCII = 0; $ASCII <= 255; $ASCII++) {
19  $str1 = decbin($ASCII);  //ASCII value in binary form
20  $str2 = decbin( ord( chr($ASCII) ) );  //Getting equivelent ASCII value for the character in binary form
21  echo "-- Iteration $count --\n";
22  var_dump( strncasecmp($str1, $str2, 8) );  //comparing all the 8-bits; expected: int(0)
23  var_dump( strncasecmp($str1, $str2, 4) );  //comparing only 4-bits; expected: int(0)
24  $count++;
25}
26
27echo "\n-- Checking with out of character's range, given in binary format --\n";
28$str1 = decbin(256);
29$str2 = decbin( ord( chr(256) ));
30var_dump( strncasecmp($str1, $str2, 8) );  //comparing all the 8-bits; expected: int(1)
31
32echo "\n*** Done ***\n";
33?>
34--EXPECTF--
35*** Test strncasecmp() function: with binary inputs ***
36
37-- Checking with all 256 characters given, in binary format --
38-- Iteration 1 --
39int(0)
40int(0)
41-- Iteration 2 --
42int(0)
43int(0)
44-- Iteration 3 --
45int(0)
46int(0)
47-- Iteration 4 --
48int(0)
49int(0)
50-- Iteration 5 --
51int(0)
52int(0)
53-- Iteration 6 --
54int(0)
55int(0)
56-- Iteration 7 --
57int(0)
58int(0)
59-- Iteration 8 --
60int(0)
61int(0)
62-- Iteration 9 --
63int(0)
64int(0)
65-- Iteration 10 --
66int(0)
67int(0)
68-- Iteration 11 --
69int(0)
70int(0)
71-- Iteration 12 --
72int(0)
73int(0)
74-- Iteration 13 --
75int(0)
76int(0)
77-- Iteration 14 --
78int(0)
79int(0)
80-- Iteration 15 --
81int(0)
82int(0)
83-- Iteration 16 --
84int(0)
85int(0)
86-- Iteration 17 --
87int(0)
88int(0)
89-- Iteration 18 --
90int(0)
91int(0)
92-- Iteration 19 --
93int(0)
94int(0)
95-- Iteration 20 --
96int(0)
97int(0)
98-- Iteration 21 --
99int(0)
100int(0)
101-- Iteration 22 --
102int(0)
103int(0)
104-- Iteration 23 --
105int(0)
106int(0)
107-- Iteration 24 --
108int(0)
109int(0)
110-- Iteration 25 --
111int(0)
112int(0)
113-- Iteration 26 --
114int(0)
115int(0)
116-- Iteration 27 --
117int(0)
118int(0)
119-- Iteration 28 --
120int(0)
121int(0)
122-- Iteration 29 --
123int(0)
124int(0)
125-- Iteration 30 --
126int(0)
127int(0)
128-- Iteration 31 --
129int(0)
130int(0)
131-- Iteration 32 --
132int(0)
133int(0)
134-- Iteration 33 --
135int(0)
136int(0)
137-- Iteration 34 --
138int(0)
139int(0)
140-- Iteration 35 --
141int(0)
142int(0)
143-- Iteration 36 --
144int(0)
145int(0)
146-- Iteration 37 --
147int(0)
148int(0)
149-- Iteration 38 --
150int(0)
151int(0)
152-- Iteration 39 --
153int(0)
154int(0)
155-- Iteration 40 --
156int(0)
157int(0)
158-- Iteration 41 --
159int(0)
160int(0)
161-- Iteration 42 --
162int(0)
163int(0)
164-- Iteration 43 --
165int(0)
166int(0)
167-- Iteration 44 --
168int(0)
169int(0)
170-- Iteration 45 --
171int(0)
172int(0)
173-- Iteration 46 --
174int(0)
175int(0)
176-- Iteration 47 --
177int(0)
178int(0)
179-- Iteration 48 --
180int(0)
181int(0)
182-- Iteration 49 --
183int(0)
184int(0)
185-- Iteration 50 --
186int(0)
187int(0)
188-- Iteration 51 --
189int(0)
190int(0)
191-- Iteration 52 --
192int(0)
193int(0)
194-- Iteration 53 --
195int(0)
196int(0)
197-- Iteration 54 --
198int(0)
199int(0)
200-- Iteration 55 --
201int(0)
202int(0)
203-- Iteration 56 --
204int(0)
205int(0)
206-- Iteration 57 --
207int(0)
208int(0)
209-- Iteration 58 --
210int(0)
211int(0)
212-- Iteration 59 --
213int(0)
214int(0)
215-- Iteration 60 --
216int(0)
217int(0)
218-- Iteration 61 --
219int(0)
220int(0)
221-- Iteration 62 --
222int(0)
223int(0)
224-- Iteration 63 --
225int(0)
226int(0)
227-- Iteration 64 --
228int(0)
229int(0)
230-- Iteration 65 --
231int(0)
232int(0)
233-- Iteration 66 --
234int(0)
235int(0)
236-- Iteration 67 --
237int(0)
238int(0)
239-- Iteration 68 --
240int(0)
241int(0)
242-- Iteration 69 --
243int(0)
244int(0)
245-- Iteration 70 --
246int(0)
247int(0)
248-- Iteration 71 --
249int(0)
250int(0)
251-- Iteration 72 --
252int(0)
253int(0)
254-- Iteration 73 --
255int(0)
256int(0)
257-- Iteration 74 --
258int(0)
259int(0)
260-- Iteration 75 --
261int(0)
262int(0)
263-- Iteration 76 --
264int(0)
265int(0)
266-- Iteration 77 --
267int(0)
268int(0)
269-- Iteration 78 --
270int(0)
271int(0)
272-- Iteration 79 --
273int(0)
274int(0)
275-- Iteration 80 --
276int(0)
277int(0)
278-- Iteration 81 --
279int(0)
280int(0)
281-- Iteration 82 --
282int(0)
283int(0)
284-- Iteration 83 --
285int(0)
286int(0)
287-- Iteration 84 --
288int(0)
289int(0)
290-- Iteration 85 --
291int(0)
292int(0)
293-- Iteration 86 --
294int(0)
295int(0)
296-- Iteration 87 --
297int(0)
298int(0)
299-- Iteration 88 --
300int(0)
301int(0)
302-- Iteration 89 --
303int(0)
304int(0)
305-- Iteration 90 --
306int(0)
307int(0)
308-- Iteration 91 --
309int(0)
310int(0)
311-- Iteration 92 --
312int(0)
313int(0)
314-- Iteration 93 --
315int(0)
316int(0)
317-- Iteration 94 --
318int(0)
319int(0)
320-- Iteration 95 --
321int(0)
322int(0)
323-- Iteration 96 --
324int(0)
325int(0)
326-- Iteration 97 --
327int(0)
328int(0)
329-- Iteration 98 --
330int(0)
331int(0)
332-- Iteration 99 --
333int(0)
334int(0)
335-- Iteration 100 --
336int(0)
337int(0)
338-- Iteration 101 --
339int(0)
340int(0)
341-- Iteration 102 --
342int(0)
343int(0)
344-- Iteration 103 --
345int(0)
346int(0)
347-- Iteration 104 --
348int(0)
349int(0)
350-- Iteration 105 --
351int(0)
352int(0)
353-- Iteration 106 --
354int(0)
355int(0)
356-- Iteration 107 --
357int(0)
358int(0)
359-- Iteration 108 --
360int(0)
361int(0)
362-- Iteration 109 --
363int(0)
364int(0)
365-- Iteration 110 --
366int(0)
367int(0)
368-- Iteration 111 --
369int(0)
370int(0)
371-- Iteration 112 --
372int(0)
373int(0)
374-- Iteration 113 --
375int(0)
376int(0)
377-- Iteration 114 --
378int(0)
379int(0)
380-- Iteration 115 --
381int(0)
382int(0)
383-- Iteration 116 --
384int(0)
385int(0)
386-- Iteration 117 --
387int(0)
388int(0)
389-- Iteration 118 --
390int(0)
391int(0)
392-- Iteration 119 --
393int(0)
394int(0)
395-- Iteration 120 --
396int(0)
397int(0)
398-- Iteration 121 --
399int(0)
400int(0)
401-- Iteration 122 --
402int(0)
403int(0)
404-- Iteration 123 --
405int(0)
406int(0)
407-- Iteration 124 --
408int(0)
409int(0)
410-- Iteration 125 --
411int(0)
412int(0)
413-- Iteration 126 --
414int(0)
415int(0)
416-- Iteration 127 --
417int(0)
418int(0)
419-- Iteration 128 --
420int(0)
421int(0)
422-- Iteration 129 --
423int(0)
424int(0)
425-- Iteration 130 --
426int(0)
427int(0)
428-- Iteration 131 --
429int(0)
430int(0)
431-- Iteration 132 --
432int(0)
433int(0)
434-- Iteration 133 --
435int(0)
436int(0)
437-- Iteration 134 --
438int(0)
439int(0)
440-- Iteration 135 --
441int(0)
442int(0)
443-- Iteration 136 --
444int(0)
445int(0)
446-- Iteration 137 --
447int(0)
448int(0)
449-- Iteration 138 --
450int(0)
451int(0)
452-- Iteration 139 --
453int(0)
454int(0)
455-- Iteration 140 --
456int(0)
457int(0)
458-- Iteration 141 --
459int(0)
460int(0)
461-- Iteration 142 --
462int(0)
463int(0)
464-- Iteration 143 --
465int(0)
466int(0)
467-- Iteration 144 --
468int(0)
469int(0)
470-- Iteration 145 --
471int(0)
472int(0)
473-- Iteration 146 --
474int(0)
475int(0)
476-- Iteration 147 --
477int(0)
478int(0)
479-- Iteration 148 --
480int(0)
481int(0)
482-- Iteration 149 --
483int(0)
484int(0)
485-- Iteration 150 --
486int(0)
487int(0)
488-- Iteration 151 --
489int(0)
490int(0)
491-- Iteration 152 --
492int(0)
493int(0)
494-- Iteration 153 --
495int(0)
496int(0)
497-- Iteration 154 --
498int(0)
499int(0)
500-- Iteration 155 --
501int(0)
502int(0)
503-- Iteration 156 --
504int(0)
505int(0)
506-- Iteration 157 --
507int(0)
508int(0)
509-- Iteration 158 --
510int(0)
511int(0)
512-- Iteration 159 --
513int(0)
514int(0)
515-- Iteration 160 --
516int(0)
517int(0)
518-- Iteration 161 --
519int(0)
520int(0)
521-- Iteration 162 --
522int(0)
523int(0)
524-- Iteration 163 --
525int(0)
526int(0)
527-- Iteration 164 --
528int(0)
529int(0)
530-- Iteration 165 --
531int(0)
532int(0)
533-- Iteration 166 --
534int(0)
535int(0)
536-- Iteration 167 --
537int(0)
538int(0)
539-- Iteration 168 --
540int(0)
541int(0)
542-- Iteration 169 --
543int(0)
544int(0)
545-- Iteration 170 --
546int(0)
547int(0)
548-- Iteration 171 --
549int(0)
550int(0)
551-- Iteration 172 --
552int(0)
553int(0)
554-- Iteration 173 --
555int(0)
556int(0)
557-- Iteration 174 --
558int(0)
559int(0)
560-- Iteration 175 --
561int(0)
562int(0)
563-- Iteration 176 --
564int(0)
565int(0)
566-- Iteration 177 --
567int(0)
568int(0)
569-- Iteration 178 --
570int(0)
571int(0)
572-- Iteration 179 --
573int(0)
574int(0)
575-- Iteration 180 --
576int(0)
577int(0)
578-- Iteration 181 --
579int(0)
580int(0)
581-- Iteration 182 --
582int(0)
583int(0)
584-- Iteration 183 --
585int(0)
586int(0)
587-- Iteration 184 --
588int(0)
589int(0)
590-- Iteration 185 --
591int(0)
592int(0)
593-- Iteration 186 --
594int(0)
595int(0)
596-- Iteration 187 --
597int(0)
598int(0)
599-- Iteration 188 --
600int(0)
601int(0)
602-- Iteration 189 --
603int(0)
604int(0)
605-- Iteration 190 --
606int(0)
607int(0)
608-- Iteration 191 --
609int(0)
610int(0)
611-- Iteration 192 --
612int(0)
613int(0)
614-- Iteration 193 --
615int(0)
616int(0)
617-- Iteration 194 --
618int(0)
619int(0)
620-- Iteration 195 --
621int(0)
622int(0)
623-- Iteration 196 --
624int(0)
625int(0)
626-- Iteration 197 --
627int(0)
628int(0)
629-- Iteration 198 --
630int(0)
631int(0)
632-- Iteration 199 --
633int(0)
634int(0)
635-- Iteration 200 --
636int(0)
637int(0)
638-- Iteration 201 --
639int(0)
640int(0)
641-- Iteration 202 --
642int(0)
643int(0)
644-- Iteration 203 --
645int(0)
646int(0)
647-- Iteration 204 --
648int(0)
649int(0)
650-- Iteration 205 --
651int(0)
652int(0)
653-- Iteration 206 --
654int(0)
655int(0)
656-- Iteration 207 --
657int(0)
658int(0)
659-- Iteration 208 --
660int(0)
661int(0)
662-- Iteration 209 --
663int(0)
664int(0)
665-- Iteration 210 --
666int(0)
667int(0)
668-- Iteration 211 --
669int(0)
670int(0)
671-- Iteration 212 --
672int(0)
673int(0)
674-- Iteration 213 --
675int(0)
676int(0)
677-- Iteration 214 --
678int(0)
679int(0)
680-- Iteration 215 --
681int(0)
682int(0)
683-- Iteration 216 --
684int(0)
685int(0)
686-- Iteration 217 --
687int(0)
688int(0)
689-- Iteration 218 --
690int(0)
691int(0)
692-- Iteration 219 --
693int(0)
694int(0)
695-- Iteration 220 --
696int(0)
697int(0)
698-- Iteration 221 --
699int(0)
700int(0)
701-- Iteration 222 --
702int(0)
703int(0)
704-- Iteration 223 --
705int(0)
706int(0)
707-- Iteration 224 --
708int(0)
709int(0)
710-- Iteration 225 --
711int(0)
712int(0)
713-- Iteration 226 --
714int(0)
715int(0)
716-- Iteration 227 --
717int(0)
718int(0)
719-- Iteration 228 --
720int(0)
721int(0)
722-- Iteration 229 --
723int(0)
724int(0)
725-- Iteration 230 --
726int(0)
727int(0)
728-- Iteration 231 --
729int(0)
730int(0)
731-- Iteration 232 --
732int(0)
733int(0)
734-- Iteration 233 --
735int(0)
736int(0)
737-- Iteration 234 --
738int(0)
739int(0)
740-- Iteration 235 --
741int(0)
742int(0)
743-- Iteration 236 --
744int(0)
745int(0)
746-- Iteration 237 --
747int(0)
748int(0)
749-- Iteration 238 --
750int(0)
751int(0)
752-- Iteration 239 --
753int(0)
754int(0)
755-- Iteration 240 --
756int(0)
757int(0)
758-- Iteration 241 --
759int(0)
760int(0)
761-- Iteration 242 --
762int(0)
763int(0)
764-- Iteration 243 --
765int(0)
766int(0)
767-- Iteration 244 --
768int(0)
769int(0)
770-- Iteration 245 --
771int(0)
772int(0)
773-- Iteration 246 --
774int(0)
775int(0)
776-- Iteration 247 --
777int(0)
778int(0)
779-- Iteration 248 --
780int(0)
781int(0)
782-- Iteration 249 --
783int(0)
784int(0)
785-- Iteration 250 --
786int(0)
787int(0)
788-- Iteration 251 --
789int(0)
790int(0)
791-- Iteration 252 --
792int(0)
793int(0)
794-- Iteration 253 --
795int(0)
796int(0)
797-- Iteration 254 --
798int(0)
799int(0)
800-- Iteration 255 --
801int(0)
802int(0)
803-- Iteration 256 --
804int(0)
805int(0)
806
807-- Checking with out of character's range, given in binary format --
808int(1)
809
810*** Done ***
811