Skip to content

Commit e99489a

Browse files
ryanmeiera-maurice
authored andcommitted
Open Source support for IID Tests, testing/cppsdk
This CL makes the changes necessary to run the basic Instance ID tests with the Firebase ++ Open Source build. In order to make this work, this CL also adds Open Source support to //firebase/testing/cppsdk/, which is used by the IID tests (and presumably a number of other C++ tests). Additionally, added a workflow to the copy.bara.sky script to support copying from in-progress CLs. PiperOrigin-RevId: 258222273
1 parent d7fbaa1 commit e99489a

File tree

8 files changed

+186
-10
lines changed

8 files changed

+186
-10
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ add_external_library(flatbuffers)
102102

103103
if(FIREBASE_CPP_BUILD_TESTS)
104104
add_external_library(googletest)
105+
add_external_library(absl)
105106
endif()
106107

107108
# Some of the external libraries are not used for mobile.
@@ -255,6 +256,12 @@ endif()
255256
# then refer to.
256257
set(FIREBASE_CPP_SDK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
257258

259+
# If we're building tests, we need to include the 'testing' folder before any
260+
# of the tests actually get built.
261+
if(FIREBASE_CPP_BUILD_TESTS)
262+
add_subdirectory(testing)
263+
endif()
264+
258265
# App needs to come first, since other libraries will depend upon it.
259266
add_subdirectory(app)
260267
if (FIREBASE_INCLUDE_ADMOB)

cmake/test_rules.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function(cc_test name)
2727
# Parse the arguments into cc_test_SOURCES and cc_test_DEPENDS.
2828
cmake_parse_arguments(cc_test "" "" "${multi}" ${ARGN})
2929

30-
list(APPEND cc_test_DEPENDS gtest gtest_main)
30+
list(APPEND cc_test_DEPENDS gmock gtest gtest_main)
3131

3232
add_executable(${name} ${cc_test_SOURCES})
3333
add_test(${name} ${name})
@@ -36,4 +36,8 @@ function(cc_test name)
3636
${FIREBASE_SOURCE_DIR}
3737
)
3838
target_link_libraries(${name} PRIVATE ${cc_test_DEPENDS})
39+
target_compile_definitions(${name}
40+
PRIVATE
41+
-DINTERNAL_EXPERIMENTAL=1
42+
)
3943
endfunction()

instance_id/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ if(IOS)
119119
# Add a dependency to downloading the headers onto instance_id.
120120
add_dependencies(firebase_instance_id ${pod_target_name})
121121
endif()
122+
123+
if(FIREBASE_CPP_BUILD_TESTS)
124+
# Add the tests subdirectory
125+
add_subdirectory(tests)
126+
endif()

testing/CMakeLists.txt

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
cmake_minimum_required (VERSION 3.1)
2+
set (CMAKE_CXX_STANDARD 11)
3+
4+
include(binary_to_array)
5+
6+
project(firebase_testing NONE)
7+
enable_language(C)
8+
enable_language(CXX)
9+
10+
# Build the testdata_config generated files using flatbuffers
11+
set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS
12+
"--no-union-value-namespacing"
13+
"--gen-object-api"
14+
"--cpp-ptr-type" "flatbuffers::unique_ptr")
15+
build_flatbuffers("${CMAKE_CURRENT_LIST_DIR}/testdata_config.fbs"
16+
""
17+
"generate_testing_fps"
18+
"${FIREBASE_FLATBUFFERS_DEPENDENCIES}"
19+
"${FIREBASE_GEN_FILE_DIR}/testing"
20+
""
21+
"")
22+
binary_to_array("testdata_config_resource"
23+
"${CMAKE_CURRENT_LIST_DIR}/testdata_config.fbs"
24+
"firebase::testing::cppsdk"
25+
"${FIREBASE_GEN_FILE_DIR}/testing")
26+
27+
28+
set(config_common_SRCS
29+
config.h
30+
config.cc
31+
config_test.cc
32+
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_generated.h
33+
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_resource.h
34+
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_resource.cc)
35+
set(config_android_SRCS
36+
config_android.cc)
37+
set(config_ios_SRCS
38+
config_ios.h
39+
config_ios.mm)
40+
set(config_desktop_SRCS
41+
config_desktop.h
42+
config_desktop.cc)
43+
if(ANDROID)
44+
set(config_SRCS
45+
"${config_common_SRCS}"
46+
"${config_android_SRCS}")
47+
elseif(IOS)
48+
set(config_SRCS
49+
"${config_common_SRCS}"
50+
"${config_ios_SRCS}")
51+
else()
52+
set(config_SRCS
53+
"${config_common_SRCS}"
54+
"${config_desktop_SRCS}")
55+
endif()
56+
57+
set(reporter_common_SRCS
58+
reporter.h
59+
reporter.cc
60+
reporter_test.cc
61+
reporter_impl.h
62+
reporter_impl.cc
63+
reporter_impl_test.cc
64+
)
65+
set(reporter_android_SRCS
66+
reporter_android.cc)
67+
if(ANDROID)
68+
set(reporter_SRCS
69+
"${reporter_common_SRCS}"
70+
"${reporter_android_SRCS}")
71+
else()
72+
set(reporter_SRCS
73+
"${reporter_common_SRCS}")
74+
endif()
75+
76+
set(ticker_common_SRCS
77+
ticker.h
78+
ticker_test.cc)
79+
set(ticker_android_SRCS
80+
ticker_android.cc)
81+
set(ticker_ios_SRCS
82+
ticker_ios.h)
83+
set(ticker_desktop_SRCS
84+
ticker_desktop.h
85+
ticker_desktop.cc)
86+
if(ANDROID)
87+
set(ticker_SRCS
88+
"${ticker_common_SRCS}"
89+
"${ticker_android_SRCS}")
90+
elseif(IOS)
91+
set(ticker_SRCS
92+
"${ticker_common_SRCS}"
93+
"${ticker_ios_SRCS}")
94+
else()
95+
set(ticker_SRCS
96+
"${ticker_common_SRCS}"
97+
"${ticker_desktop_SRCS}")
98+
endif()
99+
100+
set(util_android_SRCS
101+
util_android.h
102+
util_android.cc
103+
util_android_test.cc)
104+
set(util_ios_SRCS
105+
util_ios.h
106+
util_ios.mm
107+
util_ios_test.mm)
108+
if(ANDROID)
109+
set(util_SRCS
110+
"${util_android_SRCS}")
111+
elseif(IOS)
112+
set(util_SRCS
113+
"${util_ios_SRCS}")
114+
else()
115+
set(util_SRCS "")
116+
endif()
117+
118+
add_library(firebase_testing STATIC
119+
${config_SRCS}
120+
${reporter_SRCS}
121+
${ticker_SRCS}
122+
${util_SRCS})
123+
124+
target_include_directories(firebase_testing
125+
PUBLIC
126+
${FLATBUFFERS_SOURCE_DIR}/include
127+
PRIVATE
128+
${FIREBASE_CPP_SDK_ROOT_DIR}
129+
${FIREBASE_GEN_FILE_DIR}
130+
)
131+
132+
target_link_libraries(firebase_testing
133+
PRIVATE
134+
gtest
135+
gmock
136+
)

testing/config.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "testing/config.h"
22

3-
#include "base/logging.h"
3+
#include "gtest/gtest.h"
4+
#include "gmock/gmock.h"
45
#include "testing/testdata_config_resource.h"
56
#include "flatbuffers/idl.h"
67

8+
79
namespace firebase {
810
namespace testing {
911
namespace cppsdk {
@@ -15,8 +17,10 @@ void ConfigSet(const char* test_data_in_json) {
1517
flatbuffers::Parser parser;
1618
const char* schema_str =
1719
reinterpret_cast<const char*>(testdata_config_resource_data);
18-
CHECK(parser.Parse(schema_str)) << "Failed to parse schema:" << parser.error_;
19-
CHECK(parser.Parse(test_data_in_json)) << "Invalid JSON:" << parser.error_;
20+
ASSERT_TRUE(parser.Parse(schema_str))
21+
<< "Failed to parse schema:" << parser.error_;
22+
ASSERT_TRUE(parser.Parse(test_data_in_json))
23+
<< "Invalid JSON:" << parser.error_;
2024

2125
// Assign
2226
internal::ConfigSetImpl(parser.builder_.GetBufferPointer(),

testing/config_desktop.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "testing/config_desktop.h"
22
#include "testing/config.h"
33

4+
#include <cassert>
45
#include <cstdint>
6+
#include <cstdlib>
57

6-
#include "base/logging.h"
78
#include "app/src/mutex.h"
9+
#include "gtest/gtest.h"
10+
#include "gmock/gmock.h"
811
#include "testing/testdata_config_generated.h"
912
#include "flatbuffers/idl.h"
1013

@@ -23,7 +26,12 @@ static std::vector<uint8_t*> g_all_test_data; // NOLINT
2326

2427
const ConfigRow* ConfigGet(const char* fake) {
2528
MutexLock lock(testing_mutex);
26-
CHECK(g_test_data_config != nullptr) << "No test data at all";
29+
30+
if (g_test_data_config == nullptr) {
31+
ADD_FAILURE() << "No test data at all";
32+
assert(false);
33+
}
34+
2735
const TestDataConfig* config = GetTestDataConfig(g_test_data_config);
2836
// LookupByKey() does not work because the data passed in may not conform. So
2937
// we just iterate over the test data.

testing/reporter.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include <algorithm>
22
#include <set>
3+
#include <sstream>
34
#include <string>
45
#include <utility>
56
#include <vector>
67

78
#include "testing/reporter.h"
8-
#include "third_party/absl/strings/str_cat.h"
9-
#include "third_party/absl/strings/str_join.h"
109

1110
namespace firebase {
1211
namespace testing {
@@ -72,8 +71,17 @@ bool ReportRow::operator<(const ReportRow& other) const {
7271
}
7372

7473
std::string ReportRow::toString() const {
75-
return absl::StrCat(fake_, " ", result_, " ", getPlatformString(), " [",
76-
absl::StrJoin(args_, " "), "]");
74+
std::ostringstream stream;
75+
76+
stream << fake_ << " " << result_ << " " << getPlatformString() << " [";
77+
for (int i = 0; i < args_.size(); i++) {
78+
stream << args_[i];
79+
if (i < args_.size()-1)
80+
stream << " ";
81+
}
82+
stream << "]";
83+
84+
return stream.str();
7785
}
7886

7987
::std::ostream& operator<<(::std::ostream& os, const ReportRow& r) {

testing/run_all_tests.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef FIREBASE_TESTING_CPPSDK_RUN_ALL_TESTS_H_
55
#define FIREBASE_TESTING_CPPSDK_RUN_ALL_TESTS_H_
66

7+
#if defined(__ANDROID__) || defined(FIREBASE_ANDROID_FOR_DESKTOP)
8+
79
#include <jni.h>
810

911
namespace firebase {
@@ -27,4 +29,6 @@ inline jobject GetTestActivity() {
2729
} // namespace testing
2830
} // namespace firebase
2931

32+
#endif // defined(__ANDROID__) || defined(FIREBASE_ANDROID_FOR_DESKTOP)
33+
3034
#endif // FIREBASE_TESTING_CPPSDK_RUN_ALL_TESTS_H_

0 commit comments

Comments
 (0)