Remove an old PangoFontDescription forward declaration.
[chromium-blink-merge.git] / base / version_unittest.cc
blob46d8255d15379d7a7553043e4bd1ab0972b6498b
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"
9 namespace {
11 TEST(VersionTest, DefaultConstructor) {
12 Version v;
13 EXPECT_FALSE(v.IsValid());
16 TEST(VersionTest, ValueSemantics) {
17 Version v1("1.2.3.4");
18 EXPECT_TRUE(v1.IsValid());
19 Version v3;
20 EXPECT_FALSE(v3.IsValid());
22 Version v2(v1);
23 v3 = v2;
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 {
32 const char* input;
33 size_t parts;
34 bool success;
35 } cases[] = {
36 {"", 0, false},
37 {" ", 0, false},
38 {"\t", 0, false},
39 {"\n", 0, false},
40 {" ", 0, false},
41 {".", 0, false},
42 {" . ", 0, false},
43 {"0", 1, true},
44 {"0.", 0, false},
45 {"0.0", 2, true},
46 {"65537.0", 0, false},
47 {"-1.0", 0, false},
48 {"1.-1.0", 0, false},
49 {"1,--1.0", 0, false},
50 {"+1.0", 0, false},
51 {"1.+1.0", 0, false},
52 {"1+1.0", 0, false},
53 {"++1.0", 0, false},
54 {"1.0a", 0, false},
55 {"1.2.3.4.5.6.7.8.9.0", 10, true},
56 {"02.1", 0, false},
57 {"0.01", 2, true},
58 {"f.1", 0, false},
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());
65 if (cases[i].success)
66 EXPECT_EQ(cases[i].parts, version.components().size());
70 TEST(VersionTest, Compare) {
71 static const struct version_compare {
72 const char* lhs;
73 const char* rhs;
74 int expected;
75 } cases[] = {
76 {"1.0", "1.0", 0},
77 {"1.0", "0.0", 1},
78 {"1.0", "2.0", -1},
79 {"1.0", "1.1", -1},
80 {"1.1", "1.0", 1},
81 {"1.0", "1.0.1", -1},
82 {"1.1", "1.0.1", 1},
83 {"1.1", "1.0.1", 1},
84 {"1.0.0", "1.0", 0},
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 {
100 const char* lhs;
101 const char* rhs;
102 int expected;
103 } cases[] = {
104 {"1.0", "1.*", 0},
105 {"1.0", "0.*", 1},
106 {"1.0", "2.*", -1},
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 {
127 const char* version;
128 bool expected;
129 } cases[] = {
130 {"1.0", true},
131 {"", false},
132 {"1.2.3.4.5.6", true},
133 {"1.2.3.*", true},
134 {"1.2.3.5*", false},
135 {"1.2.3.56*", false},
136 {"1.*.3", false},
137 {"20.*", true},
138 {"+2.*", false},
139 {"*", false},
140 {"*.2", 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;
148 } // namespace