Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | /* |
2 | * libdpkg - Debian packaging suite library routines | |
3 | * t-deb-version.c - test deb version handling | |
4 | * | |
5 | * Copyright © 2012 Guillem Jover <guillem@debian.org> | |
6 | * | |
7 | * This is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | #include <config.h> | |
22 | #include <compat.h> | |
23 | ||
24 | #include <limits.h> | |
25 | #include <stdio.h> | |
26 | ||
27 | #include <dpkg/test.h> | |
28 | #include <dpkg/deb-version.h> | |
29 | ||
30 | static void | |
31 | test_deb_version_parse(void) | |
32 | { | |
33 | struct deb_version v; | |
34 | char *vs; | |
35 | ||
36 | /* Test valid versions. */ | |
37 | test_pass(deb_version_parse(&v, "0.0") == NULL); | |
38 | test_pass(v.major == 0 && v.minor == 0); | |
39 | ||
40 | test_pass(deb_version_parse(&v, "1.1") == NULL); | |
41 | test_pass(v.major == 1 && v.minor == 1); | |
42 | ||
43 | test_pass(deb_version_parse(&v, "1.001") == NULL); | |
44 | test_pass(v.major == 1 && v.minor == 1); | |
45 | ||
46 | test_pass(deb_version_parse(&v, "1.0010") == NULL); | |
47 | test_pass(v.major == 1 && v.minor == 10); | |
48 | ||
49 | test_pass(deb_version_parse(&v, "0.939000") == NULL); | |
50 | test_pass(v.major == 0 && v.minor == 939000); | |
51 | ||
52 | test_pass(deb_version_parse(&v, "1.1\n") == NULL); | |
53 | test_pass(v.major == 1 && v.minor == 1); | |
54 | ||
55 | /* Test invalid versions. */ | |
56 | test_fail(deb_version_parse(&v, "0") == NULL); | |
57 | test_fail(deb_version_parse(&v, "a") == NULL); | |
58 | test_fail(deb_version_parse(&v, "a.b") == NULL); | |
59 | test_fail(deb_version_parse(&v, "a~b") == NULL); | |
60 | test_fail(deb_version_parse(&v, " 1.1") == NULL); | |
61 | test_fail(deb_version_parse(&v, "2 .2") == NULL); | |
62 | test_fail(deb_version_parse(&v, "3. 3") == NULL); | |
63 | test_fail(deb_version_parse(&v, "4.4 ") == NULL); | |
64 | test_fail(deb_version_parse(&v, " 5.5 ") == NULL); | |
65 | ||
66 | /* Test integer limits. */ | |
67 | if (asprintf(&vs, "%d.0", INT_MAX) < 0) | |
68 | test_bail("cannot allocate memory for asprintf()"); | |
69 | test_pass(deb_version_parse(&v, vs) == NULL); | |
70 | free(vs); | |
71 | ||
72 | if (asprintf(&vs, "%d.0", INT_MAX - 1) < 0) | |
73 | test_bail("cannot allocate memory for asprintf()"); | |
74 | test_pass(deb_version_parse(&v, vs) == NULL); | |
75 | free(vs); | |
76 | ||
77 | if (asprintf(&vs, "%u.0", 1U + (unsigned int)INT_MAX) < 0) | |
78 | test_bail("cannot allocate memory for asprintf()"); | |
79 | test_fail(deb_version_parse(&v, vs) == NULL); | |
80 | free(vs); | |
81 | ||
82 | /* FIXME: Complete. */ | |
83 | } | |
84 | ||
85 | TEST_ENTRY(test) | |
86 | { | |
87 | test_plan(24); | |
88 | ||
89 | test_deb_version_parse(); | |
90 | } |