diff options
-rw-r--r-- | include/cutils/str_parms.h | 5 | ||||
-rw-r--r-- | libcutils/Android.mk | 26 | ||||
-rw-r--r-- | libcutils/iosched_policy.c | 2 | ||||
-rw-r--r-- | libcutils/str_parms.c | 50 | ||||
-rw-r--r-- | libcutils/tests/Android.mk | 51 | ||||
-rw-r--r-- | libcutils/tests/test_str_parms.cpp | 57 |
6 files changed, 101 insertions, 90 deletions
diff --git a/include/cutils/str_parms.h b/include/cutils/str_parms.h index 66f363770..aa1435a08 100644 --- a/include/cutils/str_parms.h +++ b/include/cutils/str_parms.h | |||
@@ -18,6 +18,9 @@ | |||
18 | #define __CUTILS_STR_PARMS_H | 18 | #define __CUTILS_STR_PARMS_H |
19 | 19 | ||
20 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #include <sys/cdefs.h> | ||
22 | |||
23 | __BEGIN_DECLS | ||
21 | 24 | ||
22 | struct str_parms; | 25 | struct str_parms; |
23 | 26 | ||
@@ -52,4 +55,6 @@ char *str_parms_to_str(struct str_parms *str_parms); | |||
52 | /* debug */ | 55 | /* debug */ |
53 | void str_parms_dump(struct str_parms *str_parms); | 56 | void str_parms_dump(struct str_parms *str_parms); |
54 | 57 | ||
58 | __END_DECLS | ||
59 | |||
55 | #endif /* __CUTILS_STR_PARMS_H */ | 60 | #endif /* __CUTILS_STR_PARMS_H */ |
diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 71fdfd35d..62c61138a 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk | |||
@@ -75,7 +75,6 @@ ifneq ($(HOST_OS),windows) | |||
75 | LOCAL_CFLAGS += -Werror | 75 | LOCAL_CFLAGS += -Werror |
76 | endif | 76 | endif |
77 | LOCAL_MULTILIB := both | 77 | LOCAL_MULTILIB := both |
78 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
79 | include $(BUILD_HOST_STATIC_LIBRARY) | 78 | include $(BUILD_HOST_STATIC_LIBRARY) |
80 | 79 | ||
81 | include $(CLEAR_VARS) | 80 | include $(CLEAR_VARS) |
@@ -86,22 +85,8 @@ ifneq ($(HOST_OS),windows) | |||
86 | LOCAL_CFLAGS += -Werror | 85 | LOCAL_CFLAGS += -Werror |
87 | endif | 86 | endif |
88 | LOCAL_MULTILIB := both | 87 | LOCAL_MULTILIB := both |
89 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
90 | include $(BUILD_HOST_SHARED_LIBRARY) | 88 | include $(BUILD_HOST_SHARED_LIBRARY) |
91 | 89 | ||
92 | # Tests for host | ||
93 | # ======================================================== | ||
94 | include $(CLEAR_VARS) | ||
95 | LOCAL_MODULE := tst_str_parms | ||
96 | LOCAL_CFLAGS += -DTEST_STR_PARMS | ||
97 | ifneq ($(HOST_OS),windows) | ||
98 | LOCAL_CFLAGS += -Werror | ||
99 | endif | ||
100 | LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c | ||
101 | LOCAL_STATIC_LIBRARIES := liblog | ||
102 | LOCAL_MODULE_TAGS := optional | ||
103 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
104 | include $(BUILD_HOST_EXECUTABLE) | ||
105 | 90 | ||
106 | 91 | ||
107 | # Shared and static library for target | 92 | # Shared and static library for target |
@@ -139,7 +124,6 @@ LOCAL_SRC_FILES_x86_64 += \ | |||
139 | LOCAL_C_INCLUDES := $(libcutils_c_includes) | 124 | LOCAL_C_INCLUDES := $(libcutils_c_includes) |
140 | LOCAL_STATIC_LIBRARIES := liblog | 125 | LOCAL_STATIC_LIBRARIES := liblog |
141 | LOCAL_CFLAGS += -Werror -std=gnu90 | 126 | LOCAL_CFLAGS += -Werror -std=gnu90 |
142 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
143 | include $(BUILD_STATIC_LIBRARY) | 127 | include $(BUILD_STATIC_LIBRARY) |
144 | 128 | ||
145 | include $(CLEAR_VARS) | 129 | include $(CLEAR_VARS) |
@@ -150,16 +134,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog | |||
150 | LOCAL_SHARED_LIBRARIES := liblog | 134 | LOCAL_SHARED_LIBRARIES := liblog |
151 | LOCAL_CFLAGS += -Werror | 135 | LOCAL_CFLAGS += -Werror |
152 | LOCAL_C_INCLUDES := $(libcutils_c_includes) | 136 | LOCAL_C_INCLUDES := $(libcutils_c_includes) |
153 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
154 | include $(BUILD_SHARED_LIBRARY) | 137 | include $(BUILD_SHARED_LIBRARY) |
155 | 138 | ||
156 | include $(CLEAR_VARS) | ||
157 | LOCAL_MODULE := tst_str_parms | ||
158 | LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror | ||
159 | LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c | ||
160 | LOCAL_SHARED_LIBRARIES := liblog | ||
161 | LOCAL_MODULE_TAGS := optional | ||
162 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
163 | include $(BUILD_EXECUTABLE) | ||
164 | |||
165 | include $(call all-makefiles-under,$(LOCAL_PATH)) | 139 | include $(call all-makefiles-under,$(LOCAL_PATH)) |
diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index a6da9cac6..8946d3c14 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** Copyright 2007-2014, The Android Open Source Project | 2 | ** Copyright 2007, The Android Open Source Project |
3 | ** | 3 | ** |
4 | ** Licensed under the Apache License, Version 2.0 (the "License"); | 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
5 | ** you may not use this file except in compliance with the License. | 5 | ** you may not use this file except in compliance with the License. |
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c index dfe8c4ba7..924289aa9 100644 --- a/libcutils/str_parms.c +++ b/libcutils/str_parms.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2011-2013 The Android Open Source Project | 2 | * Copyright (C) 2011 The Android Open Source Project |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
@@ -357,51 +357,3 @@ void str_parms_dump(struct str_parms *str_parms) | |||
357 | { | 357 | { |
358 | hashmapForEach(str_parms->map, dump_entry, str_parms); | 358 | hashmapForEach(str_parms->map, dump_entry, str_parms); |
359 | } | 359 | } |
360 | |||
361 | #ifdef TEST_STR_PARMS | ||
362 | static void test_str_parms_str(const char *str) | ||
363 | { | ||
364 | struct str_parms *str_parms; | ||
365 | char *out_str; | ||
366 | |||
367 | str_parms = str_parms_create_str(str); | ||
368 | str_parms_add_str(str_parms, "dude", "woah"); | ||
369 | str_parms_add_str(str_parms, "dude", "woah"); | ||
370 | str_parms_del(str_parms, "dude"); | ||
371 | str_parms_dump(str_parms); | ||
372 | out_str = str_parms_to_str(str_parms); | ||
373 | str_parms_destroy(str_parms); | ||
374 | ALOGI("%s: '%s' stringified is '%s'", __func__, str, out_str); | ||
375 | free(out_str); | ||
376 | } | ||
377 | |||
378 | int main(void) | ||
379 | { | ||
380 | test_str_parms_str(""); | ||
381 | test_str_parms_str(";"); | ||
382 | test_str_parms_str("="); | ||
383 | test_str_parms_str("=;"); | ||
384 | test_str_parms_str("=bar"); | ||
385 | test_str_parms_str("=bar;"); | ||
386 | test_str_parms_str("foo="); | ||
387 | test_str_parms_str("foo=;"); | ||
388 | test_str_parms_str("foo=bar"); | ||
389 | test_str_parms_str("foo=bar;"); | ||
390 | test_str_parms_str("foo=bar;baz"); | ||
391 | test_str_parms_str("foo=bar;baz="); | ||
392 | test_str_parms_str("foo=bar;baz=bat"); | ||
393 | test_str_parms_str("foo=bar;baz=bat;"); | ||
394 | test_str_parms_str("foo=bar;baz=bat;foo=bar"); | ||
395 | |||
396 | // hashmapPut reports errors by setting errno to ENOMEM. | ||
397 | // Test that we're not confused by running in an environment where this is already true. | ||
398 | errno = ENOMEM; | ||
399 | test_str_parms_str("foo=bar;baz="); | ||
400 | if (errno != ENOMEM) { | ||
401 | abort(); | ||
402 | } | ||
403 | test_str_parms_str("foo=bar;baz="); | ||
404 | |||
405 | return 0; | ||
406 | } | ||
407 | #endif | ||
diff --git a/libcutils/tests/Android.mk b/libcutils/tests/Android.mk index d532dfbf5..cf70345cf 100644 --- a/libcutils/tests/Android.mk +++ b/libcutils/tests/Android.mk | |||
@@ -15,36 +15,59 @@ | |||
15 | LOCAL_PATH := $(call my-dir) | 15 | LOCAL_PATH := $(call my-dir) |
16 | 16 | ||
17 | test_src_files := \ | 17 | test_src_files := \ |
18 | test_str_parms.cpp \ | ||
19 | |||
20 | test_target_only_src_files := \ | ||
18 | MemsetTest.cpp \ | 21 | MemsetTest.cpp \ |
19 | PropertiesTest.cpp \ | 22 | PropertiesTest.cpp \ |
20 | 23 | ||
24 | test_libraries := libcutils liblog | ||
25 | |||
26 | |||
27 | # | ||
28 | # Target. | ||
29 | # | ||
30 | |||
21 | include $(CLEAR_VARS) | 31 | include $(CLEAR_VARS) |
22 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
23 | LOCAL_MODULE := libcutils_test | 32 | LOCAL_MODULE := libcutils_test |
24 | LOCAL_SRC_FILES := $(test_src_files) | 33 | LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) |
25 | LOCAL_SHARED_LIBRARIES := \ | 34 | LOCAL_SHARED_LIBRARIES := $(test_libraries) |
26 | libcutils \ | ||
27 | liblog \ | ||
28 | libutils \ | ||
29 | |||
30 | LOCAL_MULTILIB := both | 35 | LOCAL_MULTILIB := both |
31 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 | 36 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 |
32 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 | 37 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 |
33 | include $(BUILD_NATIVE_TEST) | 38 | include $(BUILD_NATIVE_TEST) |
34 | 39 | ||
35 | include $(CLEAR_VARS) | 40 | include $(CLEAR_VARS) |
36 | LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk | ||
37 | LOCAL_MODULE := libcutils_test_static | 41 | LOCAL_MODULE := libcutils_test_static |
38 | LOCAL_FORCE_STATIC_EXECUTABLE := true | 42 | LOCAL_FORCE_STATIC_EXECUTABLE := true |
43 | LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) | ||
44 | LOCAL_STATIC_LIBRARIES := libc $(test_libraries) | ||
45 | LOCAL_CXX_STL := libc++_static | ||
46 | LOCAL_MULTILIB := both | ||
47 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 | ||
48 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 | ||
49 | include $(BUILD_NATIVE_TEST) | ||
50 | |||
51 | |||
52 | # | ||
53 | # Host. | ||
54 | # | ||
55 | |||
56 | include $(CLEAR_VARS) | ||
57 | LOCAL_MODULE := libcutils_test | ||
39 | LOCAL_SRC_FILES := $(test_src_files) | 58 | LOCAL_SRC_FILES := $(test_src_files) |
40 | LOCAL_STATIC_LIBRARIES := \ | 59 | LOCAL_SHARED_LIBRARIES := $(test_libraries) |
41 | libc \ | 60 | LOCAL_MULTILIB := both |
42 | libcutils \ | 61 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 |
43 | liblog \ | 62 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 |
44 | libutils \ | 63 | include $(BUILD_HOST_NATIVE_TEST) |
45 | 64 | ||
65 | include $(CLEAR_VARS) | ||
66 | LOCAL_MODULE := libcutils_test_static | ||
67 | LOCAL_SRC_FILES := $(test_src_files) | ||
68 | LOCAL_STATIC_LIBRARIES := $(test_libraries) | ||
46 | LOCAL_CXX_STL := libc++_static | 69 | LOCAL_CXX_STL := libc++_static |
47 | LOCAL_MULTILIB := both | 70 | LOCAL_MULTILIB := both |
48 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 | 71 | LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 |
49 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 | 72 | LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 |
50 | include $(BUILD_NATIVE_TEST) | 73 | include $(BUILD_HOST_NATIVE_TEST) |
diff --git a/libcutils/tests/test_str_parms.cpp b/libcutils/tests/test_str_parms.cpp new file mode 100644 index 000000000..d8f639b4b --- /dev/null +++ b/libcutils/tests/test_str_parms.cpp | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 The Android Open Source Project | ||
3 | * | ||
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 | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
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. | ||
15 | */ | ||
16 | |||
17 | #include <cutils/str_parms.h> | ||
18 | #include <gtest/gtest.h> | ||
19 | |||
20 | static void test_str_parms_str(const char* str, const char* expected) { | ||
21 | str_parms* str_parms = str_parms_create_str(str); | ||
22 | str_parms_add_str(str_parms, "dude", "woah"); | ||
23 | str_parms_add_str(str_parms, "dude", "woah"); | ||
24 | str_parms_del(str_parms, "dude"); | ||
25 | str_parms_dump(str_parms); | ||
26 | char* out_str = str_parms_to_str(str_parms); | ||
27 | str_parms_destroy(str_parms); | ||
28 | ASSERT_STREQ(expected, out_str) << str; | ||
29 | free(out_str); | ||
30 | } | ||
31 | |||
32 | TEST(str_parms, smoke) { | ||
33 | test_str_parms_str("", ""); | ||
34 | test_str_parms_str(";", ""); | ||
35 | test_str_parms_str("=", ""); | ||
36 | test_str_parms_str("=;", ""); | ||
37 | test_str_parms_str("=bar", ""); | ||
38 | test_str_parms_str("=bar;", ""); | ||
39 | test_str_parms_str("foo=", "foo="); | ||
40 | test_str_parms_str("foo=;", "foo="); | ||
41 | test_str_parms_str("foo=bar", "foo=bar"); | ||
42 | test_str_parms_str("foo=bar;", "foo=bar"); | ||
43 | test_str_parms_str("foo=bar;baz", "foo=bar;baz="); | ||
44 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); | ||
45 | test_str_parms_str("foo=bar;baz=bat", "foo=bar;baz=bat"); | ||
46 | test_str_parms_str("foo=bar;baz=bat;", "foo=bar;baz=bat"); | ||
47 | test_str_parms_str("foo=bar1;baz=bat;foo=bar2", "foo=bar2;baz=bat"); | ||
48 | } | ||
49 | |||
50 | TEST(str_parms, put_ENOMEM) { | ||
51 | // hashmapPut reports errors by setting errno to ENOMEM. | ||
52 | // Test that we're not confused by running in an environment where this is already true. | ||
53 | errno = ENOMEM; | ||
54 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); | ||
55 | ASSERT_EQ(ENOMEM, errno); | ||
56 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); | ||
57 | } | ||