This source file includes following definitions.
- TEST
- TEST
- TEST
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(AutocompleteMatchTest, MoreRelevant) {
struct RelevantCases {
int r1;
int r2;
bool expected_result;
} cases[] = {
{ 10, 0, true },
{ 10, -5, true },
{ -5, 10, false },
{ 0, 10, false },
{ -10, -5, false },
{ -5, -10, true },
};
AutocompleteMatch m1(NULL, 0, false,
AutocompleteMatchType::URL_WHAT_YOU_TYPED);
AutocompleteMatch m2(NULL, 0, false,
AutocompleteMatchType::URL_WHAT_YOU_TYPED);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
m1.relevance = cases[i].r1;
m2.relevance = cases[i].r2;
EXPECT_EQ(cases[i].expected_result,
AutocompleteMatch::MoreRelevant(m1, m2));
}
}
TEST(AutocompleteMatchTest, MergeClassifications) {
EXPECT_EQ(std::string(),
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ACMatchClassifications(),
AutocompleteMatch::ACMatchClassifications())));
EXPECT_EQ("0,0",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,0"),
AutocompleteMatch::ACMatchClassifications())));
EXPECT_EQ("0,0",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ACMatchClassifications(),
AutocompleteMatch::ClassificationsFromString("0,0"))));
EXPECT_EQ("0,1",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,1"),
AutocompleteMatch::ACMatchClassifications())));
EXPECT_EQ("0,1",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ACMatchClassifications(),
AutocompleteMatch::ClassificationsFromString("0,1"))));
EXPECT_EQ("0,1",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,0"),
AutocompleteMatch::ClassificationsFromString("0,1"))));
EXPECT_EQ("0,3," "1,2",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,1," "1,0"),
AutocompleteMatch::ClassificationsFromString("0,2"))));
EXPECT_EQ("0,3," "1,2",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,2"),
AutocompleteMatch::ClassificationsFromString("0,1," "1,0"))));
EXPECT_EQ("0,3",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString("0,1," "1,2"),
AutocompleteMatch::ClassificationsFromString("0,2," "1,1"))));
EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0",
AutocompleteMatch::ClassificationsToString(
AutocompleteMatch::MergeClassifications(
AutocompleteMatch::ClassificationsFromString(
"0,0," "2,1," "4,3," "7,7," "10,6," "15,0"),
AutocompleteMatch::ClassificationsFromString(
"0,2," "1,0," "5,7," "6,1," "17,0"))));
}
TEST(AutocompleteMatchTest, SupportsDeletion) {
AutocompleteMatch m(NULL, 0, false,
AutocompleteMatchType::URL_WHAT_YOU_TYPED);
EXPECT_FALSE(m.SupportsDeletion());
AutocompleteMatch m1(NULL, 0, true,
AutocompleteMatchType::URL_WHAT_YOU_TYPED);
EXPECT_TRUE(m1.SupportsDeletion());
m.duplicate_matches.push_back(AutocompleteMatch(
NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
m.duplicate_matches.push_back(AutocompleteMatch(
NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
EXPECT_FALSE(m.SupportsDeletion());
m.duplicate_matches.push_back(AutocompleteMatch(
NULL, 0, true, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
EXPECT_TRUE(m.SupportsDeletion());
}