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

Side by Side Diff: base/version_unittest.cc

Issue 7105008: Clean up base/Version (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
« 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 5 #include "base/memory/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 class VersionTest : public testing::Test { 9 class VersionTest : public testing::Test {
10 }; 10 };
11 11
12 TEST_F(VersionTest, DefaultConstructor) { 12 TEST_F(VersionTest, DefaultConstructor) {
13 Version v; 13 Version v;
14 EXPECT_FALSE(v.is_valid_); 14 EXPECT_FALSE(v.IsValid());
15 }
16
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());
22 {
23 Version v2(v1);
24 v3 = v2;
25 EXPECT_TRUE(v2.IsValid());
26 EXPECT_TRUE(v1.Equals(v2));
27 }
28 EXPECT_TRUE(v3.Equals(v1));
15 } 29 }
16 30
17 TEST_F(VersionTest, GetVersionFromString) { 31 TEST_F(VersionTest, GetVersionFromString) {
18 static const struct version_string { 32 static const struct version_string {
19 const char* input; 33 const char* input;
20 size_t parts; 34 size_t parts;
21 bool success; 35 bool success;
22 } cases[] = { 36 } cases[] = {
23 {"", 0, false}, 37 {"", 0, false},
24 {" ", 0, false}, 38 {" ", 0, false},
(...skipping 11 matching lines...) Expand all
36 {"1.+1.0", 0, false}, 50 {"1.+1.0", 0, false},
37 {"1.0a", 0, false}, 51 {"1.0a", 0, false},
38 {"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},
39 {"02.1", 0, false}, 53 {"02.1", 0, false},
40 {"f.1", 0, false}, 54 {"f.1", 0, false},
41 }; 55 };
42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
43 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input)); 57 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input));
44 EXPECT_EQ(cases[i].success, vers.get() != NULL); 58 EXPECT_EQ(cases[i].success, vers.get() != NULL);
45 if (cases[i].success) { 59 if (cases[i].success) {
46 EXPECT_TRUE(vers->is_valid_); 60 EXPECT_TRUE(vers->IsValid());
47 EXPECT_EQ(cases[i].parts, vers->components().size()); 61 EXPECT_EQ(cases[i].parts, vers->components().size());
48 } 62 }
49 } 63 }
50 } 64 }
51 65
52 TEST_F(VersionTest, Compare) { 66 TEST_F(VersionTest, Compare) {
53 static const struct version_compare { 67 static const struct version_compare {
54 const char* lhs; 68 const char* lhs;
55 const char* rhs; 69 const char* rhs;
56 int expected; 70 int expected;
57 } cases[] = { 71 } cases[] = {
58 {"1.0", "1.0", 0}, 72 {"1.0", "1.0", 0},
59 {"1.0", "0.0", 1}, 73 {"1.0", "0.0", 1},
60 {"1.0", "2.0", -1}, 74 {"1.0", "2.0", -1},
61 {"1.0", "1.1", -1}, 75 {"1.0", "1.1", -1},
62 {"1.1", "1.0", 1}, 76 {"1.1", "1.0", 1},
63 {"1.0", "1.0.1", -1}, 77 {"1.0", "1.0.1", -1},
64 {"1.1", "1.0.1", 1}, 78 {"1.1", "1.0.1", 1},
65 {"1.1", "1.0.1", 1}, 79 {"1.1", "1.0.1", 1},
66 {"1.0.0", "1.0", 0}, 80 {"1.0.0", "1.0", 0},
67 {"1.0.3", "1.0.20", -1}, 81 {"1.0.3", "1.0.20", -1},
68 }; 82 };
69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
70 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs)); 84 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs));
71 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs)); 85 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs));
72 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) << 86 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) <<
73 cases[i].lhs << " ? " << cases[i].rhs; 87 cases[i].lhs << " ? " << cases[i].rhs;
74 } 88 }
75 } 89 }
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