]>
Commit | Line | Data |
---|---|---|
71185b48 UH |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
6ec6c43b | 21 | #include <config.h> |
71185b48 UH |
22 | #include <stdlib.h> |
23 | #include <check.h> | |
4960aeb0 | 24 | #include <libsigrok/libsigrok.h> |
17794067 | 25 | #include "lib.h" |
71185b48 UH |
26 | |
27 | /* | |
28 | * Check the version number API calls and macros. | |
29 | * | |
30 | * The numbers returned by the sr_*_version*get() calls must match the | |
31 | * respective SR_*_VERSION* macro values, must be >= 0, and must not be | |
32 | * unreasonably high (> 20), otherwise something is probably wrong. | |
33 | */ | |
34 | START_TEST(test_version_numbers) | |
35 | { | |
36 | int ver; | |
37 | ||
38 | ver = sr_package_version_major_get(); | |
39 | fail_unless(ver == SR_PACKAGE_VERSION_MAJOR); | |
40 | fail_unless(ver >= 0 && ver <= 20); | |
41 | ver = sr_package_version_minor_get(); | |
42 | fail_unless(ver == SR_PACKAGE_VERSION_MINOR); | |
43 | fail_unless(ver >= 0 && ver <= 20); | |
44 | ver = sr_package_version_micro_get(); | |
45 | fail_unless(ver == SR_PACKAGE_VERSION_MICRO); | |
46 | fail_unless(ver >= 0 && ver <= 20); | |
47 | ||
48 | ver = sr_lib_version_current_get(); | |
49 | fail_unless(ver == SR_LIB_VERSION_CURRENT); | |
50 | fail_unless(ver >= 0 && ver <= 20); | |
51 | ver = sr_lib_version_revision_get(); | |
52 | fail_unless(ver == SR_LIB_VERSION_REVISION); | |
53 | fail_unless(ver >= 0 && ver <= 20); | |
54 | ver = sr_lib_version_age_get(); | |
55 | fail_unless(ver == SR_LIB_VERSION_AGE); | |
56 | fail_unless(ver >= 0 && ver <= 20); | |
57 | } | |
58 | END_TEST | |
59 | ||
60 | /* | |
61 | * Check the version number API calls and macros. | |
62 | * | |
3cc20283 GS |
63 | * The string representations of the package/lib version must neither be |
64 | * NULL nor empty, and the length shall be within an expected range. | |
65 | * | |
66 | * The lower limit assumes: | |
67 | * - A version text consists of three parts (major, minor, micro), | |
68 | * like "0.1.0". | |
69 | * - Three numbers with at least one digit, and their separators, | |
70 | * result in a minimum length of 5. | |
71 | * | |
72 | * The upper limit assumes: | |
73 | * - The major, minor, and micro parts won't contain more than two | |
74 | * digits each (this is an arbitrary choice). | |
75 | * - An optional "-git-<hash>" suffix might follow. While git(1) | |
76 | * defaults to 7 hex digits for abbreviated hashes, projects of | |
77 | * larger scale might recommend to use more digits to avoid | |
78 | * potential ambiguity (e.g. Linux recommends core.abbrev=12). | |
79 | * Again, this is an arbitrary choice. | |
71185b48 UH |
80 | */ |
81 | START_TEST(test_version_strings) | |
82 | { | |
83 | const char *str; | |
3cc20283 GS |
84 | const size_t len_min = 5; |
85 | const size_t len_max = 2 + 1 + 2 + 1 + 2 + 5 + 12; | |
71185b48 UH |
86 | |
87 | str = sr_package_version_string_get(); | |
88 | fail_unless(str != NULL); | |
3cc20283 GS |
89 | fail_unless(strlen(str) >= len_min); |
90 | fail_unless(strlen(str) <= len_max); | |
71185b48 UH |
91 | str = sr_lib_version_string_get(); |
92 | fail_unless(str != NULL); | |
3cc20283 GS |
93 | fail_unless(strlen(str) >= len_min); |
94 | fail_unless(strlen(str) <= len_max); | |
71185b48 UH |
95 | } |
96 | END_TEST | |
97 | ||
98 | Suite *suite_version(void) | |
99 | { | |
100 | Suite *s; | |
101 | TCase *tc; | |
102 | ||
103 | s = suite_create("version"); | |
104 | ||
105 | tc = tcase_create("version"); | |
106 | tcase_add_test(tc, test_version_numbers); | |
107 | tcase_add_test(tc, test_version_strings); | |
108 | suite_add_tcase(s, tc); | |
109 | ||
110 | return s; | |
111 | } |