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

Side by Side Diff: base/version_unittest.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 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') | base/vlog.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 "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 13 matching lines...) Expand all
24 EXPECT_TRUE(v2.IsValid()); 24 EXPECT_TRUE(v2.IsValid());
25 EXPECT_TRUE(v1.Equals(v2)); 25 EXPECT_TRUE(v1.Equals(v2));
26 } 26 }
27 EXPECT_TRUE(v3.Equals(v1)); 27 EXPECT_TRUE(v3.Equals(v1));
28 } 28 }
29 29
30 TEST(VersionTest, GetVersionFromString) { 30 TEST(VersionTest, GetVersionFromString) {
31 static const struct version_string { 31 static const struct version_string {
32 const char* input; 32 const char* input;
33 size_t parts; 33 size_t parts;
34 uint32_t firstpart;
34 bool success; 35 bool success;
35 } cases[] = { 36 } cases[] = {
36 {"", 0, false}, 37 {"", 0, 0, false},
37 {" ", 0, false}, 38 {" ", 0, 0, false},
38 {"\t", 0, false}, 39 {"\t", 0, 0, false},
39 {"\n", 0, false}, 40 {"\n", 0, 0, false},
40 {" ", 0, false}, 41 {" ", 0, 0, false},
41 {".", 0, false}, 42 {".", 0, 0, false},
42 {" . ", 0, false}, 43 {" . ", 0, 0, false},
43 {"0", 1, true}, 44 {"0", 1, 0, true},
44 {"0.", 0, false}, 45 {"0.", 0, 0, false},
45 {"0.0", 2, true}, 46 {"0.0", 2, 0, true},
46 {"65537.0", 0, false}, 47 {"4294967295.0", 2, 4294967295, true},
47 {"-1.0", 0, false}, 48 {"4294967296.0", 0, 0, false},
48 {"1.-1.0", 0, false}, 49 {"-1.0", 0, 0, false},
49 {"1,--1.0", 0, false}, 50 {"1.-1.0", 0, 0, false},
50 {"+1.0", 0, false}, 51 {"1,--1.0", 0, 0, false},
51 {"1.+1.0", 0, false}, 52 {"+1.0", 0, 0, false},
52 {"1+1.0", 0, false}, 53 {"1.+1.0", 0, 0, false},
53 {"++1.0", 0, false}, 54 {"1+1.0", 0, 0, false},
54 {"1.0a", 0, false}, 55 {"++1.0", 0, 0, false},
55 {"1.2.3.4.5.6.7.8.9.0", 10, true}, 56 {"1.0a", 0, 0, false},
56 {"02.1", 0, false}, 57 {"1.2.3.4.5.6.7.8.9.0", 10, 1, true},
57 {"0.01", 2, true}, 58 {"02.1", 0, 0, false},
58 {"f.1", 0, false}, 59 {"0.01", 2, 0, true},
59 {"15.007.20011", 3, true}, 60 {"f.1", 0, 0, false},
61 {"15.007.20011", 3, 15, true},
62 {"15.5.28.130162", 4, 15, true},
60 }; 63 };
61 64
62 for (size_t i = 0; i < arraysize(cases); ++i) { 65 for (size_t i = 0; i < arraysize(cases); ++i) {
63 Version version(cases[i].input); 66 Version version(cases[i].input);
64 EXPECT_EQ(cases[i].success, version.IsValid()); 67 EXPECT_EQ(cases[i].success, version.IsValid());
65 if (cases[i].success) 68 if (cases[i].success) {
66 EXPECT_EQ(cases[i].parts, version.components().size()); 69 EXPECT_EQ(cases[i].parts, version.components().size());
70 EXPECT_EQ(cases[i].firstpart, version.components()[0]);
71 }
67 } 72 }
68 } 73 }
69 74
70 TEST(VersionTest, Compare) { 75 TEST(VersionTest, Compare) {
71 static const struct version_compare { 76 static const struct version_compare {
72 const char* lhs; 77 const char* lhs;
73 const char* rhs; 78 const char* rhs;
74 int expected; 79 int expected;
75 } cases[] = { 80 } cases[] = {
76 {"1.0", "1.0", 0}, 81 {"1.0", "1.0", 0},
77 {"1.0", "0.0", 1}, 82 {"1.0", "0.0", 1},
78 {"1.0", "2.0", -1}, 83 {"1.0", "2.0", -1},
79 {"1.0", "1.1", -1}, 84 {"1.0", "1.1", -1},
80 {"1.1", "1.0", 1}, 85 {"1.1", "1.0", 1},
81 {"1.0", "1.0.1", -1}, 86 {"1.0", "1.0.1", -1},
82 {"1.1", "1.0.1", 1}, 87 {"1.1", "1.0.1", 1},
83 {"1.1", "1.0.1", 1}, 88 {"1.1", "1.0.1", 1},
84 {"1.0.0", "1.0", 0}, 89 {"1.0.0", "1.0", 0},
85 {"1.0.3", "1.0.20", -1}, 90 {"1.0.3", "1.0.20", -1},
86 {"11.0.10", "15.007.20011", -1}, 91 {"11.0.10", "15.007.20011", -1},
92 {"11.0.10", "15.5.28.130162", -1},
87 }; 93 };
88 for (size_t i = 0; i < arraysize(cases); ++i) { 94 for (size_t i = 0; i < arraysize(cases); ++i) {
89 Version lhs(cases[i].lhs); 95 Version lhs(cases[i].lhs);
90 Version rhs(cases[i].rhs); 96 Version rhs(cases[i].rhs);
91 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) << 97 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) <<
92 cases[i].lhs << " ? " << cases[i].rhs; 98 cases[i].lhs << " ? " << cases[i].rhs;
93 99
94 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1)); 100 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1));
95 } 101 }
96 } 102 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 {"*", false}, 145 {"*", false},
140 {"*.2", false}, 146 {"*.2", false},
141 }; 147 };
142 for (size_t i = 0; i < arraysize(cases); ++i) { 148 for (size_t i = 0; i < arraysize(cases); ++i) {
143 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version), 149 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version),
144 cases[i].expected) << cases[i].version << "?" << cases[i].expected; 150 cases[i].expected) << cases[i].version << "?" << cases[i].expected;
145 } 151 }
146 } 152 }
147 153
148 } // namespace 154 } // namespace
OLDNEW
« no previous file with comments | « base/version.cc ('k') | base/vlog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698