Skip to content

Commit d221c5f

Browse files
authored
Add Firestore tests on desktop to an "internal" integration test. (#333)
All of the tests have been brought in. They run and succeed on Linux and Mac. Not yet tested on Windows. Building and running on mobile, and support for triggering these tests in the integration test workflow, will come in a future PR.
1 parent 897c619 commit d221c5f

File tree

67 files changed

+11291
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+11291
-58
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/* Copyright 2020 Google LLC
4+
**
5+
** Licensed under the Apache License, Version 2.0 (the "License");
6+
** you may not use this file except in compliance with the License.
7+
** You may obtain a copy of the License at
8+
**
9+
** http://www.apache.org/licenses/LICENSE-2.0
10+
**
11+
** Unless required by applicable law or agreed to in writing, software
12+
** distributed under the License is distributed on an "AS IS" BASIS,
13+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
** See the License for the specific language governing permissions and
15+
** limitations under the License.
16+
*/
17+
-->
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.google.firebase.cpp.database.testapp"
20+
android:versionCode="1"
21+
android:versionName="1.0">
22+
<uses-permission android:name="android.permission.INTERNET" />
23+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
24+
<uses-permission android:name="android.permission.WAKE_LOCK" />
25+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
26+
<application android:label="@string/app_name">
27+
<activity android:name="android.app.NativeActivity"
28+
android:screenOrientation="portrait"
29+
android:configChanges="orientation|screenSize">
30+
<meta-data android:name="android.app.lib_name"
31+
android:value="android_integration_test_main" />
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN" />
34+
<category android:name="android.intent.category.LAUNCHER" />
35+
</intent-filter>
36+
<intent-filter>
37+
<action android:name="com.google.intent.action.TEST_LOOP"/>
38+
<category android:name="android.intent.category.DEFAULT"/>
39+
<data android:mimeType="application/javascript"/>
40+
</intent-filter>
41+
</activity>
42+
</application>
43+
</manifest>
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# Copyright 2020 Google LLC
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+
# Cmake file for a single C++ integration test build.
16+
17+
cmake_minimum_required(VERSION 2.8)
18+
19+
# User settings for Firebase integration tests.
20+
# Path to Firebase SDK.
21+
# Try to read the path to the Firebase C++ SDK from an environment variable.
22+
if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
23+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
24+
else()
25+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../cpp_sdk_version.json")
26+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
27+
else()
28+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
29+
endif()
30+
endif()
31+
if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
32+
set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
33+
endif()
34+
if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
35+
message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
36+
endif()
37+
38+
# Copy all prerequisite files for integration tests to run.
39+
if(NOT ANDROID)
40+
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py)
41+
# If this is running from inside the SDK directory, run the setup script.
42+
execute_process(COMMAND "python" "${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py" "${CMAKE_CURRENT_LIST_DIR}")
43+
endif()
44+
endif()
45+
46+
# Windows runtime mode, either MD or MT depending on whether you are using
47+
# /MD or /MT. For more information see:
48+
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
49+
set(MSVC_RUNTIME_MODE MD)
50+
51+
project(firebase_testapp)
52+
53+
# Integration test source files.
54+
set(FIREBASE_APP_FRAMEWORK_SRCS
55+
src/app_framework.cc
56+
src/app_framework.h
57+
)
58+
59+
set(FIREBASE_TEST_FRAMEWORK_SRCS
60+
src/firebase_test_framework.h
61+
src/firebase_test_framework.cc
62+
)
63+
64+
set(FIREBASE_INTEGRATION_TEST_SRCS
65+
src/array_transform_test.cc
66+
src/cleanup_test.cc
67+
src/collection_reference_test.cc
68+
src/cursor_test.cc
69+
src/document_change_test.cc
70+
src/document_reference_test.cc
71+
src/document_snapshot_test.cc
72+
src/field_value_test.cc
73+
src/fields_test.cc
74+
src/includes_test.cc
75+
src/listener_registration_test.cc
76+
src/numeric_transforms_test.cc
77+
src/query_network_test.cc
78+
src/query_snapshot_test.cc
79+
src/query_test.cc
80+
src/sanity_test.cc
81+
src/server_timestamp_test.cc
82+
src/smoke_test.cc
83+
src/transaction_extra_test.cc
84+
src/transaction_test.cc
85+
src/type_test.cc
86+
src/validation_test.cc
87+
src/write_batch_test.cc
88+
src/firestore_test.cc
89+
src/util/future_test_util.cc
90+
src/util/integration_test_util.cc
91+
src/firestore_integration_test.cc
92+
)
93+
94+
# The include directory for the testapp.
95+
include_directories(src)
96+
# The include directory for the C++ SDK root.
97+
include_directories(${FIREBASE_CPP_SDK_DIR})
98+
# Additional public headers from Firestore core SDK.
99+
include_directories(${PROJECT_BINARY_DIR}/bin/external/src/firestore)
100+
# Additional public headers for absl.
101+
include_directories(${PROJECT_BINARY_DIR}/bin/external/src/firestore-build/external/src/abseil-cpp)
102+
# Allow testing internal Firebase APIs.
103+
add_definitions(-DINTERNAL_EXPERIMENTAL)
104+
105+
# Integration test uses some features that require C++ 11, such as lambdas.
106+
set (CMAKE_CXX_STANDARD 11)
107+
108+
# Download and unpack googletest (and googlemock) at configure time
109+
set(GOOGLETEST_ROOT ${CMAKE_CURRENT_LIST_DIR}/external/googletest)
110+
# Note: Once googletest is downloaded once, it won't be updated or
111+
# downloaded again unless you delete the "external/googletest"
112+
# directory.
113+
if (NOT EXISTS ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
114+
configure_file(googletest.cmake
115+
${CMAKE_CURRENT_LIST_DIR}/external/googletest/CMakeLists.txt COPYONLY)
116+
execute_process(COMMAND ${CMAKE_COMMAND} .
117+
RESULT_VARIABLE result
118+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
119+
if(result)
120+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
121+
endif()
122+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
123+
RESULT_VARIABLE result
124+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
125+
if(result)
126+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
127+
endif()
128+
endif()
129+
130+
if(ANDROID)
131+
# Build an Android application.
132+
133+
# Source files used for the Android build.
134+
set(FIREBASE_APP_FRAMEWORK_ANDROID_SRCS
135+
src/android/android_app_framework.cc
136+
)
137+
138+
# Source files used for the Android build.
139+
set(FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS
140+
src/android/android_firebase_test_framework.cc
141+
)
142+
143+
# Build native_app_glue as a static lib
144+
add_library(native_app_glue STATIC
145+
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
146+
147+
# Export ANativeActivity_onCreate(),
148+
# Refer to: https://github.com/android-ndk/ndk/issues/381.
149+
set(CMAKE_SHARED_LINKER_FLAGS
150+
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
151+
152+
add_library(gtest STATIC
153+
${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
154+
target_include_directories(gtest
155+
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
156+
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include)
157+
add_library(gmock STATIC
158+
${GOOGLETEST_ROOT}/src/googlemock/src/gmock-all.cc)
159+
target_include_directories(gmock
160+
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
161+
PRIVATE ${GOOGLETEST_ROOT}/src/googlemock
162+
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include
163+
PUBLIC ${GOOGLETEST_ROOT}/src/googlemock/include)
164+
165+
# Define the target as a shared library, as that is what gradle expects.
166+
set(integration_test_target_name "android_integration_test_main")
167+
add_library(${integration_test_target_name} SHARED
168+
${FIREBASE_APP_FRAMEWORK_SRCS}
169+
${FIREBASE_APP_FRAMEWORK_ANDROID_SRCS}
170+
${FIREBASE_INTEGRATION_TEST_SRCS}
171+
${FIREBASE_TEST_FRAMEWORK_SRCS}
172+
${FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS}
173+
)
174+
175+
target_include_directories(${integration_test_target_name} PRIVATE
176+
${ANDROID_NDK}/sources/android/native_app_glue)
177+
178+
set(ADDITIONAL_LIBS log android atomic native_app_glue)
179+
else()
180+
# Build a desktop application.
181+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
182+
183+
# Prevent overriding the parent project's compiler/linker
184+
# settings on Windows
185+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
186+
187+
# Add googletest directly to our build. This defines
188+
# the gtest and gtest_main targets.
189+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/googletest/src
190+
${CMAKE_CURRENT_LIST_DIR}/external/googletest/build
191+
EXCLUDE_FROM_ALL)
192+
193+
# The gtest/gtest_main targets carry header search path
194+
# dependencies automatically when using CMake 2.8.11 or
195+
# later. Otherwise we have to add them here ourselves.
196+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
197+
include_directories("${gtest_SOURCE_DIR}/include")
198+
include_directories("${gmock_SOURCE_DIR}/include")
199+
endif()
200+
201+
# Windows runtime mode, either MD or MT depending on whether you are using
202+
# /MD or /MT. For more information see:
203+
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
204+
set(MSVC_RUNTIME_MODE MD)
205+
206+
# Platform abstraction layer for the desktop integration test.
207+
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
208+
src/desktop/desktop_app_framework.cc
209+
)
210+
211+
set(integration_test_target_name "integration_test")
212+
add_executable(${integration_test_target_name}
213+
${FIREBASE_APP_FRAMEWORK_SRCS}
214+
${FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS}
215+
${FIREBASE_TEST_FRAMEWORK_SRCS}
216+
${FIREBASE_INTEGRATION_TEST_SRCS}
217+
)
218+
219+
if(APPLE)
220+
set(ADDITIONAL_LIBS
221+
gssapi_krb5
222+
pthread
223+
"-framework CoreFoundation"
224+
"-framework Foundation"
225+
"-framework GSS"
226+
"-framework Security"
227+
"-framework SystemConfiguration"
228+
)
229+
elseif(MSVC)
230+
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32)
231+
else()
232+
set(ADDITIONAL_LIBS pthread)
233+
endif()
234+
235+
# If a config file is present, copy it into the binary location so that it's
236+
# possible to create the default Firebase app.
237+
set(FOUND_JSON_FILE FALSE)
238+
foreach(config "google-services-desktop.json" "google-services.json")
239+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${config}")
240+
add_custom_command(
241+
TARGET ${integration_test_target_name} POST_BUILD
242+
COMMAND ${CMAKE_COMMAND} -E copy
243+
"${CMAKE_CURRENT_LIST_DIR}/${config}" $<TARGET_FILE_DIR:${integration_test_target_name}>)
244+
set(FOUND_JSON_FILE TRUE)
245+
break()
246+
endif()
247+
endforeach()
248+
if(NOT FOUND_JSON_FILE)
249+
message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.")
250+
endif()
251+
endif()
252+
253+
# Add the Firebase libraries to the target using the function from the SDK.
254+
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
255+
256+
# Note that firebase_app needs to be last in the list.
257+
set(firebase_libs firebase_firestore firebase_auth firebase_app)
258+
set(gtest_libs gtest gmock)
259+
target_link_libraries(${integration_test_target_name} ${firebase_libs} firestore_core absl_variant
260+
${gtest_libs} ${ADDITIONAL_LIBS})

0 commit comments

Comments
 (0)