16
16
17
17
#import < XCTest/XCTest.h>
18
18
19
- #import < FirebaseCommunity/FIRLogger.h>
20
19
#import < Firestore/FIRFirestoreSettings.h>
21
20
22
21
#import " Auth/FSTEmptyCredentialsProvider.h"
@@ -42,61 +41,61 @@ @interface FSTStreamStatusDelegate : NSObject <FSTWatchStreamDelegate, FSTWriteS
42
41
@property (nonatomic , readonly ) NSMutableArray <NSString *> *states;
43
42
@property (atomic , readwrite ) BOOL invokeCallbacks;
44
43
@property (nonatomic , weak ) XCTestExpectation *expectation;
45
- @property (nonatomic , weak , readonly ) FSTStream *stream;
46
44
47
- - (instancetype )initWithStream : (FSTStream *)stream NS_DESIGNATED_INITIALIZER;
48
- - (instancetype )init NS_UNAVAILABLE;
49
45
@end
50
46
51
47
@implementation FSTStreamStatusDelegate
52
48
53
- - (instancetype )initWithStream : (FSTStream *) stream {
49
+ - (instancetype )init {
54
50
if (self = [super init ]) {
55
51
_states = [NSMutableArray new ];
56
- _stream = stream;
57
52
}
58
53
59
54
return self;
60
55
}
61
56
62
- - (void )streamDidReceiveChange : (FSTWatchChange *)change
63
- snapshotVersion : (FSTSnapshotVersion *)snapshotVersion {
64
- [_states addObject: @" didReceiveChange" ];
57
+ - (void )watchStreamDidOpen {
58
+ [_states addObject: @" watchStreamDidOpen" ];
65
59
[_expectation fulfill ];
66
60
_expectation = nil ;
67
61
}
68
62
69
- - (void )streamDidOpen {
70
- [_states addObject: @" didOpen " ];
63
+ - (void )writeStreamDidOpen {
64
+ [_states addObject: @" writeStreamDidOpen " ];
71
65
[_expectation fulfill ];
72
66
_expectation = nil ;
73
67
}
74
68
75
- - (void )streamDidClose : ( NSError *_Nullable) error {
76
- [_states addObject: @" didClose " ];
69
+ - (void )writeStreamDidCompleteHandshake {
70
+ [_states addObject: @" writeStreamDidCompleteHandshake " ];
77
71
[_expectation fulfill ];
78
72
_expectation = nil ;
79
73
}
80
74
81
- - (void )streamDidCompleteHandshake {
82
- [_states addObject: @" didCompleteHandshake " ];
75
+ - (void )writeStreamWasInterrupted : ( NSError *_Nullable) error {
76
+ [_states addObject: @" writeStreamWasInterrupted " ];
83
77
[_expectation fulfill ];
84
78
_expectation = nil ;
85
79
}
86
80
87
- - (void )streamDidReceiveResponseWithVersion : (FSTSnapshotVersion *)commitVersion
88
- mutationResults : (NSArray <FSTMutationResult *> *)results {
89
- [_states addObject: @" didReceiveResponse" ];
81
+ - (void )watchStreamWasInterrupted : (NSError *_Nullable)error {
82
+ [_states addObject: @" watchStreamWasInterrupted" ];
90
83
[_expectation fulfill ];
91
84
_expectation = nil ;
92
85
}
93
86
94
- - (void )writeValue : (id )value {
95
- [self .stream writeValue: value];
87
+ - (void )watchStreamDidChange : (FSTWatchChange *)change
88
+ snapshotVersion : (FSTSnapshotVersion *)snapshotVersion {
89
+ [_states addObject: @" watchStreamDidChange" ];
90
+ [_expectation fulfill ];
91
+ _expectation = nil ;
96
92
}
97
93
98
- - (void )writesFinishedWithError : (NSError *)errorOrNil {
99
- [self .stream writesFinishedWithError: errorOrNil];
94
+ - (void )writeStreamDidReceiveResponseWithVersion : (FSTSnapshotVersion *)commitVersion
95
+ mutationResults : (NSArray <FSTMutationResult *> *)results {
96
+ [_states addObject: @" writeStreamDidReceiveResponseWithVersion" ];
97
+ [_expectation fulfill ];
98
+ _expectation = nil ;
100
99
}
101
100
102
101
- (void )fulfillOnCallback : (XCTestExpectation *)expectation {
@@ -113,9 +112,9 @@ @interface FSTStreamTests : XCTestCase
113
112
@implementation FSTStreamTests {
114
113
dispatch_queue_t _testQueue;
115
114
FSTDatabaseInfo *_databaseInfo;
116
- FSTTestDispatchQueue *_workerDispatchQueue;
117
115
FSTEmptyCredentialsProvider *_credentials;
118
116
FSTStreamStatusDelegate *_delegate;
117
+ FSTTestDispatchQueue *_workerDispatchQueue;
119
118
120
119
/* * Single mutation to send to the write stream. */
121
120
NSArray <FSTMutation *> *_mutations;
@@ -149,20 +148,16 @@ - (FSTWriteStream *)setUpWriteStream {
149
148
workerDispatchQueue: _workerDispatchQueue
150
149
credentials: _credentials];
151
150
152
- FSTWriteStream *stream = [datastore createWriteStream ];
153
- _delegate = [[FSTStreamStatusDelegate alloc ] initWithStream: stream];
154
-
155
- return stream;
151
+ _delegate = [FSTStreamStatusDelegate new ];
152
+ return [datastore createWriteStream ];
156
153
}
157
154
158
155
- (FSTWatchStream *)setUpWatchStream {
159
156
FSTDatastore *datastore = [[FSTDatastore alloc ] initWithDatabaseInfo: _databaseInfo
160
157
workerDispatchQueue: _workerDispatchQueue
161
158
credentials: _credentials];
162
- FSTWatchStream *stream = [datastore createWatchStream ];
163
- _delegate = [[FSTStreamStatusDelegate alloc ] initWithStream: stream];
164
-
165
- return stream;
159
+ _delegate = [FSTStreamStatusDelegate new ];
160
+ return [datastore createWatchStream ];
166
161
}
167
162
168
163
- (void )verifyDelegate : (NSArray <NSString *> *)expectedStates {
@@ -193,7 +188,7 @@ - (void)testWatchStreamStopBeforeHandshake {
193
188
// Simulate a final callback from GRPC
194
189
[watchStream writesFinishedWithError: nil ];
195
190
196
- [self verifyDelegate: @[ @" didOpen " ]];
191
+ [self verifyDelegate: @[ @" watchStreamDidOpen " ]];
197
192
}
198
193
199
194
/* * Verifies that the write stream does not issue an onClose callback after a call to stop(). */
@@ -218,7 +213,7 @@ - (void)testWriteStreamStopBeforeHandshake {
218
213
// Simulate a final callback from GRPC
219
214
[writeStream writesFinishedWithError: nil ];
220
215
221
- [self verifyDelegate: @[ @" didOpen " ]];
216
+ [self verifyDelegate: @[ @" writeStreamDidOpen " ]];
222
217
}
223
218
224
219
- (void )testWriteStreamStopAfterHandshake {
@@ -255,7 +250,7 @@ - (void)testWriteStreamStopAfterHandshake {
255
250
[writeStream stop ];
256
251
}];
257
252
258
- [self verifyDelegate: @[ @" didOpen " , @" didCompleteHandshake " , @" didReceiveResponse " ]];
253
+ [self verifyDelegate: @[ @" writeStreamDidOpen " , @" writeStreamDidCompleteHandshake " , @" writeStreamDidReceiveResponseWithVersion " ]];
259
254
}
260
255
261
256
- (void )testStreamClosesWhenIdle {
@@ -286,7 +281,7 @@ - (void)testStreamClosesWhenIdle {
286
281
XCTAssertFalse ([writeStream isOpen ]);
287
282
});
288
283
289
- [self verifyDelegate: @[ @" didOpen " , @" didCompleteHandshake " , @" didClose " ]];
284
+ [self verifyDelegate: @[ @" writeStreamDidOpen " , @" writeStreamDidCompleteHandshake " , @" writeStreamWasInterrupted " ]];
290
285
}
291
286
292
287
- (void )testStreamCancelsIdleOnWrite {
@@ -327,7 +322,7 @@ - (void)testStreamCancelsIdleOnWrite {
327
322
[writeStream stop ];
328
323
}];
329
324
330
- [self verifyDelegate: @[ @" didOpen " , @" didCompleteHandshake " , @" didReceiveResponse " ]];
325
+ [self verifyDelegate: @[ @" writeStreamDidOpen " , @" writeStreamDidCompleteHandshake " , @" writeStreamDidReceiveResponseWithVersion " ]];
331
326
}
332
327
333
328
@end
0 commit comments