xref: /PHP-5.6/ext/hash/tests/fnv132.phpt (revision d05ce257)
1--TEST--
2FNV
3--SKIPIF--
4<?php extension_loaded('hash') or die ('Skip - hash extension not available'); ?>
5--FILE--
6<?php
7
8function R10($t) {
9	return str_repeat($t, 10);
10}
11
12function R500($t) {
13	return str_repeat($t, 500);
14}
15
16$tests = array(
17	array( "", "811c9dc5" ),
18	array( "a", "050c5d7e" ),
19	array( "b", "050c5d7d" ),
20	array( "c", "050c5d7c" ),
21	array( "d", "050c5d7b" ),
22	array( "e", "050c5d7a" ),
23	array( "f", "050c5d79" ),
24	array( "fo", "6b772514" ),
25	array( "foo", "408f5e13" ),
26	array( "foob", "b4b1178b" ),
27	array( "fooba", "fdc80fb0" ),
28	array( "foobar", "31f0b262" ),
29	array( "\0", "050c5d1f" ),
30	array( "a\0", "70772d5a" ),
31	array( "b\0", "6f772bc7" ),
32	array( "c\0", "6e772a34" ),
33	array( "d\0", "6d7728a1" ),
34	array( "e\0", "6c77270e" ),
35	array( "f\0", "6b77257b" ),
36	array( "fo\0", "408f5e7c" ),
37	array( "foo\0", "b4b117e9" ),
38	array( "foob\0", "fdc80fd1" ),
39	array( "fooba\0", "31f0b210" ),
40	array( "foobar\0", "ffe8d046" ),
41	array( "ch", "6e772a5c" ),
42	array( "cho", "4197aebb" ),
43	array( "chon", "fcc8100f" ),
44	array( "chong", "fdf147fa" ),
45	array( "chongo", "bcd44ee1" ),
46	array( "chongo ", "23382c13" ),
47	array( "chongo w", "846d619e" ),
48	array( "chongo wa", "1630abdb" ),
49	array( "chongo was", "c99e89b2" ),
50	array( "chongo was ", "1692c316" ),
51	array( "chongo was h", "9f091bca" ),
52	array( "chongo was he", "2556be9b" ),
53	array( "chongo was her", "628e0e73" ),
54	array( "chongo was here", "98a0bf6c" ),
55	array( "chongo was here!", "b10d5725" ),
56	array( "chongo was here!\n", "dd002f35" ),
57	array( "ch\0", "4197aed4" ),
58	array( "cho\0", "fcc81061" ),
59	array( "chon\0", "fdf1479d" ),
60	array( "chong\0", "bcd44e8e" ),
61	array( "chongo\0", "23382c33" ),
62	array( "chongo \0", "846d61e9" ),
63	array( "chongo w\0", "1630abba" ),
64	array( "chongo wa\0", "c99e89c1" ),
65	array( "chongo was\0", "1692c336" ),
66	array( "chongo was \0", "9f091ba2" ),
67	array( "chongo was h\0", "2556befe" ),
68	array( "chongo was he\0", "628e0e01" ),
69	array( "chongo was her\0", "98a0bf09" ),
70	array( "chongo was here\0", "b10d5704" ),
71	array( "chongo was here!\0", "dd002f3f" ),
72	array( "chongo was here!\n\0", "1c4a506f" ),
73	array( "cu", "6e772a41" ),
74	array( "cur", "26978421" ),
75	array( "curd", "e184ff97" ),
76	array( "curds", "9b5e5ac6" ),
77	array( "curds ", "5b88e592" ),
78	array( "curds a", "aa8164b7" ),
79	array( "curds an", "20b18c7b" ),
80	array( "curds and", "f28025c5" ),
81	array( "curds and ", "84bb753f" ),
82	array( "curds and w", "3219925a" ),
83	array( "curds and wh", "384163c6" ),
84	array( "curds and whe", "54f010d7" ),
85	array( "curds and whey", "8cea820c" ),
86	array( "curds and whey\n", "e12ab8ee" ),
87	array( "cu\0", "26978453" ),
88	array( "cur\0", "e184fff3" ),
89	array( "curd\0", "9b5e5ab5" ),
90	array( "curds\0", "5b88e5b2" ),
91	array( "curds \0", "aa8164d6" ),
92	array( "curds a\0", "20b18c15" ),
93	array( "curds an\0", "f28025a1" ),
94	array( "curds and\0", "84bb751f" ),
95	array( "curds and \0", "3219922d" ),
96	array( "curds and w\0", "384163ae" ),
97	array( "curds and wh\0", "54f010b2" ),
98	array( "curds and whe\0", "8cea8275" ),
99	array( "curds and whey\0", "e12ab8e4" ),
100	array( "curds and whey\n\0", "64411eaa" ),
101	array( "line 1\nline 2\nline 3", "31ae8f83" ),
102	array( "chongo <Landon Curt Noll> /\\../\\", "995fa9c4" ),
103	array( "chongo <Landon Curt Noll> /\\../\\\0", "35983f8c" ),
104	array( "chongo (Landon Curt Noll) /\\../\\", "5036a251" ),
105	array( "chongo (Landon Curt Noll) /\\../\\\0", "97018583" ),
106	array( "http://antwrp.gsfc.nasa.gov/apod/astropix.html", "b4448d60" ),
107	array( "http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash", "025dfe59" ),
108	array( "http://epod.usra.edu/", "c5eab3af" ),
109	array( "http://exoplanet.eu/", "7d21ba1e" ),
110	array( "http://hvo.wr.usgs.gov/cam3/", "7704cddb" ),
111	array( "http://hvo.wr.usgs.gov/cams/HMcam/", "d0071bfe" ),
112	array( "http://hvo.wr.usgs.gov/kilauea/update/deformation.html", "0ff3774c" ),
113	array( "http://hvo.wr.usgs.gov/kilauea/update/images.html", "b0fea0ea" ),
114	array( "http://hvo.wr.usgs.gov/kilauea/update/maps.html", "58177303" ),
115	array( "http://hvo.wr.usgs.gov/volcanowatch/current_issue.html", "4f599cda" ),
116	array( "http://neo.jpl.nasa.gov/risk/", "3e590a47" ),
117	array( "http://norvig.com/21-days.html", "965595f8" ),
118	array( "http://primes.utm.edu/curios/home.php", "c37f178d" ),
119	array( "http://slashdot.org/", "9711dd26" ),
120	array( "http://tux.wr.usgs.gov/Maps/155.25-19.5.html", "23c99b7f" ),
121	array( "http://volcano.wr.usgs.gov/kilaueastatus.php", "6e568b17" ),
122	array( "http://www.avo.alaska.edu/activity/Redoubt.php", "43f0245b" ),
123	array( "http://www.dilbert.com/fast/", "bcb7a001" ),
124	array( "http://www.fourmilab.ch/gravitation/orbits/", "12e6dffe" ),
125	array( "http://www.fpoa.net/", "0792f2d6" ),
126	array( "http://www.ioccc.org/index.html", "b966936b" ),
127	array( "http://www.isthe.com/cgi-bin/number.cgi", "46439ac5" ),
128	array( "http://www.isthe.com/chongo/bio.html", "728d49af" ),
129	array( "http://www.isthe.com/chongo/index.html", "d33745c9" ),
130	array( "http://www.isthe.com/chongo/src/calc/lucas-calc", "bc382a57" ),
131	array( "http://www.isthe.com/chongo/tech/astro/venus2004.html", "4bda1d31" ),
132	array( "http://www.isthe.com/chongo/tech/astro/vita.html", "ce35ccae" ),
133	array( "http://www.isthe.com/chongo/tech/comp/c/expert.html", "3b6eed94" ),
134	array( "http://www.isthe.com/chongo/tech/comp/calc/index.html", "445c9c58" ),
135	array( "http://www.isthe.com/chongo/tech/comp/fnv/index.html", "3db8bf9d" ),
136	array( "http://www.isthe.com/chongo/tech/math/number/howhigh.html", "2dee116d" ),
137	array( "http://www.isthe.com/chongo/tech/math/number/number.html", "c18738da" ),
138	array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html", "5b156176" ),
139	array( "http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest", "2aa7d593" ),
140	array( "http://www.lavarnd.org/cgi-bin/corpspeak.cgi", "b2409658" ),
141	array( "http://www.lavarnd.org/cgi-bin/haiku.cgi", "e1489528" ),
142	array( "http://www.lavarnd.org/cgi-bin/rand-none.cgi", "fe1ee07e" ),
143	array( "http://www.lavarnd.org/cgi-bin/randdist.cgi", "e8842315" ),
144	array( "http://www.lavarnd.org/index.html", "3a6a63a2" ),
145	array( "http://www.lavarnd.org/what/nist-test.html", "06d2c18c" ),
146	array( "http://www.macosxhints.com/", "f8ef7225" ),
147	array( "http://www.mellis.com/", "843d3300" ),
148	array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm", "bb24f7ae" ),
149	array( "http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm", "878c0ec9" ),
150	array( "http://www.paulnoll.com/", "b557810f" ),
151	array( "http://www.pepysdiary.com/", "57423246" ),
152	array( "http://www.sciencenews.org/index/home/activity/view", "87f7505e" ),
153	array( "http://www.skyandtelescope.com/", "bb809f20" ),
154	array( "http://www.sput.nl/~rob/sirius.html", "8932abb5" ),
155	array( "http://www.systemexperts.com/", "0a9b3aa0" ),
156	array( "http://www.tq-international.com/phpBB3/index.php", "b8682a24" ),
157	array( "http://www.travelquesttours.com/index.htm", "a7ac1c56" ),
158	array( "http://www.wunderground.com/global/stations/89606.html", "11409252" ),
159	array( R10("21701"), "a987f517" ),
160	array( R10("M21701"), "f309e7ed" ),
161	array( R10("2^21701-1"), "c9e8f417" ),
162	array( R10("\x54\xc5"), "7f447bdd" ),
163	array( R10("\xc5\x54"), "b929adc5" ),
164	array( R10("23209"), "57022879" ),
165	array( R10("M23209"), "dcfd2c49" ),
166	array( R10("2^23209-1"), "6edafff5" ),
167	array( R10("\x5a\xa9"), "f04fb1f1" ),
168	array( R10("\xa9\x5a"), "fb7de8b9" ),
169	array( R10("391581216093"), "c5f1d7e9" ),
170	array( R10("391581*2^216093-1"), "32c1f439" ),
171	array( R10("\x05\xf9\x9d\x03\x4c\x81"), "7fd3eb7d" ),
172	array( R10("FEDCBA9876543210"), "81597da5" ),
173	array( R10("\xfe\xdc\xba\x98\x76\x54\x32\x10"), "05eb7a25" ),
174	array( R10("EFCDAB8967452301"), "9c0fa1b5" ),
175	array( R10("\xef\xcd\xab\x89\x67\x45\x23\x01"), "53ccb1c5" ),
176	array( R10("0123456789ABCDEF"), "fabece15" ),
177	array( R10("\x01\x23\x45\x67\x89\xab\xcd\xef"), "4ad745a5" ),
178	array( R10("1032547698BADCFE"), "e5bdc495" ),
179	array( R10("\x10\x32\x54\x76\x98\xba\xdc\xfe"), "23b3c0a5" ),
180	array( R500("\x00"), "fa823dd5" ),
181	array( R500("\x07"), "0c6c58b9" ),
182	array( R500("~"), "e2dbccd5" ),
183	array( R500("\x7f"), "db7f50f9" ),
184);
185
186$i = 0;
187$pass = true;
188foreach($tests as $test) {
189	$result = hash('fnv132', $test[0]);
190	if ($result != $test[1]) {
191		echo "Iteration " . $i . " failed - expected '" . $test[1] . "', got '" . $result . "' for '" . $test[1] . "'\n";
192        $pass = false;
193	}
194	$i++;
195}
196
197if($pass) {
198    echo "PASS";
199}
200?>
201--EXPECT--
202PASS
203