Mercurial > hg > octave-kai > gnulib-hg
annotate tests/test-filevercmp.c @ 12839:c6d23570567d
Work around getdelim() bug on FreeBSD 8.0.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 31 Jan 2010 17:43:25 +0100 |
parents | c2cbabec01dd |
children | 97fc9a21a8fb |
rev | line source |
---|---|
10573 | 1 /* Test of filevercmp() function. |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12496
diff
changeset
|
2 Copyright (C) 2008-2010 Free Software Foundation, Inc. |
10573 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | |
17 | |
18 #include <config.h> | |
19 | |
20 #include "filevercmp.h" | |
21 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
22 #include <stddef.h> |
10573 | 23 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
24 #include "macros.h" |
10573 | 25 |
26 /* set of well sorted examples */ | |
27 static const char *const examples[] = | |
28 { | |
11470
ecb28ce608f1
filevercmp: fix regression
Kamil Dudka <kdudka@redhat.com>
parents:
11429
diff
changeset
|
29 "", |
11266
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
30 ".", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
31 "..", |
11471
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
32 ".0", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
33 ".9", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
34 ".A", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
35 ".Z", |
11266
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
36 ".a~", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
37 ".a", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
38 ".b~", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
39 ".b", |
11471
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
40 ".z", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
41 ".zz~", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
42 ".zz", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
43 ".zz.~1~", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
44 ".zz.0", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
45 "0", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
46 "9", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
47 "A", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
48 "Z", |
11266
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
49 "a~", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
50 "a", |
11429
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
51 "a.b~", |
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
52 "a.b", |
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
53 "a.bc~", |
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
54 "a.bc", |
11266
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
55 "b~", |
98bcf3f48aa7
filevercmp: Move hidden files up in ordering.
Kamil Dudka <kdudka@redhat.com>
parents:
10573
diff
changeset
|
56 "b", |
10573 | 57 "gcc-c++-10.fc9.tar.gz", |
11429
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
58 "gcc-c++-10.fc9.tar.gz.~1~", |
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
59 "gcc-c++-10.fc9.tar.gz.~2~", |
10573 | 60 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2", |
11429
a32a8b26323e
filevercmp: handle simple~ and numbered.~3~ backup suffixes
Kamil Dudka <kdudka@redhat.com>
parents:
11266
diff
changeset
|
61 "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2.~1~", |
10573 | 62 "glibc-2-0.1.beta1.fc10.rpm", |
63 "glibc-common-5-0.2.beta2.fc9.ebuild", | |
64 "glibc-common-5-0.2b.deb", | |
65 "glibc-common-11b.ebuild", | |
66 "glibc-common-11-0.6rc2.ebuild", | |
67 "libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz", | |
68 "libstdc++-4a.fc8.tar.gz", | |
69 "libstdc++-4.10.4.20040204svn.rpm", | |
70 "libstdc++-devel-3.fc8.ebuild", | |
71 "libstdc++-devel-3a.fc9.tar.gz", | |
72 "libstdc++-devel-8.fc8.deb", | |
73 "libstdc++-devel-8.6.2-0.4b.fc8", | |
74 "nss_ldap-1-0.2b.fc9.tar.bz2", | |
75 "nss_ldap-1-0.6rc2.fc8.tar.gz", | |
76 "nss_ldap-1.0-0.1a.tar.gz", | |
77 "nss_ldap-10beta1.fc8.tar.gz", | |
78 "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild", | |
11471
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
79 "z", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
80 "zz~", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
81 "zz", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
82 "zz.~1~", |
8557d9d3cace
filevercmp: correct today's change
Kamil Dudka <kdudka@redhat.com>
parents:
11470
diff
changeset
|
83 "zz.0", |
11470
ecb28ce608f1
filevercmp: fix regression
Kamil Dudka <kdudka@redhat.com>
parents:
11429
diff
changeset
|
84 "#.b#", |
10573 | 85 NULL |
86 }; | |
87 | |
88 int | |
12197
e45d9bb2233e
tests: avoid several compiler warnings
Eric Blake <ebb9@byu.net>
parents:
11471
diff
changeset
|
89 main (void) |
10573 | 90 { |
91 const char *const *i; | |
92 | |
93 /* Following tests taken from test-strverscmp.c */ | |
94 ASSERT (filevercmp ("", "") == 0); | |
95 ASSERT (filevercmp ("a", "a") == 0); | |
96 ASSERT (filevercmp ("a", "b") < 0); | |
97 ASSERT (filevercmp ("b", "a") > 0); | |
98 ASSERT (filevercmp ("a0", "a") > 0); | |
99 ASSERT (filevercmp ("00", "01") < 0); | |
100 ASSERT (filevercmp ("01", "010") < 0); | |
101 ASSERT (filevercmp ("9", "10") < 0); | |
102 ASSERT (filevercmp ("0a", "0") > 0); | |
103 | |
104 /* compare each version string with each other - O(n^2) */ | |
105 for (i = examples; *i; i++) | |
106 { | |
107 const char *const *j; | |
108 for (j = examples; *j; j++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
109 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
110 int result = filevercmp (*i, *j); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
111 if (result < 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
112 ASSERT (i < j); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
113 else if (0 < result) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
114 ASSERT (j < i); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
115 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
116 ASSERT (i == j); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12197
diff
changeset
|
117 } |
10573 | 118 } |
119 | |
120 return 0; | |
121 } |