summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2015-04-02 16:26:32 -0500
committerGerrit Code Review2015-04-02 16:26:32 -0500
commit2159318647b6032a9d752012b923c579dc1f80da (patch)
treef01619eb6b1f5475cdb1f31c8119af854531e244
parentd8fb29b0c09de25c416141a4bb150cc7db9f28ca (diff)
parentaf98efbd15878fbd97fd3ef3c413d739ed9589e9 (diff)
downloadplatform-system-core-2159318647b6032a9d752012b923c579dc1f80da.tar.gz
platform-system-core-2159318647b6032a9d752012b923c579dc1f80da.tar.xz
platform-system-core-2159318647b6032a9d752012b923c579dc1f80da.zip
Merge "Move all libcutils tests into the gtests."
-rw-r--r--include/cutils/str_parms.h5
-rw-r--r--libcutils/Android.mk26
-rw-r--r--libcutils/iosched_policy.c2
-rw-r--r--libcutils/str_parms.c50
-rw-r--r--libcutils/tests/Android.mk51
-rw-r--r--libcutils/tests/test_str_parms.cpp57
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
22struct str_parms; 25struct str_parms;
23 26
@@ -52,4 +55,6 @@ char *str_parms_to_str(struct str_parms *str_parms);
52/* debug */ 55/* debug */
53void str_parms_dump(struct str_parms *str_parms); 56void 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)
75LOCAL_CFLAGS += -Werror 75LOCAL_CFLAGS += -Werror
76endif 76endif
77LOCAL_MULTILIB := both 77LOCAL_MULTILIB := both
78LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
79include $(BUILD_HOST_STATIC_LIBRARY) 78include $(BUILD_HOST_STATIC_LIBRARY)
80 79
81include $(CLEAR_VARS) 80include $(CLEAR_VARS)
@@ -86,22 +85,8 @@ ifneq ($(HOST_OS),windows)
86LOCAL_CFLAGS += -Werror 85LOCAL_CFLAGS += -Werror
87endif 86endif
88LOCAL_MULTILIB := both 87LOCAL_MULTILIB := both
89LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
90include $(BUILD_HOST_SHARED_LIBRARY) 88include $(BUILD_HOST_SHARED_LIBRARY)
91 89
92# Tests for host
93# ========================================================
94include $(CLEAR_VARS)
95LOCAL_MODULE := tst_str_parms
96LOCAL_CFLAGS += -DTEST_STR_PARMS
97ifneq ($(HOST_OS),windows)
98LOCAL_CFLAGS += -Werror
99endif
100LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c
101LOCAL_STATIC_LIBRARIES := liblog
102LOCAL_MODULE_TAGS := optional
103LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
104include $(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 += \
139LOCAL_C_INCLUDES := $(libcutils_c_includes) 124LOCAL_C_INCLUDES := $(libcutils_c_includes)
140LOCAL_STATIC_LIBRARIES := liblog 125LOCAL_STATIC_LIBRARIES := liblog
141LOCAL_CFLAGS += -Werror -std=gnu90 126LOCAL_CFLAGS += -Werror -std=gnu90
142LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
143include $(BUILD_STATIC_LIBRARY) 127include $(BUILD_STATIC_LIBRARY)
144 128
145include $(CLEAR_VARS) 129include $(CLEAR_VARS)
@@ -150,16 +134,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog
150LOCAL_SHARED_LIBRARIES := liblog 134LOCAL_SHARED_LIBRARIES := liblog
151LOCAL_CFLAGS += -Werror 135LOCAL_CFLAGS += -Werror
152LOCAL_C_INCLUDES := $(libcutils_c_includes) 136LOCAL_C_INCLUDES := $(libcutils_c_includes)
153LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
154include $(BUILD_SHARED_LIBRARY) 137include $(BUILD_SHARED_LIBRARY)
155 138
156include $(CLEAR_VARS)
157LOCAL_MODULE := tst_str_parms
158LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror
159LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c
160LOCAL_SHARED_LIBRARIES := liblog
161LOCAL_MODULE_TAGS := optional
162LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
163include $(BUILD_EXECUTABLE)
164
165include $(call all-makefiles-under,$(LOCAL_PATH)) 139include $(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
362static 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
378int 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 @@
15LOCAL_PATH := $(call my-dir) 15LOCAL_PATH := $(call my-dir)
16 16
17test_src_files := \ 17test_src_files := \
18 test_str_parms.cpp \
19
20test_target_only_src_files := \
18 MemsetTest.cpp \ 21 MemsetTest.cpp \
19 PropertiesTest.cpp \ 22 PropertiesTest.cpp \
20 23
24test_libraries := libcutils liblog
25
26
27#
28# Target.
29#
30
21include $(CLEAR_VARS) 31include $(CLEAR_VARS)
22LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
23LOCAL_MODULE := libcutils_test 32LOCAL_MODULE := libcutils_test
24LOCAL_SRC_FILES := $(test_src_files) 33LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files)
25LOCAL_SHARED_LIBRARIES := \ 34LOCAL_SHARED_LIBRARIES := $(test_libraries)
26 libcutils \
27 liblog \
28 libutils \
29
30LOCAL_MULTILIB := both 35LOCAL_MULTILIB := both
31LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 36LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
32LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 37LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
33include $(BUILD_NATIVE_TEST) 38include $(BUILD_NATIVE_TEST)
34 39
35include $(CLEAR_VARS) 40include $(CLEAR_VARS)
36LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
37LOCAL_MODULE := libcutils_test_static 41LOCAL_MODULE := libcutils_test_static
38LOCAL_FORCE_STATIC_EXECUTABLE := true 42LOCAL_FORCE_STATIC_EXECUTABLE := true
43LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files)
44LOCAL_STATIC_LIBRARIES := libc $(test_libraries)
45LOCAL_CXX_STL := libc++_static
46LOCAL_MULTILIB := both
47LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
48LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
49include $(BUILD_NATIVE_TEST)
50
51
52#
53# Host.
54#
55
56include $(CLEAR_VARS)
57LOCAL_MODULE := libcutils_test
39LOCAL_SRC_FILES := $(test_src_files) 58LOCAL_SRC_FILES := $(test_src_files)
40LOCAL_STATIC_LIBRARIES := \ 59LOCAL_SHARED_LIBRARIES := $(test_libraries)
41 libc \ 60LOCAL_MULTILIB := both
42 libcutils \ 61LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
43 liblog \ 62LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
44 libutils \ 63include $(BUILD_HOST_NATIVE_TEST)
45 64
65include $(CLEAR_VARS)
66LOCAL_MODULE := libcutils_test_static
67LOCAL_SRC_FILES := $(test_src_files)
68LOCAL_STATIC_LIBRARIES := $(test_libraries)
46LOCAL_CXX_STL := libc++_static 69LOCAL_CXX_STL := libc++_static
47LOCAL_MULTILIB := both 70LOCAL_MULTILIB := both
48LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 71LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
49LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 72LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
50include $(BUILD_NATIVE_TEST) 73include $(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
20static 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
32TEST(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
50TEST(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}