diff --git a/functions/testapp/.gitignore b/functions/testapp/.gitignore
new file mode 100644
index 00000000..0679330e
--- /dev/null
+++ b/functions/testapp/.gitignore
@@ -0,0 +1,6 @@
+build/
+.*
+!/.gitignore
+google-services.json
+local.properties
+*.iml
\ No newline at end of file
diff --git a/functions/testapp/AndroidManifest.xml b/functions/testapp/AndroidManifest.xml
new file mode 100644
index 00000000..bb076723
--- /dev/null
+++ b/functions/testapp/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/functions/testapp/CMakeLists.txt b/functions/testapp/CMakeLists.txt
new file mode 100644
index 00000000..57c41072
--- /dev/null
+++ b/functions/testapp/CMakeLists.txt
@@ -0,0 +1,106 @@
+cmake_minimum_required(VERSION 2.8)
+
+# User settings for Firebase samples.
+# Path to Firebase SDK.
+# Try to read the path to the Firebase C++ SDK from an environment variable.
+if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
+ set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
+else()
+ set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
+endif()
+if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
+ set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
+endif()
+if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
+ message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
+endif()
+
+# Windows runtime mode, either MD or MT depending on whether you are using
+# /MD or /MT. For more information see:
+# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
+set(MSVC_RUNTIME_MODE MD)
+
+project(firebase_testapp)
+
+# Sample source files.
+set(FIREBASE_SAMPLE_COMMON_SRCS
+ src/main.h
+ src/common_main.cc
+)
+
+# Platform abstraction layer for the sample.
+set(FIREBASE_SAMPLE_DESKTOP_SRCS
+ src/desktop/desktop_main.cc
+)
+
+# Sample uses some features that require C++ 11, such as lambdas.
+set (CMAKE_CXX_STANDARD 11)
+
+# Determine the path to the library based on the platform and configuration.
+if(APPLE)
+ set(FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR}/libs/darwin/universal)
+ set(ADDITIONAL_LIBS
+ pthread
+ "-framework CoreFoundation"
+ "-framework Security"
+ )
+elseif(MSVC)
+ if(${CMAKE_CL_64})
+ set(MSVC_CPU x64)
+ else()
+ set(MSVC_CPU x86)
+ endif()
+ if(CMAKE_BUILD_TYPE EQUAL Release)
+ set(MSVC_CONFIG Release)
+ else()
+ set(MSVC_CONFIG Debug)
+ endif()
+ set(MSVC_VS_VERSION VS2015)
+ set(FIREBASE_SDK_LIBDIR
+ ${FIREBASE_CPP_SDK_DIR}/libs/windows/${MSVC_VS_VERSION}/${MSVC_RUNTIME_MODE}/${MSVC_CPU}/${MSVC_CONFIG})
+ set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv)
+else()
+ # The Firebase libraries are not built with glibcxx11, so disable the ABI.
+ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
+ set(LINUX_CPU x86_64)
+ set(FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR}/libs/linux/${LINUX_CPU})
+ set(ADDITIONAL_LIBS pthread)
+endif()
+
+# Link Firebase libraries.
+# NOTE: firebase_app needs to be after all other Firebase libraries.
+link_directories(${FIREBASE_SDK_LIBDIR})
+set(FIREBASE_LIBS firebase_functions firebase_auth firebase_app)
+
+# Add the Firebase include directory.
+set(FIREBASE_SDK_INCLUDEDIR ${FIREBASE_CPP_SDK_DIR}/include)
+include_directories(${FIREBASE_SDK_INCLUDEDIR})
+
+# The include directory for the testapp.
+include_directories(src)
+
+add_executable(desktop_testapp
+ ${FIREBASE_SAMPLE_DESKTOP_SRCS}
+ ${FIREBASE_SAMPLE_COMMON_SRCS}
+)
+target_link_libraries(desktop_testapp
+ ${FIREBASE_LIBS}
+ ${ADDITIONAL_LIBS}
+)
+
+# If a config file is present, copy it into the binary location so that it's
+# possible to create the default Firebase app.
+set(FOUND_JSON_FILE FALSE)
+foreach(config "google-services-desktop.json" "google-services.json")
+ if (EXISTS ${config})
+ add_custom_command(
+ TARGET desktop_testapp POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${config} $)
+ set(FOUND_JSON_FILE TRUE)
+ break()
+ endif()
+endforeach()
+if(NOT FOUND_JSON_FILE)
+ message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.")
+endif()
diff --git a/functions/testapp/LICENSE b/functions/testapp/LICENSE
new file mode 100644
index 00000000..d6456956
--- /dev/null
+++ b/functions/testapp/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/functions/testapp/LaunchScreen.storyboard b/functions/testapp/LaunchScreen.storyboard
new file mode 100644
index 00000000..673e0f7e
--- /dev/null
+++ b/functions/testapp/LaunchScreen.storyboard
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/functions/testapp/Podfile b/functions/testapp/Podfile
new file mode 100644
index 00000000..71037b25
--- /dev/null
+++ b/functions/testapp/Podfile
@@ -0,0 +1,8 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+# Firebase Cloud Functions test application.
+target 'testapp' do
+ pod 'Firebase/Core'
+ pod 'Firebase/Functions'
+ pod 'Firebase/Auth'
+end
diff --git a/functions/testapp/build.gradle b/functions/testapp/build.gradle
new file mode 100644
index 00000000..86b4086c
--- /dev/null
+++ b/functions/testapp/build.gradle
@@ -0,0 +1,112 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+buildscript {
+ repositories {
+ mavenLocal()
+ maven { url 'https://maven.google.com' }
+ jcenter()
+ google()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.1.3'
+ classpath 'com.google.gms:google-services:4.0.1'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenLocal()
+ maven { url 'https://maven.google.com' }
+ jcenter()
+ }
+}
+
+apply plugin: 'com.android.application'
+
+// Pre-experimental Gradle plug-in NDK boilerplate below.
+// Right now the Firebase plug-in does not work with the experimental
+// Gradle plug-in so we're using ndk-build for the moment.
+project.ext {
+ // Configure the Firebase C++ SDK location.
+ firebase_cpp_sdk_dir = System.getProperty('firebase_cpp_sdk.dir')
+ if (firebase_cpp_sdk_dir == null || firebase_cpp_sdk_dir.isEmpty()) {
+ firebase_cpp_sdk_dir = System.getenv('FIREBASE_CPP_SDK_DIR')
+ if (firebase_cpp_sdk_dir == null || firebase_cpp_sdk_dir.isEmpty()) {
+ if ((new File('firebase_cpp_sdk')).exists()) {
+ firebase_cpp_sdk_dir = 'firebase_cpp_sdk'
+ } else {
+ throw new StopActionException(
+ 'firebase_cpp_sdk.dir property or the FIREBASE_CPP_SDK_DIR ' +
+ 'environment variable must be set to reference the Firebase C++ ' +
+ 'SDK install directory. This is used to configure static library ' +
+ 'and C/C++ include paths for the SDK.')
+ }
+ }
+ }
+ if (!(new File(firebase_cpp_sdk_dir)).exists()) {
+ throw new StopActionException(
+ sprintf('Firebase C++ SDK directory %s does not exist',
+ firebase_cpp_sdk_dir))
+ }
+ // Check the NDK location using the same configuration options as the
+ // experimental Gradle plug-in.
+ ndk_dir = project.android.ndkDirectory
+ if (ndk_dir == null || !ndk_dir.exists()) {
+ ndk_dir = System.getenv('ANDROID_NDK_HOME')
+ if (ndk_dir == null || ndk_dir.isEmpty()) {
+ throw new StopActionException(
+ 'Android NDK directory should be specified using the ndk.dir ' +
+ 'property or ANDROID_NDK_HOME environment variable.')
+ }
+ }
+}
+
+android {
+ compileSdkVersion 26
+ buildToolsVersion '26.0.3'
+
+ sourceSets {
+ main {
+ jniLibs.srcDirs = ['libs']
+ manifest.srcFile 'AndroidManifest.xml'
+ java.srcDirs = ['src/android/java']
+ res.srcDirs = ['res']
+ }
+ }
+
+ defaultConfig {
+ applicationId 'com.google.firebase.cpp.functions.testapp'
+ minSdkVersion 14
+ targetSdkVersion 26
+ versionCode 1
+ versionName '1.0'
+
+ externalNativeBuild {
+ ndkBuild {
+ arguments "FIREBASE_CPP_SDK_DIR=${project.ext.firebase_cpp_sdk_dir}"
+ }
+ }
+ }
+ externalNativeBuild {
+ ndkBuild {
+ path file("jni/Android.mk")
+ }
+ }
+ buildTypes {
+ release {
+ minifyEnabled true
+ proguardFile getDefaultProguardFile('proguard-android.txt')
+ proguardFile file(project.ext.firebase_cpp_sdk_dir + "/libs/android/app.pro")
+ proguardFile file(project.ext.firebase_cpp_sdk_dir + "/libs/android/auth.pro")
+ proguardFile file(project.ext.firebase_cpp_sdk_dir + "/libs/android/functions.pro")
+ proguardFile file('proguard.pro')
+ }
+ }
+}
+
+dependencies {
+ implementation 'com.google.firebase:firebase-core:16.0.0'
+ implementation 'com.google.firebase:firebase-auth:16.0.1'
+ implementation 'com.google.firebase:firebase-functions:16.1.0'
+}
+
+apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
diff --git a/functions/testapp/gradle/wrapper/gradle-wrapper.jar b/functions/testapp/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..8c0fb64a
Binary files /dev/null and b/functions/testapp/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/functions/testapp/gradle/wrapper/gradle-wrapper.properties b/functions/testapp/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..d2f44f72
--- /dev/null
+++ b/functions/testapp/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Nov 27 14:03:45 PST 2017
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/functions/testapp/gradlew b/functions/testapp/gradlew
new file mode 100644
index 00000000..91a7e269
--- /dev/null
+++ b/functions/testapp/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/functions/testapp/gradlew.bat b/functions/testapp/gradlew.bat
new file mode 100644
index 00000000..8a0b282a
--- /dev/null
+++ b/functions/testapp/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/functions/testapp/jni/Android.mk b/functions/testapp/jni/Android.mk
new file mode 100644
index 00000000..d7c13ceb
--- /dev/null
+++ b/functions/testapp/jni/Android.mk
@@ -0,0 +1,64 @@
+# Copyright 2016 Google Inc. All rights reserved.
+#
+# 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.
+
+LOCAL_PATH:=$(call my-dir)/..
+
+ifeq ($(FIREBASE_CPP_SDK_DIR),)
+$(error FIREBASE_CPP_SDK_DIR must specify the Firebase package location.)
+endif
+
+# With Firebase libraries for the selected build configuration (ABI + STL)
+STL:=$(firstword $(subst _, ,$(APP_STL)))
+FIREBASE_LIBRARY_PATH:=\
+$(FIREBASE_CPP_SDK_DIR)/libs/android/$(TARGET_ARCH_ABI)/$(STL)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:=firebase_app
+LOCAL_SRC_FILES:=$(FIREBASE_LIBRARY_PATH)/libfirebase_app.a
+LOCAL_EXPORT_C_INCLUDES:=$(FIREBASE_CPP_SDK_DIR)/include
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:=firebase_auth
+LOCAL_SRC_FILES:=$(FIREBASE_LIBRARY_PATH)/libfirebase_auth.a
+LOCAL_EXPORT_C_INCLUDES:=$(FIREBASE_CPP_SDK_DIR)/include
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:=firebase_functions
+LOCAL_SRC_FILES:=$(FIREBASE_LIBRARY_PATH)/libfirebase_functions.a
+LOCAL_EXPORT_C_INCLUDES:=$(FIREBASE_CPP_SDK_DIR)/include
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE:=android_main
+LOCAL_SRC_FILES:=\
+ $(LOCAL_PATH)/src/common_main.cc \
+ $(LOCAL_PATH)/src/android/android_main.cc
+LOCAL_STATIC_LIBRARIES:=\
+ firebase_functions \
+ firebase_auth \
+ firebase_app
+LOCAL_WHOLE_STATIC_LIBRARIES:=\
+ android_native_app_glue
+LOCAL_C_INCLUDES:=\
+ $(NDK_ROOT)/sources/android/native_app_glue \
+ $(LOCAL_PATH)/src
+LOCAL_LDLIBS:=-llog -landroid -latomic
+LOCAL_ARM_MODE:=arm
+LOCAL_LDFLAGS:=-Wl,-z,defs -Wl,--no-undefined
+include $(BUILD_SHARED_LIBRARY)
+
+$(call import-add-path,$(NDK_ROOT)/sources/android)
+$(call import-module,android/native_app_glue)
diff --git a/functions/testapp/jni/Application.mk b/functions/testapp/jni/Application.mk
new file mode 100644
index 00000000..4904a6c8
--- /dev/null
+++ b/functions/testapp/jni/Application.mk
@@ -0,0 +1,20 @@
+# Copyright 2016 Google Inc. All rights reserved.
+#
+# 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.
+
+APP_PLATFORM:=android-14
+NDK_TOOLCHAIN_VERSION=clang
+APP_ABI:=armeabi-v7a arm64-v8a x86 x86_64
+APP_STL:=c++_static
+APP_MODULES:=android_main
+APP_CPPFLAGS+=-std=c++11
diff --git a/functions/testapp/proguard.pro b/functions/testapp/proguard.pro
new file mode 100644
index 00000000..54cd248b
--- /dev/null
+++ b/functions/testapp/proguard.pro
@@ -0,0 +1,2 @@
+-ignorewarnings
+-keep,includedescriptorclasses public class com.google.firebase.example.LoggingUtils { *; }
diff --git a/functions/testapp/readme.md b/functions/testapp/readme.md
new file mode 100644
index 00000000..44a68b33
--- /dev/null
+++ b/functions/testapp/readme.md
@@ -0,0 +1,214 @@
+Firebase Cloud Functions Quickstart
+========================
+
+The Firebase Cloud Functions Test Application (testapp) demonstrates Firebase
+Cloud Functions operations with the Firebase Cloud Functions C++ SDK. The
+application has no user interface and simply logs actions it's performing to the
+console.
+
+There are **two parts** to this project, the app and the server. Without the server, the app won't work correctly. However, you need to follow all of these instructions to setup your Firebase Project before you can setup the server.
+
+Follow the directions in `testserver\readme.md` to upload the echo function to the server.
+
+The testapp performs the following:
+ - Creates a firebase::App in a platform-specific way. The App holds
+ platform-specific context that's used by other Firebase APIs, and is a
+ central point for communication between the Firebase Cloud Functions C++
+ and Firebase Auth C++ libraries.
+ - Creates a Functions Object
+ - Grabs a HTTPS function reference to 'echoBody'
+ - Sends various values to server, and checks that the echo response
+ is the same as what was sent.
+ - Shuts down the Firebase functions and Firebase App systems.
+
+The testserver performs the following:
+ - Echos the request body back as a JSON response.
+
+Introduction
+------------
+
+- [Read more about Firebase Cloud Functions](https://firebase.google.com/docs/functions/callable)
+
+Building and Running the testapp
+--------------------------------
+
+### iOS
+ - Link your iOS app to the Firebase libraries.
+ - Get CocoaPods version 1 or later by running,
+ ```
+ sudo gem install cocoapods --pre
+ ```
+ - From the testapp directory, install the CocoaPods listed in the Podfile
+ by running,
+ ```
+ pod install
+ ```
+ - Open the generated Xcode workspace (which now has the CocoaPods),
+ ```
+ open testapp.xcworkspace
+ ```
+ - For further details please refer to the
+ [general instructions for setting up an iOS app with Firebase](https://firebase.google.com/docs/ios/setup).
+ - Register your iOS app with Firebase.
+ - Create a new app on the [Firebase console](https://firebase.google.com/console/), and attach
+ your iOS app to it.
+ - You can use "com.google.firebase.cpp.functions.testapp" as the iOS Bundle
+ ID while you're testing. You can omit App Store ID while testing.
+ - Add the GoogleService-Info.plist that you downloaded from Firebase
+ console to the testapp root directory. This file identifies your iOS app
+ to the Firebase backend.
+ - In the Firebase console for your app, select "Auth", then enable
+ "Anonymous". This will allow the testapp to use anonymous sign-in to
+ authenticate with Firebase functions, which requires a signed-in user by
+ default (an anonymous user will suffice).
+ - Download the Firebase C++ SDK linked from
+ [https://firebase.google.com/docs/cpp/setup]() and unzip it to a
+ directory of your choice.
+ - Add the following frameworks from the Firebase C++ SDK to the project:
+ - frameworks/ios/universal/firebase.framework
+ - frameworks/ios/universal/firebase_auth.framework
+ - frameworks/ios/universal/firebase_functions.framework
+ - You will need to either,
+ 1. Check "Copy items if needed" when adding the frameworks, or
+ 2. Add the framework path in "Framework Search Paths"
+ - e.g. If you downloaded the Firebase C++ SDK to
+ `/Users/me/firebase_cpp_sdk`,
+ then you would add the path
+ `/Users/me/firebase_cpp_sdk/frameworks/ios/universal`.
+ - To add the path, in XCode, select your project in the project
+ navigator, then select your target in the main window.
+ Select the "Build Settings" tab, and click "All" to see all
+ the build settings. Scroll down to "Search Paths", and add
+ your path to "Framework Search Paths".
+ - In XCode, build & run the sample on an iOS device or simulator.
+ - The testapp has no interative interface. The output of the app can be viewed
+ via the console or on the device's display. In Xcode, select
+ "View --> Debug Area --> Activate Console" from the menu to view the console.
+
+### Android
+ - Register your Android app with Firebase.
+ - Create a new app on
+ the [Firebase console](https://firebase.google.com/console/), and attach
+ your Android app to it.
+ - You can use "com.google.firebase.cpp.functions.testapp" as the Package
+ Name while you're testing.
+ - To
+ [generate a SHA1](https://developers.google.com/android/guides/client-auth)
+ run this command on Mac and Linux,
+ ```
+ keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
+ ```
+ or this command on Windows,
+ ```
+ keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
+ ```
+ - If keytool reports that you do not have a debug.keystore, you can
+ [create one with](http://developer.android.com/tools/publishing/app-signing.html#signing-manually),
+ ```
+ keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"
+ ```
+ - Add the `google-services.json` file that you downloaded from Firebase
+ console to the root directory of testapp. This file identifies your
+ Android app to the Firebase backend.
+ - For further details please refer to the
+ [general instructions for setting up an Android app with Firebase](https://firebase.google.com/docs/android/setup).
+ - Download the Firebase C++ SDK linked from
+ [https://firebase.google.com/docs/cpp/setup]() and unzip it to a
+ directory of your choice.
+ - Configure the location of the Firebase C++ SDK by setting the
+ firebase\_cpp\_sdk.dir Gradle property to the SDK install directory.
+ For example, in the project directory:
+ ```
+ echo "systemProp.firebase\_cpp\_sdk.dir=/User/$USER/firebase\_cpp\_sdk" >> gradle.properties
+ ```
+ - Ensure the Android SDK and NDK locations are set in Android Studio.
+ - From the Android Studio launch menu, go to `File/Project Structure...` or
+ `Configure/Project Defaults/Project Structure...`
+ (Shortcut: Control + Alt + Shift + S on windows, Command + ";" on a mac)
+ and download the SDK and NDK if the locations are not yet set.
+ - Open *build.gradle* in Android Studio.
+ - From the Android Studio launch menu, "Open an existing Android Studio
+ project", and select `build.gradle`.
+ - Install the SDK Platforms that Android Studio reports missing.
+ - Build the testapp and run it on an Android device or emulator.
+ - The testapp has no interactive interface. The output of the app can be
+ viewed on the device's display, or in the logcat output of Android studio or
+ by running "adb logcat *:W android_main firebase" from the command line.
+
+### Desktop
+ - Register your app with Firebase.
+ - Create a new app on the [Firebase console](https://firebase.google.com/console/),
+ following the above instructions for Android or iOS.
+ - If you have an Android project, add the `google-services.json` file that
+ you downloaded from the Firebase console to the root directory of the
+ testapp.
+ - If you have an iOS project, and don't wish to use an Android project,
+ you can use the Python script `generate_xml_from_google_services_json.py --plist`,
+ located in the Firebase C++ SDK, to convert your `GoogleService-Info.plist`
+ file into a `google-services-desktop.json` file, which can then be
+ placed in the root directory of the testapp.
+ - Download the Firebase C++ SDK linked from
+ [https://firebase.google.com/docs/cpp/setup]() and unzip it to a
+ directory of your choice.
+ - Configure the testapp with the location of the Firebase C++ SDK.
+ This can be done a couple different ways (in highest to lowest priority):
+ - When invoking cmake, pass in the location with
+ -DFIREBASE_CPP_SDK_DIR=/path/to/firebase_cpp_sdk.
+ - Set an environment variable for FIREBASE_CPP_SDK_DIR to the path to use.
+ - Edit the CMakeLists.txt file, changing the FIREBASE_CPP_SDK_DIR path
+ to the appropriate location.
+ - From the testapp directory, generate the build files by running,
+ ```
+ cmake .
+ ```
+ If you want to use XCode, you can use -G"Xcode" to generate the project.
+ Similarly, to use Visual Studio, -G"Visual Studio 15 2017". For more
+ information, see
+ [CMake generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).
+ - Build the testapp, by either opening the generated project file based on
+ the platform, or running,
+ ```
+ cmake --build .
+ ```
+ - Execute the testapp by running,
+ ```
+ ./desktop_testapp
+ ```
+ Note that the executable might be under another directory, such as Debug.
+ - The testapp has no user interface, but the output can be viewed via the
+ console.
+
+Known issues
+------------
+
+ - Due to the way Firebase Cloud Functions interacts with JSON, it is
+ possible that if you set a location to an integral value using a
+ firebase::Variant of type Int64, you may get back a firebase::Variant of
+ type Double when later retrieving the data from the functions. Be sure to
+ check the types of Variants or use methods such as Variant::AsInt64() to
+ coerce their types before accessing the data within them.
+
+Support
+-------
+
+[https://firebase.google.com/support/]()
+
+License
+-------
+
+Copyright 2016 Google, Inc.
+
+Licensed to the Apache Software Foundation (ASF) under one or more contributor
+license agreements. See the NOTICE file distributed with this work for
+additional information regarding copyright ownership. The ASF licenses this
+file to you 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.
diff --git a/functions/testapp/res/layout/main.xml b/functions/testapp/res/layout/main.xml
new file mode 100644
index 00000000..d3ffb630
--- /dev/null
+++ b/functions/testapp/res/layout/main.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/functions/testapp/res/values/strings.xml b/functions/testapp/res/values/strings.xml
new file mode 100644
index 00000000..4806f98b
--- /dev/null
+++ b/functions/testapp/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+
+ Firebase functions Test
+
diff --git a/functions/testapp/src/android/android_main.cc b/functions/testapp/src/android/android_main.cc
new file mode 100644
index 00000000..73cb30e7
--- /dev/null
+++ b/functions/testapp/src/android/android_main.cc
@@ -0,0 +1,255 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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
+
+#include
+#include
+#include
+#include
+
+#include "main.h" // NOLINT
+
+// This implementation is derived from http://github.com/google/fplutil
+
+extern "C" int common_main(int argc, const char* argv[]);
+
+static struct android_app* g_app_state = nullptr;
+static bool g_destroy_requested = false;
+static bool g_started = false;
+static bool g_restarted = false;
+static pthread_mutex_t g_started_mutex;
+
+// Handle state changes from via native app glue.
+static void OnAppCmd(struct android_app* app, int32_t cmd) {
+ g_destroy_requested |= cmd == APP_CMD_DESTROY;
+}
+
+// Process events pending on the main thread.
+// Returns true when the app receives an event requesting exit.
+bool ProcessEvents(int msec) {
+ struct android_poll_source* source = nullptr;
+ int events;
+ int looperId = ALooper_pollAll(msec, nullptr, &events,
+ reinterpret_cast(&source));
+ if (looperId >= 0 && source) {
+ source->process(g_app_state, source);
+ }
+ return g_destroy_requested | g_restarted;
+}
+
+// Get the activity.
+jobject GetActivity() { return g_app_state->activity->clazz; }
+
+// Get the window context. For Android, it's a jobject pointing to the Activity.
+jobject GetWindowContext() { return g_app_state->activity->clazz; }
+
+// Find a class, attempting to load the class if it's not found.
+jclass FindClass(JNIEnv* env, jobject activity_object, const char* class_name) {
+ jclass class_object = env->FindClass(class_name);
+ if (env->ExceptionCheck()) {
+ env->ExceptionClear();
+ // If the class isn't found it's possible NativeActivity is being used by
+ // the application which means the class path is set to only load system
+ // classes. The following falls back to loading the class using the
+ // Activity before retrieving a reference to it.
+ jclass activity_class = env->FindClass("android/app/Activity");
+ jmethodID activity_get_class_loader = env->GetMethodID(
+ activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
+
+ jobject class_loader_object =
+ env->CallObjectMethod(activity_object, activity_get_class_loader);
+
+ jclass class_loader_class = env->FindClass("java/lang/ClassLoader");
+ jmethodID class_loader_load_class =
+ env->GetMethodID(class_loader_class, "loadClass",
+ "(Ljava/lang/String;)Ljava/lang/Class;");
+ jstring class_name_object = env->NewStringUTF(class_name);
+
+ class_object = static_cast(env->CallObjectMethod(
+ class_loader_object, class_loader_load_class, class_name_object));
+
+ if (env->ExceptionCheck()) {
+ env->ExceptionClear();
+ class_object = nullptr;
+ }
+ env->DeleteLocalRef(class_name_object);
+ env->DeleteLocalRef(class_loader_object);
+ }
+ return class_object;
+}
+
+// Vars that we need available for appending text to the log window:
+class LoggingUtilsData {
+ public:
+ LoggingUtilsData()
+ : logging_utils_class_(nullptr),
+ logging_utils_add_log_text_(0),
+ logging_utils_init_log_window_(0) {}
+
+ ~LoggingUtilsData() {
+ JNIEnv* env = GetJniEnv();
+ assert(env);
+ if (logging_utils_class_) {
+ env->DeleteGlobalRef(logging_utils_class_);
+ }
+ }
+
+ void Init() {
+ JNIEnv* env = GetJniEnv();
+ assert(env);
+
+ jclass logging_utils_class = FindClass(
+ env, GetActivity(), "com/google/firebase/example/LoggingUtils");
+ assert(logging_utils_class != 0);
+
+ // Need to store as global references so it don't get moved during garbage
+ // collection.
+ logging_utils_class_ =
+ static_cast(env->NewGlobalRef(logging_utils_class));
+ env->DeleteLocalRef(logging_utils_class);
+
+ logging_utils_init_log_window_ = env->GetStaticMethodID(
+ logging_utils_class_, "initLogWindow", "(Landroid/app/Activity;)V");
+ logging_utils_add_log_text_ = env->GetStaticMethodID(
+ logging_utils_class_, "addLogText", "(Ljava/lang/String;)V");
+
+ env->CallStaticVoidMethod(logging_utils_class_,
+ logging_utils_init_log_window_, GetActivity());
+ }
+
+ void AppendText(const char* text) {
+ if (logging_utils_class_ == 0) return; // haven't been initted yet
+ JNIEnv* env = GetJniEnv();
+ assert(env);
+ jstring text_string = env->NewStringUTF(text);
+ env->CallStaticVoidMethod(logging_utils_class_, logging_utils_add_log_text_,
+ text_string);
+ env->DeleteLocalRef(text_string);
+ }
+
+ private:
+ jclass logging_utils_class_;
+ jmethodID logging_utils_add_log_text_;
+ jmethodID logging_utils_init_log_window_;
+};
+
+LoggingUtilsData* g_logging_utils_data;
+
+// Checks if a JNI exception has happened, and if so, logs it to the console.
+void CheckJNIException() {
+ JNIEnv* env = GetJniEnv();
+ if (env->ExceptionCheck()) {
+ // Get the exception text.
+ jthrowable exception = env->ExceptionOccurred();
+ env->ExceptionClear();
+
+ // Convert the exception to a string.
+ jclass object_class = env->FindClass("java/lang/Object");
+ jmethodID toString =
+ env->GetMethodID(object_class, "toString", "()Ljava/lang/String;");
+ jstring s = (jstring)env->CallObjectMethod(exception, toString);
+ const char* exception_text = env->GetStringUTFChars(s, nullptr);
+
+ // Log the exception text.
+ __android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME,
+ "-------------------JNI exception:");
+ __android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME, "%s",
+ exception_text);
+ __android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME,
+ "-------------------");
+
+ // Also, assert fail.
+ assert(false);
+
+ // In the event we didn't assert fail, clean up.
+ env->ReleaseStringUTFChars(s, exception_text);
+ env->DeleteLocalRef(s);
+ env->DeleteLocalRef(exception);
+ }
+}
+
+// Log a message that can be viewed in "adb logcat".
+void LogMessage(const char* format, ...) {
+ static const int kLineBufferSize = 100;
+ char buffer[kLineBufferSize + 2];
+
+ va_list list;
+ va_start(list, format);
+ int string_len = vsnprintf(buffer, kLineBufferSize, format, list);
+ string_len = string_len < kLineBufferSize ? string_len : kLineBufferSize;
+ // append a linebreak to the buffer:
+ buffer[string_len] = '\n';
+ buffer[string_len + 1] = '\0';
+
+ __android_log_vprint(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME, format, list);
+ g_logging_utils_data->AppendText(buffer);
+ CheckJNIException();
+ va_end(list);
+}
+
+// Get the JNI environment.
+JNIEnv* GetJniEnv() {
+ JavaVM* vm = g_app_state->activity->vm;
+ JNIEnv* env;
+ jint result = vm->AttachCurrentThread(&env, nullptr);
+ return result == JNI_OK ? env : nullptr;
+}
+
+// Execute common_main(), flush pending events and finish the activity.
+extern "C" void android_main(struct android_app* state) {
+ // native_app_glue spawns a new thread, calling android_main() when the
+ // activity onStart() or onRestart() methods are called. This code handles
+ // the case where we're re-entering this method on a different thread by
+ // signalling the existing thread to exit, waiting for it to complete before
+ // reinitializing the application.
+ if (g_started) {
+ g_restarted = true;
+ // Wait for the existing thread to exit.
+ pthread_mutex_lock(&g_started_mutex);
+ pthread_mutex_unlock(&g_started_mutex);
+ } else {
+ g_started_mutex = PTHREAD_MUTEX_INITIALIZER;
+ }
+ pthread_mutex_lock(&g_started_mutex);
+ g_started = true;
+
+ // Save native app glue state and setup a callback to track the state.
+ g_destroy_requested = false;
+ g_app_state = state;
+ g_app_state->onAppCmd = OnAppCmd;
+
+ // Create the logging display.
+ g_logging_utils_data = new LoggingUtilsData();
+ g_logging_utils_data->Init();
+
+ // Execute cross platform entry point.
+ static const char* argv[] = {FIREBASE_TESTAPP_NAME};
+ int return_value = common_main(1, argv);
+ (void)return_value; // Ignore the return value.
+ ProcessEvents(10);
+
+ // Clean up logging display.
+ delete g_logging_utils_data;
+ g_logging_utils_data = nullptr;
+
+ // Finish the activity.
+ if (!g_restarted) ANativeActivity_finish(state->activity);
+
+ g_app_state->activity->vm->DetachCurrentThread();
+ g_started = false;
+ g_restarted = false;
+ pthread_mutex_unlock(&g_started_mutex);
+}
diff --git a/functions/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java b/functions/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java
new file mode 100644
index 00000000..11d67c5b
--- /dev/null
+++ b/functions/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java
@@ -0,0 +1,55 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+package com.google.firebase.example;
+
+import android.app.Activity;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.Window;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+/**
+ * A utility class, encapsulating the data and methods required to log arbitrary
+ * text to the screen, via a non-editable TextView.
+ */
+public class LoggingUtils {
+ public static TextView sTextView = null;
+
+ public static void initLogWindow(Activity activity) {
+ LinearLayout linearLayout = new LinearLayout(activity);
+ ScrollView scrollView = new ScrollView(activity);
+ TextView textView = new TextView(activity);
+ textView.setTag("Logger");
+ linearLayout.addView(scrollView);
+ scrollView.addView(textView);
+ Window window = activity.getWindow();
+ window.takeSurface(null);
+ window.setContentView(linearLayout);
+ sTextView = textView;
+ }
+
+ public static void addLogText(final String text) {
+ new Handler(Looper.getMainLooper()).post(new Runnable() {
+ @Override
+ public void run() {
+ if (sTextView != null) {
+ sTextView.append(text);
+ }
+ }
+ });
+ }
+}
diff --git a/functions/testapp/src/common_main.cc b/functions/testapp/src/common_main.cc
new file mode 100644
index 00000000..f91851ad
--- /dev/null
+++ b/functions/testapp/src/common_main.cc
@@ -0,0 +1,205 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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
+#include "firebase/app.h"
+#include "firebase/auth.h"
+#include "firebase/functions.h"
+#include "firebase/future.h"
+#include "firebase/util.h"
+
+#include
+
+#include