Move all libcutils tests into the gtests.

This also fixes the bug where we were always testing against the fake
strlcpy we provide for glibc/Windows rather than the Android one.

This also removes some unnecessary library dependencies.

This also builds all the cutils tests for the host (static and dynamic).

Change-Id: Icd129d5b025c0ca801be5acf31a54ecd88608df9
This commit is contained in:
Elliott Hughes 2015-04-02 13:36:54 -07:00
parent d8fb29b0c0
commit af98efbd15
6 changed files with 103 additions and 92 deletions

View File

@ -18,6 +18,9 @@
#define __CUTILS_STR_PARMS_H
#include <stdint.h>
#include <sys/cdefs.h>
__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 */

View File

@ -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))

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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 <cutils/str_parms.h>
#include <gtest/gtest.h>
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=");
}