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

Unified Diff: chrome/install_static/install_static_unittests.cc

Issue 2017853002: Add functionality to the install_static library to tokenize strings and compare versions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows gn builder redness Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/install_static/install_static_unittests.cc
diff --git a/chrome/install_static/install_static_unittests.cc b/chrome/install_static/install_static_unittests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6f3844062b9e038158459214b7f187d83ff7c5f6
--- /dev/null
+++ b/chrome/install_static/install_static_unittests.cc
@@ -0,0 +1,97 @@
+// 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;
+
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.
+// Tests the MatchPattern function in the install_static library.
+TEST(InstallStaticTest, MatchPattern) {
+ EXPECT_TRUE(install_static::MatchPattern(L"", L""));
+ EXPECT_TRUE(install_static::MatchPattern(L"", L"*"));
+ EXPECT_FALSE(install_static::MatchPattern(L"", L"*a"));
+ EXPECT_FALSE(install_static::MatchPattern(L"", L"abc"));
+ EXPECT_TRUE(install_static::MatchPattern(L"Hello1234", L"He??o*1*"));
+ EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*?"));
+ EXPECT_TRUE(install_static::MatchPattern(L"Foo", L"F*"));
+ EXPECT_FALSE(install_static::MatchPattern(L"Foo", L"F*b"));
+ EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*c*d"));
+ EXPECT_TRUE(install_static::MatchPattern(L"abcd", L"*?c*d"));
+ EXPECT_FALSE(install_static::MatchPattern(L"abcd", L"abcd*efgh"));
+ EXPECT_TRUE(install_static::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 = install_static::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 = install_static::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 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.
+ // passed.
+ results = install_static::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 = install_static::TokenizeString("foo bar bleh blah boo", ' ',
+ false);
+ ASSERT_EQ(5u, results.size());
+ EXPECT_THAT(results, ElementsAre("foo", "bar", "bleh", "blah", "boo"));
+}
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.
+
+// Tests the CompareVersionString function in the install_static library.
+TEST(InstallStaticTest, CompareVersions) {
+ // Case 1. Invalid versions.
+ int result = 0;
+ EXPECT_FALSE(install_static::CompareVersionStrings("", "", &result));
+ EXPECT_FALSE(install_static::CompareVersionStrings("0.0.0.0", "A.B.C.D",
+ &result));
+ EXPECT_FALSE(install_static::CompareVersionStrings("A.0.0.0", "0.0.0.0",
+ &result));
+
+ // Case 2. Equal versions.
+ EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.0", "0.0.0.0",
+ &result));
+ EXPECT_EQ(0, result);
+
+ // Case 3. Version1 > Version 2.
+ EXPECT_TRUE(install_static::CompareVersionStrings("1.0.0.0", "0.0.0.0",
+ &result));
+ EXPECT_EQ(1, result);
+
+ // Case 4. Version1 < Version 2.
+ EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.0", "1.0.0.0",
+ &result));
+ EXPECT_EQ(-1, result);
+
+ // Case 5. Version1 < Version 2.
+ EXPECT_TRUE(install_static::CompareVersionStrings("0.0", "0.0.1.0",
+ &result));
+ EXPECT_EQ(-1, result);
+
+ // Case 6. Version1 > Version 2.
+ EXPECT_TRUE(install_static::CompareVersionStrings("0.0.0.2", "0.0",
+ &result));
+ EXPECT_EQ(1, result);
+
+ // Case 7. Version1 > Version 2.
+ EXPECT_TRUE(install_static::CompareVersionStrings("1.1.1.2", "1.1.1.1",
+ &result));
+ EXPECT_EQ(1, result);
+}
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.

Powered by Google App Engine
This is Rietveld 408576698