OLD | NEW |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.0a", 0, false}, | 50 {"1.0a", 0, false}, |
51 {"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}, |
52 {"02.1", 0, false}, | 52 {"02.1", 0, false}, |
53 {"f.1", 0, false}, | 53 {"f.1", 0, false}, |
54 }; | 54 }; |
55 | 55 |
56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 56 for (size_t i = 0; i < arraysize(cases); ++i) { |
57 Version version(cases[i].input); | 57 Version version(cases[i].input); |
58 EXPECT_EQ(cases[i].success, version.IsValid()); | 58 EXPECT_EQ(cases[i].success, version.IsValid()); |
59 if (cases[i].success) | 59 if (cases[i].success) |
60 EXPECT_EQ(cases[i].parts, version.components().size()); | 60 EXPECT_EQ(cases[i].parts, version.components().size()); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 TEST(VersionTest, Compare) { | 64 TEST(VersionTest, Compare) { |
65 static const struct version_compare { | 65 static const struct version_compare { |
66 const char* lhs; | 66 const char* lhs; |
67 const char* rhs; | 67 const char* rhs; |
68 int expected; | 68 int expected; |
69 } cases[] = { | 69 } cases[] = { |
70 {"1.0", "1.0", 0}, | 70 {"1.0", "1.0", 0}, |
71 {"1.0", "0.0", 1}, | 71 {"1.0", "0.0", 1}, |
72 {"1.0", "2.0", -1}, | 72 {"1.0", "2.0", -1}, |
73 {"1.0", "1.1", -1}, | 73 {"1.0", "1.1", -1}, |
74 {"1.1", "1.0", 1}, | 74 {"1.1", "1.0", 1}, |
75 {"1.0", "1.0.1", -1}, | 75 {"1.0", "1.0.1", -1}, |
76 {"1.1", "1.0.1", 1}, | 76 {"1.1", "1.0.1", 1}, |
77 {"1.1", "1.0.1", 1}, | 77 {"1.1", "1.0.1", 1}, |
78 {"1.0.0", "1.0", 0}, | 78 {"1.0.0", "1.0", 0}, |
79 {"1.0.3", "1.0.20", -1}, | 79 {"1.0.3", "1.0.20", -1}, |
80 }; | 80 }; |
81 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 81 for (size_t i = 0; i < arraysize(cases); ++i) { |
82 Version lhs(cases[i].lhs); | 82 Version lhs(cases[i].lhs); |
83 Version rhs(cases[i].rhs); | 83 Version rhs(cases[i].rhs); |
84 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) << | 84 EXPECT_EQ(lhs.CompareTo(rhs), cases[i].expected) << |
85 cases[i].lhs << " ? " << cases[i].rhs; | 85 cases[i].lhs << " ? " << cases[i].rhs; |
86 | 86 |
87 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1)); | 87 EXPECT_EQ(lhs.IsOlderThan(cases[i].rhs), (cases[i].expected == -1)); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 TEST(VersionTest, CompareToWildcardString) { | 91 TEST(VersionTest, CompareToWildcardString) { |
92 static const struct version_compare { | 92 static const struct version_compare { |
93 const char* lhs; | 93 const char* lhs; |
94 const char* rhs; | 94 const char* rhs; |
95 int expected; | 95 int expected; |
96 } cases[] = { | 96 } cases[] = { |
97 {"1.0", "1.*", 0}, | 97 {"1.0", "1.*", 0}, |
98 {"1.0", "0.*", 1}, | 98 {"1.0", "0.*", 1}, |
99 {"1.0", "2.*", -1}, | 99 {"1.0", "2.*", -1}, |
100 {"1.2.3", "1.2.3.*", 0}, | 100 {"1.2.3", "1.2.3.*", 0}, |
101 {"10.0", "1.0.*", 1}, | 101 {"10.0", "1.0.*", 1}, |
102 {"1.0", "3.0.*", -1}, | 102 {"1.0", "3.0.*", -1}, |
103 {"1.4", "1.3.0.*", 1}, | 103 {"1.4", "1.3.0.*", 1}, |
104 {"1.3.9", "1.3.*", 0}, | 104 {"1.3.9", "1.3.*", 0}, |
105 {"1.4.1", "1.3.*", 1}, | 105 {"1.4.1", "1.3.*", 1}, |
106 {"1.3", "1.4.5.*", -1}, | 106 {"1.3", "1.4.5.*", -1}, |
107 {"1.5", "1.4.5.*", 1}, | 107 {"1.5", "1.4.5.*", 1}, |
108 {"1.3.9", "1.3.*", 0}, | 108 {"1.3.9", "1.3.*", 0}, |
109 {"1.2.0.0.0.0", "1.2.*", 0}, | 109 {"1.2.0.0.0.0", "1.2.*", 0}, |
110 }; | 110 }; |
111 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 111 for (size_t i = 0; i < arraysize(cases); ++i) { |
112 const Version version(cases[i].lhs); | 112 const Version version(cases[i].lhs); |
113 const int result = version.CompareToWildcardString(cases[i].rhs); | 113 const int result = version.CompareToWildcardString(cases[i].rhs); |
114 EXPECT_EQ(result, cases[i].expected) << cases[i].lhs << "?" << cases[i].rhs; | 114 EXPECT_EQ(result, cases[i].expected) << cases[i].lhs << "?" << cases[i].rhs; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 TEST(VersionTest, IsValidWildcardString) { | 118 TEST(VersionTest, IsValidWildcardString) { |
119 static const struct version_compare { | 119 static const struct version_compare { |
120 const char* version; | 120 const char* version; |
121 bool expected; | 121 bool expected; |
122 } cases[] = { | 122 } cases[] = { |
123 {"1.0", true}, | 123 {"1.0", true}, |
124 {"", false}, | 124 {"", false}, |
125 {"1.2.3.4.5.6", true}, | 125 {"1.2.3.4.5.6", true}, |
126 {"1.2.3.*", true}, | 126 {"1.2.3.*", true}, |
127 {"1.2.3.5*", false}, | 127 {"1.2.3.5*", false}, |
128 {"1.2.3.56*", false}, | 128 {"1.2.3.56*", false}, |
129 {"1.*.3", false}, | 129 {"1.*.3", false}, |
130 {"20.*", true}, | 130 {"20.*", true}, |
131 {"+2.*", false}, | 131 {"+2.*", false}, |
132 {"*", false}, | 132 {"*", false}, |
133 {"*.2", false}, | 133 {"*.2", false}, |
134 }; | 134 }; |
135 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 135 for (size_t i = 0; i < arraysize(cases); ++i) { |
136 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version), | 136 EXPECT_EQ(Version::IsValidWildcardString(cases[i].version), |
137 cases[i].expected) << cases[i].version << "?" << cases[i].expected; | 137 cases[i].expected) << cases[i].version << "?" << cases[i].expected; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 } // namespace | 141 } // namespace |
OLD | NEW |