Index: chrome/install_static/install_util_unittest.cc |
diff --git a/chrome/install_static/install_util_unittest.cc b/chrome/install_static/install_util_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4132ac3c5f48b1764134c1175f30a454e60edeee |
--- /dev/null |
+++ b/chrome/install_static/install_util_unittest.cc |
@@ -0,0 +1,120 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/install_static/install_util.h" |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using ::testing::ElementsAre; |
+ |
+namespace install_static { |
+ |
+// Tests the MatchPattern function in the install_static library. |
+TEST(InstallStaticTest, MatchPattern) { |
+ EXPECT_TRUE(MatchPattern(L"", L"")); |
+ EXPECT_TRUE(MatchPattern(L"", L"*")); |
+ EXPECT_FALSE(MatchPattern(L"", L"*a")); |
+ EXPECT_FALSE(MatchPattern(L"", L"abc")); |
+ EXPECT_TRUE(MatchPattern(L"Hello1234", L"He??o*1*")); |
+ EXPECT_TRUE(MatchPattern(L"Foo", L"F*?")); |
+ EXPECT_TRUE(MatchPattern(L"Foo", L"F*")); |
+ EXPECT_FALSE(MatchPattern(L"Foo", L"F*b")); |
+ EXPECT_TRUE(MatchPattern(L"abcd", L"*c*d")); |
+ EXPECT_TRUE(MatchPattern(L"abcd", L"*?c*d")); |
+ EXPECT_FALSE(MatchPattern(L"abcd", L"abcd*efgh")); |
+ EXPECT_TRUE(MatchPattern(L"foobarabc", L"*bar*")); |
+} |
+ |
+// Tests the TokenizeString function in the install_static library. |
+TEST(InstallStaticTest, TokenizeString) { |
+ // Test if the string is tokenized correctly with all tokens stripped of |
+ // leading and trailing spaces. |
+ std::vector<std::string> results = |
+ TokenizeString("un |deux\t|trois\n|quatre", '|', true); |
+ ASSERT_EQ(4u, results.size()); |
+ EXPECT_THAT(results, ElementsAre("un", "deux", "trois", "quatre")); |
+ |
+ // Test if the string is tokenized correctly with all tokens having |
+ // leading and trailing spaces intact. |
+ results = TokenizeString("un |deux\t|trois\n|quatre", '|', false); |
+ ASSERT_EQ(4u, results.size()); |
+ EXPECT_THAT(results, ElementsAre("un ", "deux\t", "trois\n", "quatre")); |
+ |
+ // Test if tokenize returns the original string if a string containing only |
+ // one token and no delimiters is passed. |
+ results = TokenizeString("un |deux\t|trois\n|quatre", '!', false); |
+ ASSERT_EQ(1u, results.size()); |
+ ASSERT_EQ(results[0], "un |deux\t|trois\n|quatre"); |
+ |
+ // Test if tokenize handles a space character as delimiter. |
+ results = TokenizeString("foo bar bleh blah boo", ' ', false); |
+ ASSERT_EQ(5u, results.size()); |
+ EXPECT_THAT(results, ElementsAre("foo", "bar", "bleh", "blah", "boo")); |
+ |
+ // Test string with only delimiters. |
+ results = TokenizeString("||||", '|', false); |
+ ASSERT_EQ(4u, results.size()); |
+ EXPECT_THAT(results, ElementsAre("", "", "", "")); |
+ |
+ // Test string with spaces separated by delimiters. |
+ results = TokenizeString(" | | | |", '|', false); |
+ ASSERT_EQ(4u, results.size()); |
+ EXPECT_THAT(results, ElementsAre(" ", " ", " ", " ")); |
+ |
+ results = TokenizeString("one|two||four", '|', false); |
+ ASSERT_EQ(4u, results.size()); |
+ EXPECT_THAT(results, ElementsAre("one", "two", "", "four")); |
+} |
+ |
+// Tests the CompareVersionString function in the install_static library. |
+TEST(InstallStaticTest, CompareVersions) { |
+ // Case 1. Invalid versions. |
+ int result = 0; |
+ EXPECT_FALSE(CompareVersionStrings("", "", &result)); |
+ EXPECT_FALSE(CompareVersionStrings("0.0.0.0", "A.B.C.D", &result)); |
+ EXPECT_FALSE(CompareVersionStrings("A.0.0.0", "0.0.0.0", &result)); |
+ |
+ // Case 2. Equal versions. |
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.0", "0.0.0.0", &result)); |
+ EXPECT_EQ(0, result); |
+ |
+ // Case 3. Version1 > Version 2. |
+ EXPECT_TRUE(CompareVersionStrings("1.0.0.0", "0.0.0.0", &result)); |
+ EXPECT_EQ(1, result); |
+ |
+ // Case 4. Version1 < Version 2. |
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.0", "1.0.0.0", &result)); |
+ EXPECT_EQ(-1, result); |
+ |
+ // Case 5. Version1 < Version 2. |
+ EXPECT_TRUE(CompareVersionStrings("0.0", "0.0.1.0", &result)); |
+ EXPECT_EQ(-1, result); |
+ |
+ // Case 6. Version1 > Version 2. |
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.2", "0.0", &result)); |
+ EXPECT_EQ(1, result); |
+ |
+ // Case 7. Version1 > Version 2. |
+ EXPECT_TRUE(CompareVersionStrings("1.1.1.2", "1.1.1.1", &result)); |
+ EXPECT_EQ(1, result); |
+ |
+ // Case 8. Version1 < Version2 |
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.2", "0.0.0.3", &result)); |
+ EXPECT_EQ(-1, result); |
+ |
+ // Case 9. Version1 > Version2 |
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.4", "0.0.0.3", &result)); |
+ EXPECT_EQ(1, result); |
+ |
+ // Case 10. Version1 > Version2. Multiple digit numbers. |
+ EXPECT_TRUE(CompareVersionStrings("0.0.12.1", "0.0.10.3", &result)); |
+ EXPECT_EQ(1, result); |
+ |
+ // Case 11. Version1 < Version2. Multiple digit number. |
+ EXPECT_TRUE(CompareVersionStrings("10.11.12.13", "12.11.12.13", &result)); |
+ EXPECT_EQ(-1, result); |
+} |
+ |
+} // namespace install_static |