Mercurial > gnulib
annotate tests/test-gc-sha1.c @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
1 /* |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16366
diff
changeset
|
2 * Copyright (C) 2005, 2010-2013 Free Software Foundation, Inc. |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
3 * Written by Simon Josefsson |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
4 * |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
12520
e84eea643139
tests: fix license on several tests
Eric Blake <ebb9@byu.net>
parents:
12421
diff
changeset
|
7 * the Free Software Foundation; either version 3, or (at your option) |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
8 * any later version. |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
9 * |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
14 * |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
16366
bb182ee4a09d
maint: replace FSF snail-mail addresses with URLs
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
16 * along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
17 |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
6436
diff
changeset
|
18 #include <config.h> |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
19 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
20 #include <stdio.h> |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
21 #include <string.h> |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
22 #include "gc.h" |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
23 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
24 int |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
25 main (int argc, char *argv[]) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
26 { |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
27 Gc_rc rc; |
6434 | 28 gc_hash_handle h; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
29 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
30 rc = gc_init (); |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
31 if (rc != GC_OK) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
32 { |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
33 printf ("gc_init() failed\n"); |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
34 return 1; |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
35 } |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
36 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
37 { |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
38 char *in = "abcdefgh"; |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
39 size_t inlen = strlen (in); |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
40 char *expect = "\x42\x5a\xf1\x2a\x07\x43\x50\x2b" |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
41 "\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a"; |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
42 char out[20]; |
6434 | 43 const char *p; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
44 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
45 if (gc_sha1 (in, inlen, out) != 0) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
46 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
47 printf ("gc_sha1 call failed\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
48 return 1; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
49 } |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
50 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
51 if (memcmp (out, expect, 20) != 0) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
52 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
53 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
54 printf ("sha1 mismatch. expected:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
55 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
56 printf ("%02x ", expect[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
57 printf ("\ncomputed:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
58 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
59 printf ("%02x ", out[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
60 printf ("\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
61 return 1; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
62 } |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
63 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
64 rc = gc_hash_buffer (GC_SHA1, "abcdefgh", 8, out); |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
65 if (rc != GC_OK) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
66 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
67 printf ("gc_hash_buffer(sha1) call failed: %d\n", rc); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
68 return 1; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
69 } |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
70 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
71 if (memcmp (out, expect, 20) != 0) |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
72 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
73 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
74 printf ("sha1' mismatch. expected:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
75 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
76 printf ("%02x ", expect[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
77 printf ("\ncomputed:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
78 for (i = 0; i < 16; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
79 printf ("%02x ", out[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
80 printf ("\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
81 return 1; |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
82 } |
6434 | 83 |
84 if (gc_hash_digest_length (GC_SHA1) != 20) | |
85 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
86 printf ("gc_hash_digest_length (GC_SHA1) failed\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
87 return 1; |
6434 | 88 } |
89 | |
90 if ((rc = gc_hash_open (GC_SHA1, 0, &h)) != GC_OK) | |
91 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
92 printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
93 return 1; |
6434 | 94 } |
95 | |
96 gc_hash_write (h, inlen, in); | |
97 | |
98 p = gc_hash_read (h); | |
99 | |
100 if (!p) | |
101 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
102 printf ("gc_hash_read failed\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
103 return 1; |
6434 | 104 } |
105 | |
106 if (memcmp (p, expect, 20) != 0) | |
107 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
108 size_t i; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
109 printf ("sha1 1 mismatch. expected:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
110 for (i = 0; i < 20; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
111 printf ("%02x ", expect[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
112 printf ("\ncomputed:\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
113 for (i = 0; i < 20; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
114 printf ("%02x ", p[i] & 0xFF); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
115 printf ("\n"); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
116 return 1; |
6434 | 117 } |
118 | |
119 gc_hash_close (h); | |
6388
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
120 } |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
121 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
122 gc_done (); |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
123 |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
124 return 0; |
f5c12a352291
Add gc-sha1-tests module.
Simon Josefsson <simon@josefsson.org>
parents:
diff
changeset
|
125 } |