Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: base/version_unittest.cc

Issue 1575523002: Comparison and streaming operators for base::Version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes mistake in previous patch set. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/version.cc ('k') | chrome/app/chrome_crash_reporter_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/version.h" 5 #include "base/version.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 TEST(VersionTest, DefaultConstructor) { 15 TEST(VersionTest, DefaultConstructor) {
16 Version v; 16 Version v;
17 EXPECT_FALSE(v.IsValid()); 17 EXPECT_FALSE(v.IsValid());
18 } 18 }
19 19
20 TEST(VersionTest, ValueSemantics) { 20 TEST(VersionTest, ValueSemantics) {
21 Version v1("1.2.3.4"); 21 Version v1("1.2.3.4");
22 EXPECT_TRUE(v1.IsValid()); 22 EXPECT_TRUE(v1.IsValid());
23 Version v3; 23 Version v3;
24 EXPECT_FALSE(v3.IsValid()); 24 EXPECT_FALSE(v3.IsValid());
25 { 25 {
26 Version v2(v1); 26 Version v2(v1);
27 v3 = v2; 27 v3 = v2;
28 EXPECT_TRUE(v2.IsValid()); 28 EXPECT_TRUE(v2.IsValid());
29 EXPECT_TRUE(v1.Equals(v2)); 29 EXPECT_EQ(v1, v2);
30 } 30 }
31 EXPECT_TRUE(v3.Equals(v1)); 31 EXPECT_EQ(v3, v1);
32 } 32 }
33 33
34 TEST(VersionTest, GetVersionFromString) { 34 TEST(VersionTest, GetVersionFromString) {
35 static const struct version_string { 35 static const struct version_string {
36 const char* input; 36 const char* input;
37 size_t parts; 37 size_t parts;
38 uint32_t firstpart; 38 uint32_t firstpart;
39 bool success; 39 bool success;
40 } cases[] = { 40 } cases[] = {
41 {"", 0, 0, false}, 41 {"", 0, 0, false},
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 {"1.0.3", "1.0.20", -1}, 94 {"1.0.3", "1.0.20", -1},
95 {"11.0.10", "15.007.20011", -1}, 95 {"11.0.10", "15.007.20011", -1},
96 {"11.0.10", "15.5.28.130162", -1}, 96 {"11.0.10", "15.5.28.130162", -1},
97 }; 97 };
98 for (size_t i = 0; i < arraysize(cases); ++i) { 98 for (size_t i = 0; i < arraysize(cases); ++i) {
99 Version lhs(cases[i].lhs); 99 Version lhs(cases[i].lhs);
100 Version rhs(cases[i].rhs); 100 Version rhs(cases[i].rhs);
101 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) << 101 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) <<
102 cases[i].lhs << " ? " << cases[i].rhs; 102 cases[i].lhs << " ? " << cases[i].rhs;
103 103
104 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1)); 104 // Test comparison operators
105 switch (cases[i].expected) {
106 case -1:
107 EXPECT_LT(lhs, rhs);
108 EXPECT_LE(lhs, rhs);
109 EXPECT_NE(lhs, rhs);
110 EXPECT_FALSE(lhs == rhs);
111 EXPECT_FALSE(lhs >= rhs);
112 EXPECT_FALSE(lhs > rhs);
113 break;
114 case 0:
115 EXPECT_FALSE(lhs < rhs);
116 EXPECT_LE(lhs, rhs);
117 EXPECT_FALSE(lhs != rhs);
118 EXPECT_EQ(lhs, rhs);
119 EXPECT_GE(lhs, rhs);
120 EXPECT_FALSE(lhs > rhs);
121 break;
122 case 1:
123 EXPECT_FALSE(lhs < rhs);
124 EXPECT_FALSE(lhs <= rhs);
125 EXPECT_NE(lhs, rhs);
126 EXPECT_FALSE(lhs == rhs);
127 EXPECT_GE(lhs, rhs);
128 EXPECT_GT(lhs, rhs);
129 break;
130 }
105 } 131 }
106 } 132 }
107 133
108 TEST(VersionTest, CompareToWildcardString) { 134 TEST(VersionTest, CompareToWildcardString) {
109 static const struct version_compare { 135 static const struct version_compare {
110 const char* lhs; 136 const char* lhs;
111 const char* rhs; 137 const char* rhs;
112 int expected; 138 int expected;
113 } cases[] = { 139 } cases[] = {
114 {"1.0", "1.*", 0}, 140 {"1.0", "1.*", 0},
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 {"*", false}, 175 {"*", false},
150 {"*.2", false}, 176 {"*.2", false},
151 }; 177 };
152 for (size_t i = 0; i < arraysize(cases); ++i) { 178 for (size_t i = 0; i < arraysize(cases); ++i) {
153 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version), 179 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version),
154 cases[i].expected) << cases[i].version << "?" << cases[i].expected; 180 cases[i].expected) << cases[i].version << "?" << cases[i].expected;
155 } 181 }
156 } 182 }
157 183
158 } // namespace 184 } // namespace
OLDNEW
« no previous file with comments | « base/version.cc ('k') | chrome/app/chrome_crash_reporter_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698