Loading libs/androidfw/tests/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ testFiles := \ Idmap_test.cpp \ ResTable_test.cpp \ Split_test.cpp \ TestHelpers.cpp \ Theme_test.cpp \ TypeWrappers_test.cpp \ ZipUtils_test.cpp Loading libs/androidfw/tests/ResTable_test.cpp +1 −11 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ namespace { #include "data/lib/lib_arsc.h" enum { MAY_NOT_BE_BAG = false }; TEST(ResTableTest, shouldLoadSuccessfully) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Loading @@ -48,15 +46,7 @@ TEST(ResTableTest, simpleTypeIsRetrievedCorrectly) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Res_value val; ssize_t block = table.getResource(base::R::string::test1, &val, MAY_NOT_BE_BAG); ASSERT_GE(block, 0); ASSERT_EQ(Res_value::TYPE_STRING, val.dataType); const ResStringPool* pool = table.getTableStringBlock(block); ASSERT_TRUE(NULL != pool); ASSERT_EQ(String8("test1"), pool->string8ObjectAt(val.data)); EXPECT_TRUE(IsStringEqual(table, base::R::string::test1, "test1")); } TEST(ResTableTest, resourceNameIsResolved) { Loading libs/androidfw/tests/Split_test.cpp +31 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ namespace { * Package: com.android.test.basic */ #include "data/basic/split_de_fr_arsc.h" #include "data/basic/split_hdpi_v4_arsc.h" #include "data/basic/split_xhdpi_v4_arsc.h" #include "data/basic/split_xxhdpi_v4_arsc.h" /** * Include a binary resource table. This table Loading Loading @@ -163,6 +166,33 @@ TEST(SplitTest, TypeEntrySpecFlagsAreUpdated) { EXPECT_EQ(ResTable_config::CONFIG_LOCALE, frSpecFlags); } TEST(SplitTest, SelectBestDensity) { ResTable_config baseConfig; memset(&baseConfig, 0, sizeof(baseConfig)); baseConfig.density = ResTable_config::DENSITY_XHIGH; baseConfig.sdkVersion = 21; ResTable table; table.setParameters(&baseConfig); ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); ASSERT_EQ(NO_ERROR, table.add(split_hdpi_v4_arsc, split_hdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "hdpi")); ASSERT_EQ(NO_ERROR, table.add(split_xhdpi_v4_arsc, split_xhdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xhdpi")); ASSERT_EQ(NO_ERROR, table.add(split_xxhdpi_v4_arsc, split_xxhdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xhdpi")); baseConfig.density = ResTable_config::DENSITY_XXHIGH; table.setParameters(&baseConfig); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xxhdpi")); } TEST(SplitFeatureTest, TestNewResourceIsAccessible) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Loading @@ -188,7 +218,7 @@ TEST(SplitFeatureTest, TestNewResourceNameHasCorrectName) { ASSERT_EQ(NO_ERROR, table.add(feature_arsc, feature_arsc_len)); EXPECT_TRUE(table.getResourceName(base::R::string::test3, false, &name)); ASSERT_TRUE(table.getResourceName(base::R::string::test3, false, &name)); EXPECT_EQ(String16("com.android.test.basic"), String16(name.package, name.packageLen)); Loading libs/androidfw/tests/TestHelpers.cpp 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 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 "TestHelpers.h" #include <androidfw/ResourceTypes.h> #include <utils/String8.h> #include <gtest/gtest.h> namespace android { ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resourceId, const char* expectedStr) { Res_value val; ssize_t block = table.getResource(resourceId, &val, MAY_NOT_BE_BAG); if (block < 0) { return ::testing::AssertionFailure() << "could not find resource"; } if (val.dataType != Res_value::TYPE_STRING) { return ::testing::AssertionFailure() << "resource is not a string"; } const ResStringPool* pool = table.getTableStringBlock(block); if (pool == NULL) { return ::testing::AssertionFailure() << "table has no string pool for block " << block; } const String8 actual = pool->string8ObjectAt(val.data); if (String8(expectedStr) != actual) { return ::testing::AssertionFailure() << actual.string(); } return ::testing::AssertionSuccess() << actual.string(); } } // namespace android libs/androidfw/tests/TestHelpers.h +5 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <androidfw/ResourceTypes.h> #include <utils/String8.h> #include <utils/String16.h> #include <gtest/gtest.h> static inline ::std::ostream& operator<<(::std::ostream& out, const android::String8& str) { return out << str.string(); Loading @@ -17,6 +18,8 @@ static inline ::std::ostream& operator<<(::std::ostream& out, const android::Str namespace android { enum { MAY_NOT_BE_BAG = false }; static inline bool operator==(const android::ResTable_config& a, const android::ResTable_config& b) { return memcmp(&a, &b, sizeof(a)) == 0; } Loading @@ -25,6 +28,8 @@ static inline ::std::ostream& operator<<(::std::ostream& out, const android::Res return out << c.toString().string(); } ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resourceId, const char* expectedStr); } // namespace android #endif // __TEST_HELPERS_H Loading
libs/androidfw/tests/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ testFiles := \ Idmap_test.cpp \ ResTable_test.cpp \ Split_test.cpp \ TestHelpers.cpp \ Theme_test.cpp \ TypeWrappers_test.cpp \ ZipUtils_test.cpp Loading
libs/androidfw/tests/ResTable_test.cpp +1 −11 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ namespace { #include "data/lib/lib_arsc.h" enum { MAY_NOT_BE_BAG = false }; TEST(ResTableTest, shouldLoadSuccessfully) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Loading @@ -48,15 +46,7 @@ TEST(ResTableTest, simpleTypeIsRetrievedCorrectly) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Res_value val; ssize_t block = table.getResource(base::R::string::test1, &val, MAY_NOT_BE_BAG); ASSERT_GE(block, 0); ASSERT_EQ(Res_value::TYPE_STRING, val.dataType); const ResStringPool* pool = table.getTableStringBlock(block); ASSERT_TRUE(NULL != pool); ASSERT_EQ(String8("test1"), pool->string8ObjectAt(val.data)); EXPECT_TRUE(IsStringEqual(table, base::R::string::test1, "test1")); } TEST(ResTableTest, resourceNameIsResolved) { Loading
libs/androidfw/tests/Split_test.cpp +31 −1 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ namespace { * Package: com.android.test.basic */ #include "data/basic/split_de_fr_arsc.h" #include "data/basic/split_hdpi_v4_arsc.h" #include "data/basic/split_xhdpi_v4_arsc.h" #include "data/basic/split_xxhdpi_v4_arsc.h" /** * Include a binary resource table. This table Loading Loading @@ -163,6 +166,33 @@ TEST(SplitTest, TypeEntrySpecFlagsAreUpdated) { EXPECT_EQ(ResTable_config::CONFIG_LOCALE, frSpecFlags); } TEST(SplitTest, SelectBestDensity) { ResTable_config baseConfig; memset(&baseConfig, 0, sizeof(baseConfig)); baseConfig.density = ResTable_config::DENSITY_XHIGH; baseConfig.sdkVersion = 21; ResTable table; table.setParameters(&baseConfig); ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); ASSERT_EQ(NO_ERROR, table.add(split_hdpi_v4_arsc, split_hdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "hdpi")); ASSERT_EQ(NO_ERROR, table.add(split_xhdpi_v4_arsc, split_xhdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xhdpi")); ASSERT_EQ(NO_ERROR, table.add(split_xxhdpi_v4_arsc, split_xxhdpi_v4_arsc_len)); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xhdpi")); baseConfig.density = ResTable_config::DENSITY_XXHIGH; table.setParameters(&baseConfig); EXPECT_TRUE(IsStringEqual(table, base::R::string::density, "xxhdpi")); } TEST(SplitFeatureTest, TestNewResourceIsAccessible) { ResTable table; ASSERT_EQ(NO_ERROR, table.add(basic_arsc, basic_arsc_len)); Loading @@ -188,7 +218,7 @@ TEST(SplitFeatureTest, TestNewResourceNameHasCorrectName) { ASSERT_EQ(NO_ERROR, table.add(feature_arsc, feature_arsc_len)); EXPECT_TRUE(table.getResourceName(base::R::string::test3, false, &name)); ASSERT_TRUE(table.getResourceName(base::R::string::test3, false, &name)); EXPECT_EQ(String16("com.android.test.basic"), String16(name.package, name.packageLen)); Loading
libs/androidfw/tests/TestHelpers.cpp 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 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 "TestHelpers.h" #include <androidfw/ResourceTypes.h> #include <utils/String8.h> #include <gtest/gtest.h> namespace android { ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resourceId, const char* expectedStr) { Res_value val; ssize_t block = table.getResource(resourceId, &val, MAY_NOT_BE_BAG); if (block < 0) { return ::testing::AssertionFailure() << "could not find resource"; } if (val.dataType != Res_value::TYPE_STRING) { return ::testing::AssertionFailure() << "resource is not a string"; } const ResStringPool* pool = table.getTableStringBlock(block); if (pool == NULL) { return ::testing::AssertionFailure() << "table has no string pool for block " << block; } const String8 actual = pool->string8ObjectAt(val.data); if (String8(expectedStr) != actual) { return ::testing::AssertionFailure() << actual.string(); } return ::testing::AssertionSuccess() << actual.string(); } } // namespace android
libs/androidfw/tests/TestHelpers.h +5 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <androidfw/ResourceTypes.h> #include <utils/String8.h> #include <utils/String16.h> #include <gtest/gtest.h> static inline ::std::ostream& operator<<(::std::ostream& out, const android::String8& str) { return out << str.string(); Loading @@ -17,6 +18,8 @@ static inline ::std::ostream& operator<<(::std::ostream& out, const android::Str namespace android { enum { MAY_NOT_BE_BAG = false }; static inline bool operator==(const android::ResTable_config& a, const android::ResTable_config& b) { return memcmp(&a, &b, sizeof(a)) == 0; } Loading @@ -25,6 +28,8 @@ static inline ::std::ostream& operator<<(::std::ostream& out, const android::Res return out << c.toString().string(); } ::testing::AssertionResult IsStringEqual(const ResTable& table, uint32_t resourceId, const char* expectedStr); } // namespace android #endif // __TEST_HELPERS_H