Skip to content

Commit 8f2716f

Browse files
Googlera-maurice
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 291060315
1 parent 3f6babd commit 8f2716f

File tree

176 files changed

+20018
-0
lines changed

Some content is hidden

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

176 files changed

+20018
-0
lines changed

firestore/AndroidManifest.xml.tmpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="${package}"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
8+
<uses-permission android:name="android.permission.WAKE_LOCK" />
9+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
10+
<application android:label="${package} Test"
11+
android:name="android.support.multidex.MultiDexApplication">
12+
<activity android:name="android.app.NativeActivity"
13+
android:screenOrientation="portrait"
14+
android:configChanges="orientation|screenSize">
15+
<meta-data android:name="android.app.lib_name"
16+
android:value="${lib_name}" />
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
</manifest>

firestore/AndroidTest.java.tmpl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package {package_name};
2+
3+
import android.app.Instrumentation;
4+
import android.app.NativeActivity;
5+
import android.content.ContentResolver;
6+
import android.system.Os;
7+
import android.util.Log;
8+
import androidx.test.InstrumentationRegistry;
9+
import androidx.test.filters.LargeTest;
10+
import androidx.test.rule.ActivityTestRule;
11+
import androidx.test.runner.AndroidJUnit4;
12+
import com.google.android.apps.common.testing.util.AndroidTestUtil;
13+
import com.google.common.jni.JniLoader;
14+
import java.io.File;
15+
import java.util.Map;
16+
import org.junit.After;
17+
import org.junit.Before;
18+
import org.junit.Assert;
19+
import org.junit.Rule;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
23+
@RunWith(AndroidJUnit4.class)
24+
@LargeTest
25+
public class {java_class_name} {{
26+
static {{
27+
// Blaze packs shared libraries into jar files. JniLoader unpacks them and
28+
// then delegates to System.loadLibrary.
29+
JniLoader.loadLibrary("{so_lib_name}");
30+
}}
31+
32+
private native boolean runAllTest(NativeActivity activity, String filter);
33+
34+
@Rule
35+
public final ActivityTestRule<NativeActivity> rule =
36+
new ActivityTestRule<NativeActivity>(NativeActivity.class);
37+
38+
@Before
39+
public void setupFirestoreEmulatorAddress() {{
40+
ContentResolver contentResolver =
41+
InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver();
42+
Map<String, String> args = AndroidTestUtil.getTestArgs(contentResolver);
43+
if (args.containsKey("firestore_emulator_port")) {{
44+
String address = "10.0.2.2:" + args.get("firestore_emulator_port");
45+
try {{
46+
Os.setenv("FIRESTORE_EMULATOR_HOST", address, true);
47+
Log.i("{java_class_name}", "FIRESTORE_EMULATOR_HOST: " + address);
48+
}}
49+
catch (Exception e) {{
50+
Log.w("{java_class_name}", "Could not set emulator address environment variable: " + e);
51+
// Swallow exception to allow tests to run against actual backend.
52+
}}
53+
}}
54+
}}
55+
56+
// Manually stop the test activity. If we let the test harness do this for us,
57+
// somehow that will catch an expected crash and fail the test. TODO(zxu):
58+
// Investigate the root cause and undo this change, see b/111298684.
59+
@After
60+
public void stopNativeActivity() {{
61+
Instrumentation instrumentation = null;
62+
try {{
63+
instrumentation = InstrumentationRegistry.getInstrumentation();
64+
}} catch (IllegalStateException e) {{
65+
Log.e("{java_class_name}",
66+
"cannot find instrumentation for the test activity");
67+
return;
68+
}}
69+
Log.d("{java_class_name}", "try to stop test activity");
70+
instrumentation.callActivityOnStop(rule.getActivity());
71+
}}
72+
73+
private void run(String test) {{
74+
// Pass the test name as a filter to run the specific test.
75+
boolean result = runAllTest(rule.getActivity(), /*filter=*/test);
76+
Assert.assertTrue(result);
77+
}}
78+
79+
{tests}
80+
}}

firestore/Info.plist

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
GoogleService<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.google.firebase.cpp.firestore.testapp</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleURLTypes</key>
20+
<array>
21+
<dict>
22+
<key>CFBundleTypeRole</key>
23+
<string>Editor</string>
24+
<key>CFBundleURLName</key>
25+
<string>com.google.firebase.cpp.firestore.testapp.dev</string>
26+
<key>CFBundleURLSchemes</key>
27+
<array>
28+
<string>com.google.firebase.cpp.firestore.testapp.dev</string>
29+
</array>
30+
</dict>
31+
<dict>
32+
<key>CFBundleTypeRole</key>
33+
<string>Editor</string>
34+
<key>CFBundleURLName</key>
35+
<string>google</string>
36+
<key>CFBundleURLSchemes</key>
37+
<array>
38+
<string>com.googleusercontent.apps.53101460582-aosfj1hlbc89719t6qfian100u6hehh8</string>
39+
</array>
40+
</dict>
41+
</array>
42+
<key>CFBundleVersion</key>
43+
<string>1</string>
44+
<key>LSRequiresIPhoneOS</key>
45+
<true/>
46+
<key>UILaunchStoryboardName</key>
47+
<string>LaunchScreen</string>
48+
</dict>
49+
</plist>

firestore/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Overview
2+
3+
(TODO: Describe C++ SDK and its scope)
4+
5+
## Integration with FPL
6+
7+
(TODO: Describe how this is integrated with FPL, architecture overview and
8+
useful commands)
9+
10+
## Copybara process
11+
12+
(TODO: Describe how github C++ code is copied here, what is not copied, and how
13+
to run the copybara)
14+
15+
## Running integration tests
16+
17+
Given the C++ SDK runs on a lot of platforms, there are many different setups we
18+
can use to run its integration tests. Below are instructions on how to run them
19+
with all possible setups.
20+
21+
### Against Firestore emulator
22+
23+
This is the preferred way to run integration tests. The way it is configured is
24+
we have a controlling `go_test` (`integration_test_emulator.go`), which will
25+
pull Firestore emulator as a `data` dependency and set it up before it finds and
26+
runs the actual integration tests in separate processes.
27+
28+
Note this means on mobile platforms, the integration tests are run within
29+
simulation, as there is no way to setup Firestore emulator if they are run on
30+
real devices.
31+
32+
#### iOS (running within iOS simulator on forge-on-mac, hence `darwin_x86_64`):
33+
34+
(TODO: When tests fail, the messages are not properly formatted, especially
35+
newline is turned into '\n'.)
36+
37+
```bash
38+
blaze test --config=darwin_x86_64 //firebase/firestore/client/cpp:ios_integration_tests
39+
```
40+
41+
#### Android (running within Android emulator, requires kvm to run on google3):
42+
43+
(TODO: When tests fail, the messages only tell you the test failed, because of
44+
the JUnit test wrapping. Ideally we should fix that.)
45+
46+
```bash
47+
blaze --blazerc=//google/src/head/depot/google3/java/com/google/android/gmscore/blaze/blazerc \
48+
test --define=firebase_build=head --config=gmscore_x86 \
49+
//firebase/firestore/client/cpp:android_integration_tests \
50+
--experimental_one_version_enforcement=warning
51+
```
52+
53+
Support for other platforms is not available yet.
54+
55+
### Against Firestore prod backend
56+
57+
Running against the actual Firestore backend takes much longer and sometimes our
58+
tests might get to run in an environment where external network connection is
59+
impossible (such as Forge).
60+
61+
It is useful still, for example, to run it before a release or to debug issues
62+
that only happen with real backend.
63+
64+
#### iOS (Runs on real devices via MobileHarness):
65+
66+
```bash
67+
blaze test --config=ios_fat --notest_loasd //firebase/firestore/client/cpp:ios_integration_tests_mh
68+
```
69+
70+
#### Android:
71+
72+
(TODO: Right now, running below would not succeed, there needs to be a hack to
73+
fix the gmscore version built on rabbit first, eliminate the hack)
74+
75+
```bash
76+
blaze --blazerc=//google/src/head/depot/google3/java/com/google/android/gmscore/blaze/blazerc \
77+
test --define=firebase_build=head --config=gmscore_x86 \
78+
//firebase/firestore/client/cpp:android_integration_tests_prod \
79+
--experimental_one_version_enforcement=warning
80+
```
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
source googletest.sh || exit 1
4+
5+
# Copied from `googletest.sh`. The only difference is the original uses an
6+
# absolute path to python, which does not exist in some environments we are
7+
# running. There is always a python in PATH in our environments though.
8+
reserve_random_unused_tcp_port () {
9+
python -c '
10+
import os, random, socket, sys, time
11+
timeout = float(sys.argv[1])
12+
def CheckPort(port):
13+
ts = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP)
14+
us = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
15+
try:
16+
ts.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
17+
ts.bind(("", port))
18+
ts.listen(1)
19+
us.bind(("", port))
20+
# Return the sockets to prevent garbage collection.
21+
return (ts, us)
22+
except socket.error:
23+
ts.close()
24+
us.close()
25+
return None
26+
for i in range(128):
27+
port = random.randint(32760, 59759)
28+
bound_sockets = CheckPort(port)
29+
if bound_sockets:
30+
print port
31+
if timeout > 0:
32+
sys.stdin.close()
33+
sys.stdout.close()
34+
sys.stderr.close()
35+
if os.fork() == 0:
36+
time.sleep(timeout)
37+
sys.exit(0)
38+
print "NO_FREE_PORT_FOUND"
39+
sys.exit(1)
40+
' "${1:-0}"
41+
}
42+
43+
# Find executable and shared libs
44+
BINDIR="$TEST_SRCDIR/google3/firebase/firestore/client/cpp"
45+
FIRESTORE_EMULATOR_JAR=$BINDIR/CloudFirestore_emulator.jar
46+
# Pick a random available port with timeout 0
47+
EMULATOR_PORT=$( reserve_random_unused_tcp_port 0 )
48+
49+
# Add java to PATH
50+
JAVABIN=$( ls -d "$TEST_SRCDIR"/google3/third_party/java/jdk/jdk*-k8/bin | \
51+
tail -1 )
52+
PATH=$JAVABIN:$PATH
53+
54+
# Start Firestore Emulator
55+
echo "Running java -jar $FIRESTORE_EMULATOR_JAR --port=$EMULATOR_PORT"
56+
java -jar "$FIRESTORE_EMULATOR_JAR" --port="$EMULATOR_PORT" &
57+
EMULATOR_PID=$!
58+
sleep 3
59+
60+
# Running Android tests.
61+
if [[ -f "$(ls "$BINDIR"/*_test_android_prod)" ]]; then
62+
for test in $(ls "$BINDIR"/*_test_android_prod); do
63+
"$test" --test_args=firestore_emulator_port="$EMULATOR_PORT" || \
64+
die "Test $test failed" $?
65+
done
66+
fi
67+
68+
# Running iOS tests.
69+
if [[ -f "$(ls "$BINDIR"/*_test_ios)" ]]; then
70+
# Write Firestore Emulator address to a temp file
71+
echo "localhost:$EMULATOR_PORT" > /tmp/emulator_address
72+
for TEST in $(ls "$BINDIR"/*_test_ios); do
73+
"$TEST" || die "Test $TEST failed" $?
74+
done
75+
rm /tmp/emulator_address
76+
fi
77+
78+
kill $EMULATOR_PID
79+
echo "Pass"

firestore/run_local_tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Runs the presubmit tests that must be run locally, because they don't work in
3+
# TAP or Guitar at the moment (see b/135205911). Execute this script before
4+
# submitting.
5+
6+
# LINT.IfChange
7+
blaze test --config=android_arm //firebase/firestore/client/cpp:kokoro_build_test && \
8+
blaze test --config=darwin_x86_64 //firebase/firestore/client/cpp:kokoro_build_test && \
9+
blaze test //firebase/firestore/client/cpp:kokoro_build_test && \
10+
blaze test --config=msvc //firebase/firestore/client/cpp:kokoro_build_test
11+
# LINT.ThenChange(//depot_firebase_cpp/firestore/client/cpp/METADATA)

0 commit comments

Comments
 (0)