summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGreg Hackmann <ghackmann@google.com>2013-02-12 16:39:31 -0800
committerColin Cross <ccross@android.com>2013-06-18 19:24:29 -0700
commitc6ff844d75dddfb19fc804b8add2d6a79947b101 (patch)
treef7eda9c4bf1279480f00c4a27b2009246a1d1f19 /tests
parentc656d732c7712b0f73d9c560ccf3cb5ae47d219d (diff)
downloadbionic-c6ff844d75dddfb19fc804b8add2d6a79947b101.zip
bionic-c6ff844d75dddfb19fc804b8add2d6a79947b101.tar.gz
bionic-c6ff844d75dddfb19fc804b8add2d6a79947b101.tar.bz2
bionic: add __system_property_foreach
find_nth() will be inefficient on a trie. Since find_nth() is only used internally and only for enumerating properties, we can add a foreach() function to do this directly. Signed-off-by: Greg Hackmann <ghackmann@google.com> (cherry picked from commit 577418403d68e663fb33c7b0c8a90d862d9c00cf) Change-Id: Iaca97d1182ce2c28863ba85241cbb5cf6185eb2f
Diffstat (limited to 'tests')
-rw-r--r--tests/system_properties_test.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index 60188f4..70ff1d6 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -125,6 +125,25 @@ TEST(properties, fill_247) {
}
}
+static void foreach_test_callback(const prop_info *pi, void* cookie) {
+ size_t *count = static_cast<size_t *>(cookie);
+
+ ASSERT_NE((prop_info *)NULL, pi);
+ (*count)++;
+}
+
+TEST(properties, foreach) {
+ LocalPropertyTestState pa;
+ size_t count = 0;
+
+ ASSERT_EQ(0, __system_property_add("property", 8, "value1", 6));
+ ASSERT_EQ(0, __system_property_add("other_property", 14, "value2", 6));
+ ASSERT_EQ(0, __system_property_add("property_other", 14, "value3", 6));
+
+ ASSERT_EQ(0, __system_property_foreach(foreach_test_callback, &count));
+ ASSERT_EQ(3U, count);
+}
+
TEST(properties, find_nth) {
LocalPropertyTestState pa;