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