1# Copyright (C) 2016 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15#
16
17LOCAL_PATH := $(call my-dir)
18
19# Defines a test module.
20#
21# The upstream gmock configuration builds each of these as separate executables.
22# It's a pain for how we run tests in the platform, but we can handle that with
23# a test running script.
24#
25# $(1): Test name. test/$(1).cc will automatically be added to sources.
26# $(2): Additional source files.
27# $(3): "libgmock_main" or empty.
28# $(4): Variant. Can be "_host", "_ndk", or empty.
29define gmock-unit-test
30    $(eval include $(CLEAR_VARS)) \
31    $(eval LOCAL_MODULE := $(1)$(4)) \
32    $(eval LOCAL_CPP_EXTENSION := .cc) \
33    $(eval LOCAL_SRC_FILES := test/$(strip $(1)).cc $(2)) \
34    $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \
35    $(eval LOCAL_C_INCLUDES += $(LOCAL_PATH)/../googletest) \
36    $(eval LOCAL_CFLAGS += -Wall -Werror -Wno-sign-compare -Wno-unused-parameter) \
37    $(eval LOCAL_CFLAGS += -Wno-unused-private-field) \
38    $(eval LOCAL_CPP_FEATURES := rtti) \
39    $(eval LOCAL_STATIC_LIBRARIES := $(if $(3),$(3)$(4)) libgmock$(4)) \
40    $(eval LOCAL_STATIC_LIBRARIES += libgtest$(4)) \
41    $(if $(findstring _ndk,$(4)),$(eval LOCAL_SDK_VERSION := 9)) \
42    $(eval LOCAL_NDK_STL_VARIANT := c++_static) \
43    $(if $(findstring _host,$(4)),,\
44        $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS))) \
45    $(eval $(if $(findstring _host,$(4)), \
46        include $(BUILD_HOST_EXECUTABLE), \
47        include $(BUILD_EXECUTABLE)))
48endef
49
50# Create modules for each test in the suite.
51#
52# $(1): Variant. Can be "_host", "_ndk", or empty.
53define gmock-test-suite
54    $(eval $(call gmock-unit-test,gmock-actions_test,,libgmock_main,$(1))) \
55    $(eval $(call gmock-unit-test,gmock-cardinalities_test,,libgmock_main,$(1))) \
56    $(eval $(call gmock-unit-test,gmock-generated-actions_test,,libgmock_main,$(1))) \
57    $(eval $(call gmock-unit-test,gmock-generated-function-mockers_test,,libgmock_main,$(1))) \
58    $(eval $(call gmock-unit-test,gmock-generated-internal-utils_test,,libgmock_main,$(1))) \
59    $(eval $(call gmock-unit-test,gmock-generated-matchers_test,,libgmock_main,$(1))) \
60    $(eval $(call gmock-unit-test,gmock-internal-utils_test,,libgmock_main,$(1))) \
61    $(eval $(call gmock-unit-test,gmock-matchers_test,,libgmock_main,$(1))) \
62    $(eval $(call gmock-unit-test,gmock-more-actions_test,,libgmock_main,$(1))) \
63    $(eval $(call gmock-unit-test,gmock-nice-strict_test,,libgmock_main,$(1))) \
64    $(eval $(call gmock-unit-test,gmock-port_test,,libgmock_main,$(1))) \
65    $(eval $(call gmock-unit-test,gmock-spec-builders_test,,libgmock_main,$(1))) \
66    $(eval $(call gmock-unit-test,gmock_link_test,test/gmock_link2_test.cc,libgmock_main,$(1))) \
67    $(eval $(call gmock-unit-test,gmock_test,,libgmock_main,$(1)))
68endef
69
70# Test is disabled because Android doesn't build gmock with exceptions.
71# $(eval $(call gmock-unit-test,gmock_ex_test,,libgmock_main,$(1)))
72
73$(call gmock-test-suite,)
74$(call gmock-test-suite,_host)
75