2023-02-27 13:40:20 +01:00
|
|
|
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
|
2022-12-16 12:43:51 +01:00
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
struct testcase {
|
|
|
|
int rc;
|
|
|
|
char *version;
|
|
|
|
int tuple[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
struct testcase cases[] = {
|
|
|
|
/* Good */
|
|
|
|
{ 0, "0.0.0", { 0, 0, 0 } },
|
|
|
|
{ 0, "1.0.0", { 1, 0, 0 } },
|
|
|
|
{ 0, "0.1.0", { 0, 1, 0 } },
|
|
|
|
{ 0, "0.0.1", { 0, 0, 1 } },
|
|
|
|
{ 0, "1.2.3-rc1", { 1, 2, 3 } },
|
|
|
|
/* Bad */
|
|
|
|
{ -1, "-1.0.0", { 0, 0, 0 } },
|
|
|
|
{ -1, "1.2", { 0, 0, 0 } },
|
|
|
|
{ -1, "1", { 0, 0, 0 } },
|
|
|
|
{ -1, "1.O.O", { 0, 0, 0 } },
|
|
|
|
{ -1, "1.2.3rc", { 0, 0, 0 } },
|
2022-12-16 12:47:19 +01:00
|
|
|
{ -1, NULL, { 0, 0, 0 } },
|
2022-12-16 12:43:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int n = sizeof(cases) / sizeof(cases[0]);
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
struct testcase *c = &cases[i];
|
|
|
|
int tuple[3] = { 0 };
|
|
|
|
|
|
|
|
if (version_parse(c->version, tuple) != c->rc)
|
2023-03-21 16:09:01 +01:00
|
|
|
die("wrong return value");
|
2022-12-16 12:43:51 +01:00
|
|
|
|
|
|
|
if (c->rc != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
if (tuple[j] != c->tuple[j])
|
2023-03-21 16:09:01 +01:00
|
|
|
die("wrong parsed version");
|
2022-12-16 12:43:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 18:51:18 +01:00
|
|
|
err("ok");
|
|
|
|
|
2022-12-16 12:43:51 +01:00
|
|
|
return 0;
|
|
|
|
}
|