]> sigrok.org Git - libsigrok.git/blame - tests/version.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / tests / version.c
CommitLineData
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
2ea1fdf1 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
71185b48
UH
18 */
19
6ec6c43b 20#include <config.h>
71185b48
UH
21#include <stdlib.h>
22#include <check.h>
4960aeb0 23#include <libsigrok/libsigrok.h>
17794067 24#include "lib.h"
71185b48
UH
25
26/*
27 * Check the version number API calls and macros.
28 *
29 * The numbers returned by the sr_*_version*get() calls must match the
30 * respective SR_*_VERSION* macro values, must be >= 0, and must not be
31 * unreasonably high (> 20), otherwise something is probably wrong.
32 */
33START_TEST(test_version_numbers)
34{
35 int ver;
36
37 ver = sr_package_version_major_get();
38 fail_unless(ver == SR_PACKAGE_VERSION_MAJOR);
39 fail_unless(ver >= 0 && ver <= 20);
40 ver = sr_package_version_minor_get();
41 fail_unless(ver == SR_PACKAGE_VERSION_MINOR);
42 fail_unless(ver >= 0 && ver <= 20);
43 ver = sr_package_version_micro_get();
44 fail_unless(ver == SR_PACKAGE_VERSION_MICRO);
45 fail_unless(ver >= 0 && ver <= 20);
46
47 ver = sr_lib_version_current_get();
48 fail_unless(ver == SR_LIB_VERSION_CURRENT);
49 fail_unless(ver >= 0 && ver <= 20);
50 ver = sr_lib_version_revision_get();
51 fail_unless(ver == SR_LIB_VERSION_REVISION);
52 fail_unless(ver >= 0 && ver <= 20);
53 ver = sr_lib_version_age_get();
54 fail_unless(ver == SR_LIB_VERSION_AGE);
55 fail_unless(ver >= 0 && ver <= 20);
56}
57END_TEST
58
59/*
60 * Check the version number API calls and macros.
61 *
3cc20283
GS
62 * The string representations of the package/lib version must neither be
63 * NULL nor empty, and the length shall be within an expected range.
64 *
65 * The lower limit assumes:
66 * - A version text consists of three parts (major, minor, micro),
67 * like "0.1.0".
68 * - Three numbers with at least one digit, and their separators,
69 * result in a minimum length of 5.
70 *
71 * The upper limit assumes:
72 * - The major, minor, and micro parts won't contain more than two
f3bca6d9
GS
73 * digits each (this is an arbitrary choice). The three numbers
74 * are separated by a period character.
3cc20283
GS
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.
f3bca6d9 80 * - An optional "-dirty" suffix might follow.
71185b48
UH
81 */
82START_TEST(test_version_strings)
83{
84 const char *str;
3cc20283 85 const size_t len_min = 5;
f3bca6d9 86 const size_t len_max = 2 + 1 + 2 + 1 + 2 + 5 + 12 + 6;
71185b48
UH
87
88 str = sr_package_version_string_get();
89 fail_unless(str != NULL);
3cc20283 90 fail_unless(strlen(str) >= len_min);
f3bca6d9
GS
91 fail_unless(strlen(str) <= len_max,
92 "Max len exceeded, max %zu, text %s", len_max, str);
71185b48
UH
93 str = sr_lib_version_string_get();
94 fail_unless(str != NULL);
3cc20283 95 fail_unless(strlen(str) >= len_min);
f3bca6d9
GS
96 fail_unless(strlen(str) <= len_max,
97 "Max len exceeded, max %zu, text %s", len_max, str);
71185b48
UH
98}
99END_TEST
100
101Suite *suite_version(void)
102{
103 Suite *s;
104 TCase *tc;
105
106 s = suite_create("version");
107
108 tc = tcase_create("version");
109 tcase_add_test(tc, test_version_numbers);
110 tcase_add_test(tc, test_version_strings);
111 suite_add_tcase(s, tc);
112
113 return s;
114}