Skip to content

Commit 886eca4

Browse files
author
Alex Ames
committed
Added sync_point_spec.json, a file containing SyncPoint test specifications.
This file is nearly identical to test files found in the Android and iOS implementations except with two minor changes: ".comment" fields have been renamed just "comment", and the list of test cases is now enclosed in a wrapper table. Both of these changes were made so that the JSON was compatible with Flatbuffers, which makes parsing the data much easier from C++.
1 parent 4dbe73d commit 886eca4

File tree

3 files changed

+8339
-0
lines changed

3 files changed

+8339
-0
lines changed

database/tests/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,38 @@ firebase_cpp_cc_test(
225225
firebase_testing
226226
)
227227

228+
set(SYNC_POINT_SPEC_SCHEMA "${CMAKE_CURRENT_LIST_DIR}/desktop/core/sync_point_spec.fbs")
229+
set(SYNC_POINT_SPEC_JSON "${CMAKE_CURRENT_LIST_DIR}/desktop/core/sync_point_spec.json")
230+
231+
flatbuffers_generate_headers(
232+
TARGET firebase_sync_point_spec
233+
SCHEMAS ${SYNC_POINT_SPEC_SCHEMA}
234+
INCLUDE_PREFIX "database/src/desktop/core"
235+
)
236+
237+
flatbuffers_generate_binary_files(
238+
TARGET firebase_sync_point_spec_data
239+
SCHEMA ${SYNC_POINT_SPEC_SCHEMA}
240+
JSON_FILES ${SYNC_POINT_SPEC_JSON}
241+
OUTPUT_DIR "${PROJECT_BINARY_DIR}/database/tests"
242+
)
243+
244+
firebase_cpp_cc_test(
245+
firebase_rtdb_desktop_core_sync_point_spec_test
246+
SOURCES
247+
desktop/core/sync_point_spec_test.cc
248+
desktop/test/mock_listen_provider.h
249+
desktop/test/mock_listener.h
250+
desktop/test/mock_persistence_manager.h
251+
desktop/test/mock_persistence_storage_engine.h
252+
desktop/test/mock_tracked_query_manager.h
253+
desktop/test/mock_write_tree.h
254+
DEPENDS
255+
firebase_database
256+
firebase_sync_point_spec
257+
firebase_sync_point_spec_data
258+
firebase_testing
259+
)
228260
firebase_cpp_cc_test(
229261
firebase_rtdb_desktop_core_sync_tree_test
230262
SOURCES
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2021 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+
// This schema uses some non-idiomatic style for field names because it's
16+
// designed to parse an existing JSON file used by the Android and iOS
17+
// implementations of Realtime Database.
18+
19+
namespace firebase.database.internal.test_data;
20+
21+
// Order of these enum values matters. It must match the order of the EventType
22+
// enum in `database/src/desktop/view/event_type.h`
23+
enum EventType : uint8 {
24+
child_removed,
25+
child_added,
26+
child_moved,
27+
child_changed,
28+
value,
29+
}
30+
31+
enum StepType : uint8 {
32+
ackUserWrite,
33+
listen,
34+
serverMerge,
35+
serverUpdate,
36+
set,
37+
suppressWarning,
38+
unlisten,
39+
update,
40+
}
41+
42+
table Event {
43+
path: string;
44+
type: EventType;
45+
name: string;
46+
prevName: string;
47+
data: [uint8] (flexbuffer);
48+
}
49+
50+
table Bound {
51+
index: [uint8] (flexbuffer);
52+
name: string;
53+
}
54+
55+
table QueryParams {
56+
tag: int32;
57+
limitToFirst: int32;
58+
limitToLast: int32;
59+
orderByKey: bool;
60+
orderByPriority: bool;
61+
startAt: Bound;
62+
endAt: Bound;
63+
equalTo: Bound;
64+
orderBy: string;
65+
}
66+
67+
table Step {
68+
// A comment that may be printed during the test, describing what the action
69+
// that the current step is performing.
70+
comment: string;
71+
72+
type: StepType;
73+
path: string;
74+
tag: int64;
75+
params: QueryParams;
76+
data: [uint8] (flexbuffer);
77+
events: [Event];
78+
79+
visible: bool = true;
80+
callbackId: int32;
81+
writeId: int32;
82+
revert: bool;
83+
}
84+
85+
table TestCase {
86+
// A comment that may be printed during the test, describing what the what is
87+
// being tested.
88+
comment: string;
89+
90+
// The name of the test.
91+
name: string;
92+
93+
// The series of steps in this test, including what actions to take and what
94+
// events are expected to be raised at each step.
95+
steps: [Step];
96+
}
97+
98+
table TestSuite {
99+
test_cases: [TestCase];
100+
}
101+
102+
root_type TestSuite;

0 commit comments

Comments
 (0)