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

Side by Side Diff: base/version_unittest.cc

Issue 949573002: Support plugin version mid-portions with leading zeros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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') | no next file » | 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 29 matching lines...) Expand all
40 {" ", 0, false}, 40 {" ", 0, false},
41 {".", 0, false}, 41 {".", 0, false},
42 {" . ", 0, false}, 42 {" . ", 0, false},
43 {"0", 1, true}, 43 {"0", 1, true},
44 {"0.0", 2, true}, 44 {"0.0", 2, true},
45 {"65537.0", 0, false}, 45 {"65537.0", 0, false},
46 {"-1.0", 0, false}, 46 {"-1.0", 0, false},
47 {"1.-1.0", 0, false}, 47 {"1.-1.0", 0, false},
48 {"+1.0", 0, false}, 48 {"+1.0", 0, false},
49 {"1.+1.0", 0, false}, 49 {"1.+1.0", 0, false},
50 {"1+1.0", 0, false},
50 {"1.0a", 0, false}, 51 {"1.0a", 0, false},
51 {"1.2.3.4.5.6.7.8.9.0", 10, true}, 52 {"1.2.3.4.5.6.7.8.9.0", 10, true},
52 {"02.1", 0, false}, 53 {"02.1", 2, true},
Nico 2015/02/21 23:11:16 Should we still disallow 0s on the first version c
Will Harris 2015/02/22 00:37:37 yes I agree that makes most sense. Done.
53 {"f.1", 0, false}, 54 {"f.1", 0, false},
55 {"15.007.20011", 3, true},
54 }; 56 };
55 57
56 for (size_t i = 0; i < arraysize(cases); ++i) { 58 for (size_t i = 0; i < arraysize(cases); ++i) {
57 Version version(cases[i].input); 59 Version version(cases[i].input);
58 EXPECT_EQ(cases[i].success, version.IsValid()); 60 EXPECT_EQ(cases[i].success, version.IsValid());
59 if (cases[i].success) 61 if (cases[i].success)
60 EXPECT_EQ(cases[i].parts, version.components().size()); 62 EXPECT_EQ(cases[i].parts, version.components().size());
61 } 63 }
62 } 64 }
63 65
64 TEST(VersionTest, Compare) { 66 TEST(VersionTest, Compare) {
65 static const struct version_compare { 67 static const struct version_compare {
66 const char* lhs; 68 const char* lhs;
67 const char* rhs; 69 const char* rhs;
68 int expected; 70 int expected;
69 } cases[] = { 71 } cases[] = {
70 {"1.0", "1.0", 0}, 72 {"1.0", "1.0", 0},
71 {"1.0", "0.0", 1}, 73 {"1.0", "0.0", 1},
72 {"1.0", "2.0", -1}, 74 {"1.0", "2.0", -1},
73 {"1.0", "1.1", -1}, 75 {"1.0", "1.1", -1},
74 {"1.1", "1.0", 1}, 76 {"1.1", "1.0", 1},
75 {"1.0", "1.0.1", -1}, 77 {"1.0", "1.0.1", -1},
76 {"1.1", "1.0.1", 1}, 78 {"1.1", "1.0.1", 1},
77 {"1.1", "1.0.1", 1}, 79 {"1.1", "1.0.1", 1},
78 {"1.0.0", "1.0", 0}, 80 {"1.0.0", "1.0", 0},
79 {"1.0.3", "1.0.20", -1}, 81 {"1.0.3", "1.0.20", -1},
82 {"11.0.10", "15.007.20011", -1},
80 }; 83 };
81 for (size_t i = 0; i < arraysize(cases); ++i) { 84 for (size_t i = 0; i < arraysize(cases); ++i) {
82 Version lhs(cases[i].lhs); 85 Version lhs(cases[i].lhs);
83 Version rhs(cases[i].rhs); 86 Version rhs(cases[i].rhs);
84 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) << 87 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) <<
85 cases[i].lhs << " ? " << cases[i].rhs; 88 cases[i].lhs << " ? " << cases[i].rhs;
86 89
87 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1)); 90 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1));
88 } 91 }
89 } 92 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 {"*", false}, 135 {"*", false},
133 {"*.2", false}, 136 {"*.2", false},
134 }; 137 };
135 for (size_t i = 0; i < arraysize(cases); ++i) { 138 for (size_t i = 0; i < arraysize(cases); ++i) {
136 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version), 139 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version),
137 cases[i].expected) << cases[i].version << "?" << cases[i].expected; 140 cases[i].expected) << cases[i].version << "?" << cases[i].expected;
138 } 141 }
139 } 142 }
140 143
141 } // namespace 144 } // namespace
OLDNEW
« no previous file with comments | « base/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698