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 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
« base/version.cc ('K') | « 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, v3;
19 v1.InitFromString("1.2.3.4");
20 EXPECT_TRUE(v1.IsValid());
21 {
22 Version v2(v1);
23 v3 = v2;
24 EXPECT_TRUE(v2.IsValid());
25 EXPECT_TRUE(v1.Equals(v2));
26 }
27 EXPECT_TRUE(v3.Equals(v1));
15 } 28 }
16 29
17 TEST_F(VersionTest, GetVersionFromString) { 30 TEST_F(VersionTest, GetVersionFromString) {
18 static const struct version_string { 31 static const struct version_string {
19 const char* input; 32 const char* input;
20 size_t parts; 33 size_t parts;
21 bool success; 34 bool success;
22 } cases[] = { 35 } cases[] = {
23 {"", 0, false}, 36 {"", 0, false},
24 {" ", 0, false}, 37 {" ", 0, false},
(...skipping 11 matching lines...) Expand all
36 {"1.+1.0", 0, false}, 49 {"1.+1.0", 0, false},
37 {"1.0a", 0, false}, 50 {"1.0a", 0, false},
38 {"1.2.3.4.5.6.7.8.9.0", 10, true}, 51 {"1.2.3.4.5.6.7.8.9.0", 10, true},
39 {"02.1", 0, false}, 52 {"02.1", 0, false},
40 {"f.1", 0, false}, 53 {"f.1", 0, false},
41 }; 54 };
42 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
43 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input)); 56 scoped_ptr<Version> vers(Version::GetVersionFromString(cases[i].input));
44 EXPECT_EQ(cases[i].success, vers.get() != NULL); 57 EXPECT_EQ(cases[i].success, vers.get() != NULL);
45 if (cases[i].success) { 58 if (cases[i].success) {
46 EXPECT_TRUE(vers->is_valid_); 59 EXPECT_TRUE(vers->IsValid());
47 EXPECT_EQ(cases[i].parts, vers->components().size()); 60 EXPECT_EQ(cases[i].parts, vers->components().size());
48 } 61 }
49 } 62 }
50 } 63 }
51 64
52 TEST_F(VersionTest, Compare) { 65 TEST_F(VersionTest, Compare) {
53 static const struct version_compare { 66 static const struct version_compare {
54 const char* lhs; 67 const char* lhs;
55 const char* rhs; 68 const char* rhs;
56 int expected; 69 int expected;
57 } cases[] = { 70 } cases[] = {
58 {"1.0", "1.0", 0}, 71 {"1.0", "1.0", 0},
59 {"1.0", "0.0", 1}, 72 {"1.0", "0.0", 1},
60 {"1.0", "2.0", -1}, 73 {"1.0", "2.0", -1},
61 {"1.0", "1.1", -1}, 74 {"1.0", "1.1", -1},
62 {"1.1", "1.0", 1}, 75 {"1.1", "1.0", 1},
63 {"1.0", "1.0.1", -1}, 76 {"1.0", "1.0.1", -1},
64 {"1.1", "1.0.1", 1}, 77 {"1.1", "1.0.1", 1},
65 {"1.1", "1.0.1", 1}, 78 {"1.1", "1.0.1", 1},
66 {"1.0.0", "1.0", 0}, 79 {"1.0.0", "1.0", 0},
67 {"1.0.3", "1.0.20", -1}, 80 {"1.0.3", "1.0.20", -1},
68 }; 81 };
69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
70 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs)); 83 scoped_ptr<Version> lhs(Version::GetVersionFromString(cases[i].lhs));
71 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs)); 84 scoped_ptr<Version> rhs(Version::GetVersionFromString(cases[i].rhs));
72 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) << 85 EXPECT_EQ(lhs->CompareTo(*rhs), cases[i].expected) <<
73 cases[i].lhs << " ? " << cases[i].rhs; 86 cases[i].lhs << " ? " << cases[i].rhs;
74 } 87 }
75 } 88 }
OLDNEW
« base/version.cc ('K') | « base/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698