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

Side by Side Diff: chrome/installer/util/version_unittest.cc

Issue 155842: Add unit test for chrome\installer\util\version (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | « chrome/installer/installer.gyp ('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')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/installer/util/version.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/scoped_ptr.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 static const installer::Version* kNoVersion = NULL;
14
15 TEST(VersionTest, Parse) {
16 EXPECT_EQ(installer::Version::GetVersionFromString(L"1"), kNoVersion);
17 EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2"), kNoVersion);
18 EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2.3"), kNoVersion);
19 EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2.3.4.5"), kNoVersion);
20 EXPECT_EQ(installer::Version::GetVersionFromString(L"hokum"), kNoVersion);
21
22 scoped_ptr<installer::Version> v1(
23 installer::Version::GetVersionFromString(L"1.22.333.4444"));
24 EXPECT_EQ(v1->GetString(), L"1.22.333.4444");
25 }
26
27 bool Implies(bool p, bool q) { return !p | q; }
28
29 TEST(VersionTest, Comparison) {
30 static const wchar_t* version_strings[] = {
31 L"0.0.0.0",
32 L"1.0.0.0",
33 L"0.1.0.0",
34 L"0.0.1.0",
35 L"0.0.0.1",
36 L"2.0.193.1",
37 L"3.0.183.1",
38 L"3.0.187.1",
39 L"3.0.189.0",
40 };
41
42 std::vector<const installer::Version*> versions;
43
44 for (size_t i = 0; i < _countof(version_strings); ++i) {
45 std::wstring version_string(version_strings[i]);
46 const installer::Version* version =
47 installer::Version::GetVersionFromString(version_string);
48 EXPECT_NE(version, kNoVersion);
49 EXPECT_EQ(version_string, version->GetString());
50 versions.push_back(version);
51 }
52
53 // Compare all N*N pairs and check that IsHigherThan is antireflexive.
54 for (size_t i = 0; i < versions.size(); ++i) {
55 const installer::Version* v1 = versions[i];
56 for (size_t j = 0; j < versions.size(); ++j) {
57 const installer::Version* v2 = versions[j];
58 // Check exactly one of '>', '<', or '=' is true.
59 bool higher = v1->IsHigherThan(v2);
60 bool lower = v2->IsHigherThan(v1);
61 bool equal = v1->GetString() == v2->GetString();
62 EXPECT_EQ(1, higher + lower + equal);
63 }
64 }
65
66 // Compare all N*N*N triples and check that IsHigherThan is a total order.
67 for (size_t i = 0; i < versions.size(); ++i) {
68 const installer::Version* v1 = versions[i];
69 for (size_t j = 0; j < versions.size(); ++j) {
70 const installer::Version* v2 = versions[j];
71 for (size_t k = 0; k < versions.size(); ++k) {
72 const installer::Version* v3 = versions[j];
73 EXPECT_TRUE(Implies(v2->IsHigherThan(v1) && v3->IsHigherThan(v2),
74 v3->IsHigherThan(v1)));
75 }
76 }
77 }
78
79 for (size_t i = 0; i < versions.size(); ++i) {
80 delete versions[i];
81 }
82 }
OLDNEW
« no previous file with comments | « chrome/installer/installer.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698