Remove --enable-hidpi-pdf-plugin flags, enable by default
[chromium-blink-merge.git] / base / version_unittest.cc
blob15f3052595c2446702e92f584a69155b7b0a5053
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) {
13 Version v;
14 EXPECT_FALSE(v.IsValid());
17 TEST_F(VersionTest, ValueSemantics) {
18 Version v1("1.2.3.4");
19 EXPECT_TRUE(v1.IsValid());
20 Version v3;
21 EXPECT_FALSE(v3.IsValid());
23 Version v2(v1);
24 v3 = v2;
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 {
33 const char* input;
34 size_t parts;
35 bool success;
36 } cases[] = {
37 {"", 0, false},
38 {" ", 0, false},
39 {"\t", 0, false},
40 {"\n", 0, false},
41 {" ", 0, false},
42 {".", 0, false},
43 {" . ", 0, false},
44 {"0", 1, true},
45 {"0.0", 2, true},
46 {"65537.0", 0, false},
47 {"-1.0", 0, false},
48 {"1.-1.0", 0, false},
49 {"+1.0", 0, false},
50 {"1.+1.0", 0, false},
51 {"1.0a", 0, false},
52 {"1.2.3.4.5.6.7.8.9.0", 10, true},
53 {"02.1", 0, false},
54 {"f.1", 0, false},
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());
60 if (cases[i].success)
61 EXPECT_EQ(cases[i].parts, version.components().size());
65 TEST_F(VersionTest, Compare) {
66 static const struct version_compare {
67 const char* lhs;
68 const char* rhs;
69 int expected;
70 } cases[] = {
71 {"1.0", "1.0", 0},
72 {"1.0", "0.0", 1},
73 {"1.0", "2.0", -1},
74 {"1.0", "1.1", -1},
75 {"1.1", "1.0", 1},
76 {"1.0", "1.0.1", -1},
77 {"1.1", "1.0.1", 1},
78 {"1.1", "1.0.1", 1},
79 {"1.0.0", "1.0", 0},
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 {
94 const char* lhs;
95 const char* rhs;
96 int expected;
97 } cases[] = {
98 {"1.0", "1.*", 0},
99 {"1.0", "0.*", 1},
100 {"1.0", "2.*", -1},
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 {
121 const char* version;
122 bool expected;
123 } cases[] = {
124 {"1.0", true},
125 {"", false},
126 {"1.2.3.4.5.6", true},
127 {"1.2.3.*", true},
128 {"1.2.3.5*", false},
129 {"1.2.3.56*", false},
130 {"1.*.3", false},
131 {"20.*", true},
132 {"+2.*", false},
133 {"*", false},
134 {"*.2", 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;