Leosac  0.8.0
Open Source Access Control
version.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac 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 Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "tools/version.hpp"
21 #include "gtest/gtest.h"
22 
23 using namespace Leosac::Tools;
24 
25 namespace Leosac
26 {
27 namespace Test
28 {
29 
30 TEST(VersionTest, buildVersionString)
31 {
32  EXPECT_EQ("1.2.42", Version::buildVersionString(1, 2, 42));
33  EXPECT_EQ("0.0.0", Version::buildVersionString(0, 0, 0));
34 }
35 
36 TEST(VersionTest, versionCompare)
37 {
38  EXPECT_EQ(0, Version::versionCompare("0.1.0", "0.1.0"));
39  EXPECT_LT(Version::versionCompare("0.1.0", "0.666.0"), 0);
40  EXPECT_GT(Version::versionCompare("2.0.0", "1.0.0"), 0);
41  EXPECT_GT(Version::versionCompare("3.2.1", "1.2.3"), 0);
42 }
43 
44 TEST(VersionTest, isVersionValid)
45 {
46  EXPECT_TRUE(Version::isVersionValid("42.2.85"));
47  EXPECT_TRUE(Version::isVersionValid("42.2.85-c1953908880a88d8131b6782ae8ff4da89826959"));
48  EXPECT_FALSE(Version::isVersionValid("42.2.85-lama"));
49  EXPECT_FALSE(Version::isVersionValid(".42.2.85"));
50  EXPECT_FALSE(Version::isVersionValid("42.2."));
51  EXPECT_FALSE(Version::isVersionValid("42.200.11.00"));
52  EXPECT_FALSE(Version::isVersionValid("11..00"));
53 }
54 }
55 }
Leosac::Tools::Version::buildVersionString
static std::string buildVersionString(int major, int minor, int patch, std::string git_sha1="")
return semver compatible version string formatted this way: MAJOR.MINOR.PATCH
Definition: version.cpp:34
version.hpp
version handling
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::Version::versionCompare
static int versionCompare(std::string a, std::string b)
compare two version strings using semver v2.0.0
Definition: version.cpp:51
Leosac::Test::TEST
TEST(VersionTest, isVersionValid)
Definition: version.cpp:44
Leosac::Tools
Definition: DatabaseLogSink.hpp:27
Leosac::Tools::Version::isVersionValid
static bool isVersionValid(const std::string &v)
check validity of a semver version string
Definition: version.cpp:74