1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 #include "base/version.h"
31
32 #include "base/util.h"
33 #include "testing/base/public/gunit.h"
34
35 // Import the generated version_def.h.
36 #include "base/version_def.h"
37
38 namespace mozc {
39
TEST(VersionTest,BasicTest)40 TEST(VersionTest, BasicTest) {
41 EXPECT_EQ(version::kMozcVersion, Version::GetMozcVersion());
42 }
43
TEST(VersionTest,VersionNumberTest)44 TEST(VersionTest, VersionNumberTest) {
45 const int major = Version::GetMozcVersionMajor();
46 const int minor = Version::GetMozcVersionMinor();
47 const int build_number = Version::GetMozcVersionBuildNumber();
48 const int revision = Version::GetMozcVersionRevision();
49 EXPECT_EQ(Version::GetMozcVersion(), Util::StringPrintf(
50 "%d.%d.%d.%d", major, minor, build_number, revision));
51 }
52
TEST(VersionTest,CompareVersion)53 TEST(VersionTest, CompareVersion) {
54 EXPECT_FALSE(Version::CompareVersion("0.0.0.0", "0.0.0.0"));
55 EXPECT_FALSE(Version::CompareVersion("1.2.3.4", "1.2.3.4"));
56 EXPECT_TRUE(Version::CompareVersion("0.0.0.0", "0.0.0.1"));
57 EXPECT_TRUE(Version::CompareVersion("0.0.1.2", "0.1.2.3"));
58 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "5.2.3.4"));
59 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.5.3.4"));
60 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.2.5.4"));
61 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.2.3.5"));
62 EXPECT_FALSE(Version::CompareVersion("5.2.3.4", "1.2.3.4"));
63 EXPECT_FALSE(Version::CompareVersion("1.5.3.4", "1.2.3.4"));
64 EXPECT_FALSE(Version::CompareVersion("1.2.5.4", "1.2.3.4"));
65 EXPECT_FALSE(Version::CompareVersion("1.2.3.5", "1.2.3.4"));
66 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "15.2.3.4"));
67 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.25.3.4"));
68 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.2.35.4"));
69 EXPECT_TRUE(Version::CompareVersion("1.2.3.4", "1.2.3.45"));
70 EXPECT_FALSE(Version::CompareVersion("15.2.3.4", "1.2.3.4"));
71 EXPECT_FALSE(Version::CompareVersion("1.25.3.4", "1.2.3.4"));
72 EXPECT_FALSE(Version::CompareVersion("1.2.35.4", "1.2.3.4"));
73 EXPECT_FALSE(Version::CompareVersion("1.2.3.45", "1.2.3.4"));
74
75 // Always return false if "Unknown" is passed.
76 EXPECT_FALSE(Version::CompareVersion("Unknown", "Unknown"));
77 EXPECT_FALSE(Version::CompareVersion("0.0.0.0", "(Unknown)"));
78 EXPECT_FALSE(Version::CompareVersion("Unknown", "0.0.0.0"));
79 EXPECT_FALSE(Version::CompareVersion("0.0.0.0", "Unknown"));
80 EXPECT_FALSE(Version::CompareVersion("(Unknown)", "(Unknown)"));
81 EXPECT_FALSE(Version::CompareVersion("(Unknown)", "0.0.0.0"));
82 }
83
84 } // namespace mozc
85