/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ResourceValues.h" #include "test/Test.h" using ::testing::Eq; using ::testing::SizeIs; using ::testing::StrEq; namespace aapt { TEST(ResourceValuesTest, PluralEquals) { StringPool pool; Plural a; a.values[Plural::One] = util::make_unique(pool.MakeRef("one")); a.values[Plural::Other] = util::make_unique(pool.MakeRef("other")); Plural b; b.values[Plural::One] = util::make_unique(pool.MakeRef("une")); b.values[Plural::Other] = util::make_unique(pool.MakeRef("autre")); Plural c; c.values[Plural::One] = util::make_unique(pool.MakeRef("one")); c.values[Plural::Other] = util::make_unique(pool.MakeRef("other")); EXPECT_FALSE(a.Equals(&b)); EXPECT_TRUE(a.Equals(&c)); } TEST(ResourceValuesTest, PluralClone) { StringPool pool; Plural a; a.values[Plural::One] = util::make_unique(pool.MakeRef("one")); a.values[Plural::Other] = util::make_unique(pool.MakeRef("other")); std::unique_ptr b(a.Clone(&pool)); EXPECT_TRUE(a.Equals(b.get())); } TEST(ResourceValuesTest, ArrayEquals) { StringPool pool; Array a; a.elements.push_back(util::make_unique(pool.MakeRef("one"))); a.elements.push_back(util::make_unique(pool.MakeRef("two"))); Array b; b.elements.push_back(util::make_unique(pool.MakeRef("une"))); b.elements.push_back(util::make_unique(pool.MakeRef("deux"))); Array c; c.elements.push_back(util::make_unique(pool.MakeRef("uno"))); Array d; d.elements.push_back(util::make_unique(pool.MakeRef("one"))); d.elements.push_back(util::make_unique(pool.MakeRef("two"))); EXPECT_FALSE(a.Equals(&b)); EXPECT_FALSE(a.Equals(&c)); EXPECT_FALSE(b.Equals(&c)); EXPECT_TRUE(a.Equals(&d)); } TEST(ResourceValuesTest, ArrayClone) { StringPool pool; Array a; a.elements.push_back(util::make_unique(pool.MakeRef("one"))); a.elements.push_back(util::make_unique(pool.MakeRef("two"))); std::unique_ptr b(a.Clone(&pool)); EXPECT_TRUE(a.Equals(b.get())); } TEST(ResourceValuesTest, StyleEquals) { StringPool pool; std::unique_ptr