]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_versioncmp.c
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / lib / test_versioncmp.c
1 /*
2 * frr_version_cmp() tests
3 * Copyright (C) 2018 David Lamparter for NetDEF, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include <zebra.h>
20 #include <defaults.h>
21
22 static const char *rel(int x)
23 {
24 if (x < 0)
25 return "<";
26 if (x > 0)
27 return ">";
28 return "==";
29 }
30
31 static int fail;
32
33 static void compare(const char *a, const char *b, int expect)
34 {
35 int result = frr_version_cmp(a, b);
36
37 if (expect == result)
38 printf("\"%s\" %s \"%s\"\n", a, rel(result), b);
39 else {
40 printf("\"%s\" %s \"%s\", expected %s!\n", a, rel(result), b,
41 rel(expect));
42 fail = 1;
43 }
44 }
45
46 int main(int argc, char **argv)
47 {
48 compare("", "", 0);
49 compare("1", "1", 0);
50 compare("1.0", "1.00", 0);
51 compare("10.0", "1", 1);
52 compare("10.0", "2", 1);
53 compare("2.1", "10.0", -1);
54 compare("1.1.1", "1.1.0", 1);
55 compare("1.0a", "1.0", 1);
56 compare("1.0a", "1.0b", -1);
57 compare("1.0a10", "1.0a2", 1);
58 compare("1.00a2", "1.0a2", 0);
59 compare("1.00a2", "1.0a3", -1);
60 compare("1.0-dev", "1.0", 1);
61 compare("1.0~foo", "1.0", -1);
62 compare("1.0~1", "1.0~0", 1);
63 compare("1.00~1", "1.0~0", 1);
64 printf("final tally: %s\n", fail ? "FAILED" : "ok");
65 return fail;
66 }