2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "ResourceValues.h"
19 #include "test/Test.h"
23 TEST(ResourceValuesTest, PluralEquals) {
27 a.values[Plural::One] = util::make_unique<String>(pool.MakeRef("one"));
28 a.values[Plural::Other] = util::make_unique<String>(pool.MakeRef("other"));
31 b.values[Plural::One] = util::make_unique<String>(pool.MakeRef("une"));
32 b.values[Plural::Other] = util::make_unique<String>(pool.MakeRef("autre"));
35 c.values[Plural::One] = util::make_unique<String>(pool.MakeRef("one"));
36 c.values[Plural::Other] = util::make_unique<String>(pool.MakeRef("other"));
38 EXPECT_FALSE(a.Equals(&b));
39 EXPECT_TRUE(a.Equals(&c));
42 TEST(ResourceValuesTest, PluralClone) {
46 a.values[Plural::One] = util::make_unique<String>(pool.MakeRef("one"));
47 a.values[Plural::Other] = util::make_unique<String>(pool.MakeRef("other"));
49 std::unique_ptr<Plural> b(a.Clone(&pool));
50 EXPECT_TRUE(a.Equals(b.get()));
53 TEST(ResourceValuesTest, ArrayEquals) {
57 a.items.push_back(util::make_unique<String>(pool.MakeRef("one")));
58 a.items.push_back(util::make_unique<String>(pool.MakeRef("two")));
61 b.items.push_back(util::make_unique<String>(pool.MakeRef("une")));
62 b.items.push_back(util::make_unique<String>(pool.MakeRef("deux")));
65 c.items.push_back(util::make_unique<String>(pool.MakeRef("uno")));
68 d.items.push_back(util::make_unique<String>(pool.MakeRef("one")));
69 d.items.push_back(util::make_unique<String>(pool.MakeRef("two")));
71 EXPECT_FALSE(a.Equals(&b));
72 EXPECT_FALSE(a.Equals(&c));
73 EXPECT_FALSE(b.Equals(&c));
74 EXPECT_TRUE(a.Equals(&d));
77 TEST(ResourceValuesTest, ArrayClone) {
81 a.items.push_back(util::make_unique<String>(pool.MakeRef("one")));
82 a.items.push_back(util::make_unique<String>(pool.MakeRef("two")));
84 std::unique_ptr<Array> b(a.Clone(&pool));
85 EXPECT_TRUE(a.Equals(b.get()));
88 TEST(ResourceValuesTest, StyleEquals) {
91 std::unique_ptr<Style> a = test::StyleBuilder()
92 .SetParent("android:style/Parent")
93 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
94 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("2"))
97 std::unique_ptr<Style> b = test::StyleBuilder()
98 .SetParent("android:style/Parent")
99 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
100 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("3"))
103 std::unique_ptr<Style> c = test::StyleBuilder()
104 .SetParent("android:style/NoParent")
105 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
106 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("2"))
109 std::unique_ptr<Style> d = test::StyleBuilder()
110 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
111 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("2"))
114 std::unique_ptr<Style> e = test::StyleBuilder()
115 .SetParent("android:style/Parent")
116 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
117 .AddItem("android:attr/bat", ResourceUtils::TryParseInt("2"))
120 std::unique_ptr<Style> f = test::StyleBuilder()
121 .SetParent("android:style/Parent")
122 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
125 std::unique_ptr<Style> g = test::StyleBuilder()
126 .SetParent("android:style/Parent")
127 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
128 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("2"))
131 EXPECT_FALSE(a->Equals(b.get()));
132 EXPECT_FALSE(a->Equals(c.get()));
133 EXPECT_FALSE(a->Equals(d.get()));
134 EXPECT_FALSE(a->Equals(e.get()));
135 EXPECT_FALSE(a->Equals(f.get()));
137 EXPECT_TRUE(a->Equals(g.get()));
140 TEST(ResourceValuesTest, StyleClone) {
141 std::unique_ptr<Style> a = test::StyleBuilder()
142 .SetParent("android:style/Parent")
143 .AddItem("android:attr/foo", ResourceUtils::TryParseInt("1"))
144 .AddItem("android:attr/bar", ResourceUtils::TryParseInt("2"))
147 std::unique_ptr<Style> b(a->Clone(nullptr));
148 EXPECT_TRUE(a->Equals(b.get()));