OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/install_static/install_util.h" | |
6 | |
7 #include "testing/gmock/include/gmock/gmock.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 using ::testing::ElementsAre; | |
11 | |
grt (UTC plus 2)
2016/05/27 14:13:20
nit: put the tests in the install_static namespace
ananta
2016/05/27 20:05:25
Done.
| |
12 // Tests the MatchPattern function in the install_static library. | |
13 TEST(InstallStaticTest, MatchPattern) { | |
14 EXPECT_TRUE(install_static::MatchPattern(L"", L"")); | |
15 EXPECT_TRUE(install_static::MatchPattern(L"", L"*")); | |
16 EXPECT_FALSE(install_static::MatchPattern(L"", L"*a")); | |
17 EXPECT_FALSE(install_static::MatchPattern(L"", L"abc")); | |
18 EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*")); | |
19 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?")); | |
20 EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*")); | |
21 EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b")); | |
22 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d")); | |
23 EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d")); | |
24 EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh")); | |
25 EXPECT_TRUE(install_static::MatchPattern(L"foobarabc", L"*bar*")); | |
26 } | |
27 | |
28 // Tests the TokenizeString function in the install_static library. | |
29 TEST(InstallStaticTest, TokenizeString) { | |
30 // Test if the string is tokenized correctly with all tokens stripped of | |
31 // leading and trailing spaces. | |
32 std::vector<std::string> results = install_static::TokenizeString( | |
33 "un |deux\t|trois\n|quatre", '|', true); | |
34 ASSERT_EQ(4u, results.size()); | |
35 EXPECT_THAT(results, ElementsAre("un", "deux", "trois", "quatre")); | |
36 | |
37 // Test if the string is tokenized correctly with all tokens having | |
38 // leading and trailing spaces intact. | |
39 results = install_static::TokenizeString("un |deux\t|trois\n|quatre", | |
40 '|', false); | |
41 ASSERT_EQ(4u, results.size()); | |
42 EXPECT_THAT(results, ElementsAre("un ", "deux\t", "trois\n", "quatre")); | |
43 | |
44 // Test if tokenize returns the original string if an invalid token is | |
grt (UTC plus 2)
2016/05/27 14:13:20
invalid token? this is actually testing a string c
ananta
2016/05/27 20:05:25
Rephrased.
| |
45 // passed. | |
46 results = install_static::TokenizeString("un |deux\t|trois\n|quatre", | |
47 '!', false); | |
48 ASSERT_EQ(1u, results.size()); | |
49 ASSERT_EQ(results[0], "un |deux\t|trois\n|quatre"); | |
50 | |
51 // Test if tokenize handles a space character as delimiter. | |
52 results = install_static::TokenizeString("foo bar bleh blah boo", ' ', | |
53 false); | |
54 ASSERT_EQ(5u, results.size()); | |
55 EXPECT_THAT(results, ElementsAre("foo", "bar", "bleh", "blah", "boo")); | |
56 } | |
grt (UTC plus 2)
2016/05/27 14:13:20
add tests for a string of all delimiters (e.g., "|
ananta
2016/05/27 20:05:25
Done.
| |
57 | |
58 // Tests the CompareVersionString function in the install_static library. | |
59 TEST(InstallStaticTest, CompareVersions) { | |
60 // Case 1. Invalid versions. | |
61 int result = 0; | |
62 EXPECT_FALSE(install_static::CompareVersionStrings("", "", &result)); | |
63 EXPECT_FALSE(install_static::CompareVersionStrings("0.0.0.0", "A.B.C.D", | |
64 &result)); | |
65 EXPECT_FALSE(install_static::CompareVersionStrings("A.0.0.0", "0.0.0.0", | |
66 &result)); | |
67 | |
68 // Case 2. Equal versions. | |
69 EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.0", "0.0.0.0", | |
70 &result)); | |
71 EXPECT_EQ(0, result); | |
72 | |
73 // Case 3. Version1 > Version 2. | |
74 EXPECT_TRUE(install_static::CompareVersionStrings("1.0.0.0", "0.0.0.0", | |
75 &result)); | |
76 EXPECT_EQ(1, result); | |
77 | |
78 // Case 4. Version1 < Version 2. | |
79 EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.0", "1.0.0.0", | |
80 &result)); | |
81 EXPECT_EQ(-1, result); | |
82 | |
83 // Case 5. Version1 < Version 2. | |
84 EXPECT_TRUE(install_static::CompareVersionStrings("0.0", "0.0.1.0", | |
85 &result)); | |
86 EXPECT_EQ(-1, result); | |
87 | |
88 // Case 6. Version1 > Version 2. | |
89 EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.2", "0.0", | |
90 &result)); | |
91 EXPECT_EQ(1, result); | |
92 | |
93 // Case 7. Version1 > Version 2. | |
94 EXPECT_TRUE(install_static::CompareVersionStrings("1.1.1.2", "1.1.1.1", | |
95 &result)); | |
96 EXPECT_EQ(1, result); | |
97 } | |
scottmg
2016/05/27 17:27:22
maybe a test for sub-numbers that have leading 0s
ananta
2016/05/27 20:05:25
Done.
| |
OLD | NEW |