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 @@ #define __CUTILS_STR_PARMS_H #include +#include + +__BEGIN_DECLS struct str_parms; @@ -52,4 +55,6 @@ char *str_parms_to_str(struct str_parms *str_parms); /* debug */ void str_parms_dump(struct str_parms *str_parms); +__END_DECLS + #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) LOCAL_CFLAGS += -Werror endif LOCAL_MULTILIB := both -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -86,22 +85,8 @@ ifneq ($(HOST_OS),windows) LOCAL_CFLAGS += -Werror endif LOCAL_MULTILIB := both -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_HOST_SHARED_LIBRARY) -# Tests for host -# ======================================================== -include $(CLEAR_VARS) -LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS -ifneq ($(HOST_OS),windows) -LOCAL_CFLAGS += -Werror -endif -LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c -LOCAL_STATIC_LIBRARIES := liblog -LOCAL_MODULE_TAGS := optional -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -include $(BUILD_HOST_EXECUTABLE) # Shared and static library for target @@ -139,7 +124,6 @@ LOCAL_SRC_FILES_x86_64 += \ LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += -Werror -std=gnu90 -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -150,16 +134,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog LOCAL_SHARED_LIBRARIES := liblog LOCAL_CFLAGS += -Werror LOCAL_C_INCLUDES := $(libcutils_c_includes) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_SHARED_LIBRARY) -include $(CLEAR_VARS) -LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror -LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c -LOCAL_SHARED_LIBRARIES := liblog -LOCAL_MODULE_TAGS := optional -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -include $(BUILD_EXECUTABLE) - 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 @@ /* -** Copyright 2007-2014, The Android Open Source Project +** Copyright 2007, 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. 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 @@ /* - * Copyright (C) 2011-2013 The Android Open Source Project + * Copyright (C) 2011 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. @@ -357,51 +357,3 @@ void str_parms_dump(struct str_parms *str_parms) { hashmapForEach(str_parms->map, dump_entry, str_parms); } - -#ifdef TEST_STR_PARMS -static void test_str_parms_str(const char *str) -{ - struct str_parms *str_parms; - char *out_str; - - str_parms = str_parms_create_str(str); - str_parms_add_str(str_parms, "dude", "woah"); - str_parms_add_str(str_parms, "dude", "woah"); - str_parms_del(str_parms, "dude"); - str_parms_dump(str_parms); - out_str = str_parms_to_str(str_parms); - str_parms_destroy(str_parms); - ALOGI("%s: '%s' stringified is '%s'", __func__, str, out_str); - free(out_str); -} - -int main(void) -{ - test_str_parms_str(""); - test_str_parms_str(";"); - test_str_parms_str("="); - test_str_parms_str("=;"); - test_str_parms_str("=bar"); - test_str_parms_str("=bar;"); - test_str_parms_str("foo="); - test_str_parms_str("foo=;"); - test_str_parms_str("foo=bar"); - test_str_parms_str("foo=bar;"); - test_str_parms_str("foo=bar;baz"); - test_str_parms_str("foo=bar;baz="); - test_str_parms_str("foo=bar;baz=bat"); - test_str_parms_str("foo=bar;baz=bat;"); - test_str_parms_str("foo=bar;baz=bat;foo=bar"); - - // hashmapPut reports errors by setting errno to ENOMEM. - // Test that we're not confused by running in an environment where this is already true. - errno = ENOMEM; - test_str_parms_str("foo=bar;baz="); - if (errno != ENOMEM) { - abort(); - } - test_str_parms_str("foo=bar;baz="); - - return 0; -} -#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 @@ LOCAL_PATH := $(call my-dir) test_src_files := \ + test_str_parms.cpp \ + +test_target_only_src_files := \ MemsetTest.cpp \ PropertiesTest.cpp \ -include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -LOCAL_MODULE := libcutils_test -LOCAL_SRC_FILES := $(test_src_files) -LOCAL_SHARED_LIBRARIES := \ - libcutils \ - liblog \ - libutils \ +test_libraries := libcutils liblog + +# +# Target. +# + +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test +LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) +LOCAL_SHARED_LIBRARIES := $(test_libraries) LOCAL_MULTILIB := both LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 include $(BUILD_NATIVE_TEST) include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk LOCAL_MODULE := libcutils_test_static LOCAL_FORCE_STATIC_EXECUTABLE := true -LOCAL_SRC_FILES := $(test_src_files) -LOCAL_STATIC_LIBRARIES := \ - libc \ - libcutils \ - liblog \ - libutils \ - +LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) +LOCAL_STATIC_LIBRARIES := libc $(test_libraries) LOCAL_CXX_STL := libc++_static LOCAL_MULTILIB := both LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 include $(BUILD_NATIVE_TEST) + + +# +# Host. +# + +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test +LOCAL_SRC_FILES := $(test_src_files) +LOCAL_SHARED_LIBRARIES := $(test_libraries) +LOCAL_MULTILIB := both +LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 +LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 +include $(BUILD_HOST_NATIVE_TEST) + +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test_static +LOCAL_SRC_FILES := $(test_src_files) +LOCAL_STATIC_LIBRARIES := $(test_libraries) +LOCAL_CXX_STL := libc++_static +LOCAL_MULTILIB := both +LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 +LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 +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 @@ +/* + * Copyright (C) 2011 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 +#include + +static void test_str_parms_str(const char* str, const char* expected) { + str_parms* str_parms = str_parms_create_str(str); + str_parms_add_str(str_parms, "dude", "woah"); + str_parms_add_str(str_parms, "dude", "woah"); + str_parms_del(str_parms, "dude"); + str_parms_dump(str_parms); + char* out_str = str_parms_to_str(str_parms); + str_parms_destroy(str_parms); + ASSERT_STREQ(expected, out_str) << str; + free(out_str); +} + +TEST(str_parms, smoke) { + test_str_parms_str("", ""); + test_str_parms_str(";", ""); + test_str_parms_str("=", ""); + test_str_parms_str("=;", ""); + test_str_parms_str("=bar", ""); + test_str_parms_str("=bar;", ""); + test_str_parms_str("foo=", "foo="); + test_str_parms_str("foo=;", "foo="); + test_str_parms_str("foo=bar", "foo=bar"); + test_str_parms_str("foo=bar;", "foo=bar"); + test_str_parms_str("foo=bar;baz", "foo=bar;baz="); + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); + test_str_parms_str("foo=bar;baz=bat", "foo=bar;baz=bat"); + test_str_parms_str("foo=bar;baz=bat;", "foo=bar;baz=bat"); + test_str_parms_str("foo=bar1;baz=bat;foo=bar2", "foo=bar2;baz=bat"); +} + +TEST(str_parms, put_ENOMEM) { + // hashmapPut reports errors by setting errno to ENOMEM. + // Test that we're not confused by running in an environment where this is already true. + errno = ENOMEM; + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); + ASSERT_EQ(ENOMEM, errno); + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); +}