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/memory/scoped_ptr.h"
6 #include "base/version.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 class VersionTest
: public testing::Test
{
12 TEST_F(VersionTest
, DefaultConstructor
) {
14 EXPECT_FALSE(v
.IsValid());
17 TEST_F(VersionTest
, ValueSemantics
) {
18 Version
v1("1.2.3.4");
19 EXPECT_TRUE(v1
.IsValid());
21 EXPECT_FALSE(v3
.IsValid());
25 EXPECT_TRUE(v2
.IsValid());
26 EXPECT_TRUE(v1
.Equals(v2
));
28 EXPECT_TRUE(v3
.Equals(v1
));
31 TEST_F(VersionTest
, GetVersionFromString
) {
32 static const struct version_string
{
46 {"65537.0", 0, false},
52 {"1.2.3.4.5.6.7.8.9.0", 10, true},
57 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
58 Version
version(cases
[i
].input
);
59 EXPECT_EQ(cases
[i
].success
, version
.IsValid());
61 EXPECT_EQ(cases
[i
].parts
, version
.components().size());
65 TEST_F(VersionTest
, Compare
) {
66 static const struct version_compare
{
80 {"1.0.3", "1.0.20", -1},
82 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
83 Version
lhs(cases
[i
].lhs
);
84 Version
rhs(cases
[i
].rhs
);
85 EXPECT_EQ(lhs
.CompareTo(rhs
), cases
[i
].expected
) <<
86 cases
[i
].lhs
<< " ? " << cases
[i
].rhs
;
88 EXPECT_EQ(lhs
.IsOlderThan(cases
[i
].rhs
), (cases
[i
].expected
== -1));
92 TEST_F(VersionTest
, CompareToWildcardString
) {
93 static const struct version_compare
{
101 {"1.2.3", "1.2.3.*", 0},
102 {"10.0", "1.0.*", 1},
103 {"1.0", "3.0.*", -1},
104 {"1.4", "1.3.0.*", 1},
105 {"1.3.9", "1.3.*", 0},
106 {"1.4.1", "1.3.*", 1},
107 {"1.3", "1.4.5.*", -1},
108 {"1.5", "1.4.5.*", 1},
109 {"1.3.9", "1.3.*", 0},
110 {"1.2.0.0.0.0", "1.2.*", 0},
112 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
113 const Version
version(cases
[i
].lhs
);
114 const int result
= version
.CompareToWildcardString(cases
[i
].rhs
);
115 EXPECT_EQ(result
, cases
[i
].expected
) << cases
[i
].lhs
<< "?" << cases
[i
].rhs
;
119 TEST_F(VersionTest
, IsValidWildcardString
) {
120 static const struct version_compare
{
126 {"1.2.3.4.5.6", true},
129 {"1.2.3.56*", false},
136 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(cases
); ++i
) {
137 EXPECT_EQ(Version::IsValidWildcardString(cases
[i
].version
),
138 cases
[i
].expected
) << cases
[i
].version
<< "?" << cases
[i
].expected
;