diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-01-05 17:03:55 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-01-06 16:51:48 -0800 |
commit | 06d3e8fec7e2b29f99d755bee849023d88957953 (patch) | |
tree | 328055c7a9632e9660e836d4dfd0cfcc0450700e /libs/androidfw/tests/AttributeResolution_test.cpp | |
parent | 0a454c39cb5bc03cd646546aa3b8baaed1962178 (diff) |
libandroidfw: Revert null check in ApplyStyle
The out parameter `out_indices` is expected to be non-null
and so the extra null check adds a cost to performance
and opens the door to misusing the API by not supplying
`out_indices`.
Test: make libandroidfw_tests
Change-Id: Ie66fd837c5e24ec2838156e7b67f54c15cd27933
Diffstat (limited to 'libs/androidfw/tests/AttributeResolution_test.cpp')
-rw-r--r-- | libs/androidfw/tests/AttributeResolution_test.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/libs/androidfw/tests/AttributeResolution_test.cpp b/libs/androidfw/tests/AttributeResolution_test.cpp index d417aba1c595..75505171133c 100644 --- a/libs/androidfw/tests/AttributeResolution_test.cpp +++ b/libs/androidfw/tests/AttributeResolution_test.cpp @@ -16,6 +16,8 @@ #include "androidfw/AttributeResolution.h" +#include <array> + #include "android-base/file.h" #include "android-base/logging.h" #include "android-base/macros.h" @@ -67,15 +69,13 @@ TEST_F(AttributeResolutionTest, Theme) { ResTable::Theme theme(table_); ASSERT_EQ(NO_ERROR, theme.applyStyle(R::style::StyleTwo)); - uint32_t attrs[] = {R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, - R::attr::attr_four}; - std::vector<uint32_t> values; - values.resize(arraysize(attrs) * 6); + std::array<uint32_t, 4> attrs{ + {R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, R::attr::attr_four}}; + std::array<uint32_t, attrs.size() * STYLE_NUM_ENTRIES> values; ASSERT_TRUE(ResolveAttrs(&theme, 0 /*def_style_attr*/, 0 /*def_style_res*/, - nullptr /*src_values*/, 0 /*src_values_length*/, - attrs, arraysize(attrs), values.data(), - nullptr /*out_indices*/)); + nullptr /*src_values*/, 0 /*src_values_length*/, attrs.data(), + attrs.size(), values.data(), nullptr /*out_indices*/)); const uint32_t public_flag = ResTable_typeSpec::SPEC_PUBLIC; @@ -112,13 +112,12 @@ TEST_F(AttributeResolutionTest, Theme) { } TEST_F(AttributeResolutionXmlTest, XmlParser) { - uint32_t attrs[] = {R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, - R::attr::attr_four}; - std::vector<uint32_t> values; - values.resize(arraysize(attrs) * 6); + std::array<uint32_t, 4> attrs{ + {R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, R::attr::attr_four}}; + std::array<uint32_t, attrs.size() * STYLE_NUM_ENTRIES> values; - ASSERT_TRUE(RetrieveAttributes(&table_, &xml_parser_, attrs, arraysize(attrs), - values.data(), nullptr /*out_indices*/)); + ASSERT_TRUE(RetrieveAttributes(&table_, &xml_parser_, attrs.data(), attrs.size(), values.data(), + nullptr /*out_indices*/)); uint32_t* values_cursor = values.data(); EXPECT_EQ(Res_value::TYPE_NULL, values_cursor[STYLE_TYPE]); @@ -157,14 +156,13 @@ TEST_F(AttributeResolutionXmlTest, ThemeAndXmlParser) { ResTable::Theme theme(table_); ASSERT_EQ(NO_ERROR, theme.applyStyle(R::style::StyleTwo)); - uint32_t attrs[] = {R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, - R::attr::attr_four, R::attr::attr_five}; - std::vector<uint32_t> values; - values.resize(arraysize(attrs) * 6); + std::array<uint32_t, 5> attrs{{R::attr::attr_one, R::attr::attr_two, R::attr::attr_three, + R::attr::attr_four, R::attr::attr_five}}; + std::array<uint32_t, attrs.size() * STYLE_NUM_ENTRIES> values; + std::array<uint32_t, attrs.size()> indices; - ApplyStyle(&theme, &xml_parser_, 0 /*def_style_attr*/, - 0 /*def_style_res*/, attrs, arraysize(attrs), - values.data(), nullptr /*out_indices*/); + ApplyStyle(&theme, &xml_parser_, 0 /*def_style_attr*/, 0 /*def_style_res*/, attrs.data(), + attrs.size(), values.data(), indices.data()); const uint32_t public_flag = ResTable_typeSpec::SPEC_PUBLIC; |