1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/version.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(VersionTest
, DefaultConstructor
) {
13 EXPECT_FALSE(v
.IsValid());
16 TEST(VersionTest
, ValueSemantics
) {
17 Version
v1("1.2.3.4");
18 EXPECT_TRUE(v1
.IsValid());
20 EXPECT_FALSE(v3
.IsValid());
24 EXPECT_TRUE(v2
.IsValid());
25 EXPECT_TRUE(v1
.Equals(v2
));
27 EXPECT_TRUE(v3
.Equals(v1
));
30 TEST(VersionTest
, GetVersionFromString
) {
31 static const struct version_string
{
46 {"65537.0", 0, false},
49 {"1,--1.0", 0, false},
55 {"1.2.3.4.5.6.7.8.9.0", 10, true},
59 {"15.007.20011", 3, true},
62 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
63 Version
version(cases
[i
].input
);
64 EXPECT_EQ(cases
[i
].success
, version
.IsValid());
66 EXPECT_EQ(cases
[i
].parts
, version
.components().size());
70 TEST(VersionTest
, Compare
) {
71 static const struct version_compare
{
85 {"1.0.3", "1.0.20", -1},
86 {"11.0.10", "15.007.20011", -1},
88 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
89 Version
lhs(cases
[i
].lhs
);
90 Version
rhs(cases
[i
].rhs
);
91 EXPECT_EQ(lhs
.CompareTo(rhs
), cases
[i
].expected
) <<
92 cases
[i
].lhs
<< " ? " << cases
[i
].rhs
;
94 EXPECT_EQ(lhs
.IsOlderThan(cases
[i
].rhs
), (cases
[i
].expected
== -1));
98 TEST(VersionTest
, CompareToWildcardString
) {
99 static const struct version_compare
{
107 {"1.2.3", "1.2.3.*", 0},
108 {"10.0", "1.0.*", 1},
109 {"1.0", "3.0.*", -1},
110 {"1.4", "1.3.0.*", 1},
111 {"1.3.9", "1.3.*", 0},
112 {"1.4.1", "1.3.*", 1},
113 {"1.3", "1.4.5.*", -1},
114 {"1.5", "1.4.5.*", 1},
115 {"1.3.9", "1.3.*", 0},
116 {"1.2.0.0.0.0", "1.2.*", 0},
118 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
119 const Version
version(cases
[i
].lhs
);
120 const int result
= version
.CompareToWildcardString(cases
[i
].rhs
);
121 EXPECT_EQ(result
, cases
[i
].expected
) << cases
[i
].lhs
<< "?" << cases
[i
].rhs
;
125 TEST(VersionTest
, IsValidWildcardString
) {
126 static const struct version_compare
{
132 {"1.2.3.4.5.6", true},
135 {"1.2.3.56*", false},
142 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
143 EXPECT_EQ(Version::IsValidWildcardString(cases
[i
].version
),
144 cases
[i
].expected
) << cases
[i
].version
<< "?" << cases
[i
].expected
;