Skip to content

Commit da52289

Browse files
DellaBittaa-maurice
authored andcommitted
Gradle build support for testing/ directory, and resource archiving of app test classes for upcoming cc_test_on_jvm cmake build target.
PiperOrigin-RevId: 295207768
1 parent fb1642b commit da52289

File tree

3 files changed

+281
-0
lines changed

3 files changed

+281
-0
lines changed

app/test_resources/build.gradle

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
buildscript {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
dependencies {
21+
classpath 'com.android.tools.build:gradle:3.2.1'
22+
classpath 'com.google.gms:google-services:4.2.0'
23+
}
24+
}
25+
allprojects {
26+
repositories {
27+
google()
28+
jcenter()
29+
}
30+
}
31+
32+
apply plugin: 'com.android.library'
33+
34+
android {
35+
compileSdkVersion 28
36+
37+
sourceSets {
38+
main {
39+
manifest.srcFile '../../android_build_files/AndroidManifest.xml'
40+
java {
41+
srcDirs = ['../src_java/fake/com/google/firebase',
42+
'../src_java/fake/com/google/firebase/platforminfo']
43+
exclude "app"
44+
}
45+
}
46+
}
47+
}
48+
49+
afterEvaluate {
50+
generateReleaseBuildConfig.enabled = false
51+
}
52+
53+
apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
54+
extractAndDexAarFile('test_resources')

testing/build.gradle

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
buildscript {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
dependencies {
21+
classpath 'com.android.tools.build:gradle:3.2.1'
22+
classpath 'com.google.gms:google-services:4.2.0'
23+
// This uses Flatbuffers at 1.9 because the 1.10 version added a feature
24+
// that requires using a newer version of the JDK and at least Android N.
25+
// This has already been fixed at head, but a tagged release is not yet
26+
// available with that fix.
27+
classpath 'com.google.flatbuffers:flatbuffers-java:1.9.0'
28+
}
29+
}
30+
31+
allprojects {
32+
repositories {
33+
google()
34+
jcenter()
35+
}
36+
}
37+
38+
apply plugin: 'com.android.library'
39+
40+
android {
41+
compileSdkVersion 28
42+
buildToolsVersion '28.0.3'
43+
44+
sourceSets {
45+
main {
46+
manifest.srcFile '../android_build_files/AndroidManifest.xml'
47+
java {
48+
srcDirs = ['../TickerExample.java',
49+
"$buildDir/flatbuffer_generated"]
50+
}
51+
}
52+
}
53+
54+
defaultConfig {
55+
// This is the platform API where NativeActivity was introduced.
56+
minSdkVersion 9
57+
targetSdkVersion 28
58+
versionCode 1
59+
versionName "1.0"
60+
61+
buildTypes {
62+
release {
63+
minifyEnabled false
64+
}
65+
}
66+
}
67+
68+
lintOptions {
69+
abortOnError false
70+
}
71+
}
72+
73+
dependencies {
74+
implementation 'com.google.flatbuffers:flatbuffers-java:1.9.0'
75+
}
76+
77+
afterEvaluate { project ->
78+
// Define a Task that will add a Flatbuffers dependency, downloading
79+
// the source from GitHub if needed.
80+
task generateFlatbufferFiles {
81+
// Locate or download flatbuffers.
82+
def flatbuffersDir = "$buildDir/flatbuffers"
83+
def flatbuffersFolder = new File(flatbuffersDir)
84+
if (!flatbuffersFolder.exists()) {
85+
exec {
86+
executable 'git'
87+
args 'clone',
88+
'--branch',
89+
'v1.10.0',
90+
'--depth',
91+
'1',
92+
'https://github.com/google/flatbuffers.git',
93+
flatbuffersDir
94+
}
95+
}
96+
97+
// Locate or build flatc.
98+
String flatcDirPath = "$flatbuffersDir/flatc_build"
99+
def flatcDir = new File(flatcDirPath)
100+
flatcDir.mkdir()
101+
102+
String flatcExecDirPath = flatcDirPath
103+
String flatcFilename = "flatc"
104+
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
105+
flatcFilename += ".exe"
106+
flatcExecDirPath = "$flatcDirPath/Debug"
107+
}
108+
109+
def flatcExecDir = new File(flatcExecDirPath)
110+
111+
def flatcExec = new File(flatcExecDir, flatcFilename)
112+
if (!flatcExec.exists()) {
113+
exec {
114+
executable 'cmake'
115+
args '..'
116+
workingDir "${flatcDir.getPath()}"
117+
}
118+
exec {
119+
executable 'cmake'
120+
args '--build',
121+
'.',
122+
'--target',
123+
'flatc'
124+
workingDir "${flatcDir.getPath()}"
125+
}
126+
}
127+
128+
// Generate the java files from the schema files.
129+
def schemaFile = new File("./testdata_config_android.fbs")
130+
exec {
131+
executable "${flatcExec.getPath()}"
132+
args '--java',
133+
'-o',
134+
"$buildDir/flatbuffer_generated",
135+
"${schemaFile.getPath()}"
136+
}
137+
}
138+
preBuild.dependsOn generateFlatbufferFiles
139+
}
140+
141+
apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
142+
extractAndDexAarFile('testing')

testing/testdata_config_android.fbs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2020 Google
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+
// The FlatBuffers schema for configuring unit-test test data.
16+
17+
// The namespace is defined to match the google3 package.
18+
namespace com.google.firebase.testing.cppsdk;
19+
20+
// Captures the general three-value logic: true, false, error. In practice, it
21+
// could mean Success, Failure, Exception or Valid, Invalid, Exception, etc.
22+
// To reduce the work in dealing with test data, we want the default be true,
23+
// which is why 0 is assigned to true.
24+
enum FutureBoolResult : byte { True, False, Error }
25+
26+
// Bool in the future.
27+
table FutureBool {
28+
value:FutureBoolResult;
29+
ticker:long; // On which ticker, the value becomes available.
30+
}
31+
32+
// Integer in the future.
33+
table FutureInt {
34+
value:int;
35+
ticker:long; // On which ticker, the value becomes available.
36+
}
37+
38+
// A generic value in the future; a relevant fake class is expected to provide
39+
// the actual value at call time. The config will only state whether that value
40+
// or an exception is returned.
41+
table FutureGeneric {
42+
// If true, return an exception. If false, return the default value specified
43+
// in code.
44+
throwexception:bool;
45+
exceptionmsg:string; // The message of the exception;
46+
ticker:long; // On which ticker, the value becomes available.
47+
}
48+
49+
// Use this to tell fake function what value if should return.
50+
// If return value is complicated you can convert into string.
51+
table ReturnValue {
52+
tint:int;
53+
tbool:bool;
54+
tlong:long;
55+
tdouble:double;
56+
tstring:string;
57+
}
58+
59+
// Describe an HTTP/REST response.
60+
table HttpResponse {
61+
header: [string];
62+
body: [string];
63+
}
64+
65+
// A row in the config. When new data type is needed, add it here. (Order does
66+
// not matter right now since we do not store serialized data file yet.)
67+
table ConfigRow {
68+
// The magic key string to index test data.
69+
fake:string (required, key);
70+
71+
// Data type varies for different test fakes. Here we embed the type directly
72+
// inside row table instead of wrapping around by a table or union type. This
73+
// way the JSON string is less cumbersome.
74+
futurebool:FutureBool;
75+
futureint:FutureInt;
76+
futuregeneric:FutureGeneric;
77+
returnvalue:ReturnValue;
78+
httpresponse:HttpResponse;
79+
}
80+
81+
table TestDataConfig {
82+
config: [ConfigRow];
83+
}
84+
85+
root_type TestDataConfig;

0 commit comments

Comments
 (0)