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
{
45 {"65537.0", 0, false},
51 {"1.2.3.4.5.6.7.8.9.0", 10, true},
56 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
57 Version
version(cases
[i
].input
);
58 EXPECT_EQ(cases
[i
].success
, version
.IsValid());
60 EXPECT_EQ(cases
[i
].parts
, version
.components().size());
64 TEST(VersionTest
, Compare
) {
65 static const struct version_compare
{
79 {"1.0.3", "1.0.20", -1},
81 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
82 Version
lhs(cases
[i
].lhs
);
83 Version
rhs(cases
[i
].rhs
);
84 EXPECT_EQ(lhs
.CompareTo(rhs
), cases
[i
].expected
) <<
85 cases
[i
].lhs
<< " ? " << cases
[i
].rhs
;
87 EXPECT_EQ(lhs
.IsOlderThan(cases
[i
].rhs
), (cases
[i
].expected
== -1));
91 TEST(VersionTest
, CompareToWildcardString
) {
92 static const struct version_compare
{
100 {"1.2.3", "1.2.3.*", 0},
101 {"10.0", "1.0.*", 1},
102 {"1.0", "3.0.*", -1},
103 {"1.4", "1.3.0.*", 1},
104 {"1.3.9", "1.3.*", 0},
105 {"1.4.1", "1.3.*", 1},
106 {"1.3", "1.4.5.*", -1},
107 {"1.5", "1.4.5.*", 1},
108 {"1.3.9", "1.3.*", 0},
109 {"1.2.0.0.0.0", "1.2.*", 0},
111 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
112 const Version
version(cases
[i
].lhs
);
113 const int result
= version
.CompareToWildcardString(cases
[i
].rhs
);
114 EXPECT_EQ(result
, cases
[i
].expected
) << cases
[i
].lhs
<< "?" << cases
[i
].rhs
;
118 TEST(VersionTest
, IsValidWildcardString
) {
119 static const struct version_compare
{
125 {"1.2.3.4.5.6", true},
128 {"1.2.3.56*", false},
135 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
136 EXPECT_EQ(Version::IsValidWildcardString(cases
[i
].version
),
137 cases
[i
].expected
) << cases
[i
].version
<< "?" << cases
[i
].expected
;