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

Side by Side Diff: base/version_unittest.cc

Issue 1364002: Fixed bug where an empty version string is considered valid. (Closed)
Patch Set: addressed comments Created 10 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') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/version.h" 6 #include "base/version.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace { 9 class VersionTest : public testing::Test {
10 };
10 11
11 TEST(Version, GetVersionFromString) { 12 TEST_F(VersionTest, DefaultConstructor) {
13 Version v;
14 EXPECT_FALSE(v.is_valid_);
15 }
16
17 TEST_F(VersionTest, GetVersionFromString) {
12 static const struct version_string { 18 static const struct version_string {
13 const char* input; 19 const char* input;
14 size_t parts; 20 size_t parts;
15 bool success; 21 bool success;
16 } cases[] = { 22 } cases[] = {
23 {"", 0, false},
24 {" ", 0, false},
25 {"\t", 0, false},
26 {"\n", 0, false},
27 {" ", 0, false},
28 {".", 0, false},
29 {" . ", 0, false},
17 {"0", 1, true}, 30 {"0", 1, true},
18 {"0.0", 2, true}, 31 {"0.0", 2, true},
19 {"65537.0", 0, false}, 32 {"65537.0", 0, false},
20 {"-1.0", 0, false}, 33 {"-1.0", 0, false},
21 {"1.-1.0", 0, false}, 34 {"1.-1.0", 0, false},
22 {"+1.0", 0, false}, 35 {"+1.0", 0, false},
23 {"1.+1.0", 0, false}, 36 {"1.+1.0", 0, false},
24 {"1.0a", 0, false}, 37 {"1.0a", 0, false},
25 {"1.2.3.4.5.6.7.8.9.0", 10, true}, 38 {"1.2.3.4.5.6.7.8.9.0", 10, true},
26 {"02.1", 0, false}, 39 {"02.1", 0, false},
27 {"f.1", 0, false}, 40 {"f.1", 0, false},
28 }; 41 };
29 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
30 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input)); 43 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input));
31 EXPECT_EQ(cases[i].success, vers.get() != NULL); 44 EXPECT_EQ(cases[i].success, vers.get() != NULL);
32 if (cases[i].success) 45 if (cases[i].success) {
46 EXPECT_TRUE(vers->is_valid_);
33 EXPECT_EQ(cases[i].parts, vers->components().size()); 47 EXPECT_EQ(cases[i].parts, vers->components().size());
48 }
34 } 49 }
35 } 50 }
36 51
37 TEST(Version, Compare) { 52 TEST_F(VersionTest, Compare) {
38 static const struct version_compare { 53 static const struct version_compare {
39 const char* lhs; 54 const char* lhs;
40 const char* rhs; 55 const char* rhs;
41 int expected; 56 int expected;
42 } cases[] = { 57 } cases[] = {
43 {"1.0", "1.0", 0}, 58 {"1.0", "1.0", 0},
44 {"1.0", "0.0", 1}, 59 {"1.0", "0.0", 1},
45 {"1.0", "2.0", -1}, 60 {"1.0", "2.0", -1},
46 {"1.0", "1.1", -1}, 61 {"1.0", "1.1", -1},
47 {"1.1", "1.0", 1}, 62 {"1.1", "1.0", 1},
48 {"1.0", "1.0.1", -1}, 63 {"1.0", "1.0.1", -1},
49 {"1.1", "1.0.1", 1}, 64 {"1.1", "1.0.1", 1},
50 {"1.1", "1.0.1", 1}, 65 {"1.1", "1.0.1", 1},
51 {"1.0.0", "1.0", 0}, 66 {"1.0.0", "1.0", 0},
52 {"1.0.3", "1.0.20", -1}, 67 {"1.0.3", "1.0.20", -1},
53 }; 68 };
54 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
55 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs)); 70 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs));
56 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs)); 71 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs));
57 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) << 72 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) <<
58 cases[i].lhs << " ? " << cases[i].rhs; 73 cases[i].lhs << " ? " << cases[i].rhs;
59 } 74 }
60 } 75 }
61
62 }
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