30
30
// system dependencies
31
31
#import < XCTest/XCTest.h>
32
32
33
- // Set the following to 1 in order to run individual test case manually.
34
- #define MANUAL_INDIVIDUAL_TEST 0
35
-
36
33
static const uint16_t kPairingTimeoutInSeconds = 10 ;
37
34
static const uint16_t kCASESetupTimeoutInSeconds = 30 ;
38
35
static const uint16_t kTimeoutInSeconds = 3 ;
@@ -94,24 +91,44 @@ - (void)onCommissioningComplete:(NSError *)error
94
91
@interface MTRBackwardsCompatTests : XCTestCase
95
92
@end
96
93
94
+ static BOOL sStackInitRan = NO ;
95
+ static BOOL sNeedsStackShutdown = YES ;
96
+
97
97
@implementation MTRBackwardsCompatTests
98
98
99
+ + (void )tearDown
100
+ {
101
+ // Global teardown, runs once
102
+ if (sNeedsStackShutdown ) {
103
+ // We don't need to worry about ResetCommissionee. If we get here,
104
+ // we're running only one of our test methods (using
105
+ // -only-testing:MatterTests/MTROTAProviderTests/testMethodName), since
106
+ // we did not run test999_TearDown.
107
+ [self shutdownStack ];
108
+ }
109
+ }
110
+
99
111
- (void )setUp
100
112
{
113
+ // Per-test setup, runs before each test.
101
114
[super setUp ];
102
115
[self setContinueAfterFailure: NO ];
116
+
117
+ if (sStackInitRan == NO ) {
118
+ [self initStack ];
119
+ }
103
120
}
104
121
105
122
- (void )tearDown
106
123
{
107
- #if MANUAL_INDIVIDUAL_TEST
108
- [self shutdownStack ];
109
- #endif
124
+ // Per-test teardown, runs after each test.
110
125
[super tearDown ];
111
126
}
112
127
113
128
- (void )initStack
114
129
{
130
+ sStackInitRan = YES ;
131
+
115
132
XCTestExpectation * expectation = [self expectationWithDescription: @" Pairing Complete" ];
116
133
117
134
__auto_type * factory = [MTRControllerFactory sharedInstance ];
@@ -166,8 +183,10 @@ - (void)initStack
166
183
[self waitForExpectationsWithTimeout: kCASESetupTimeoutInSeconds handler: nil ];
167
184
}
168
185
169
- - (void )shutdownStack
186
+ + (void )shutdownStack
170
187
{
188
+ sNeedsStackShutdown = NO ;
189
+
171
190
MTRDeviceController * controller = sController ;
172
191
XCTAssertNotNil (controller);
173
192
@@ -177,12 +196,12 @@ - (void)shutdownStack
177
196
[[MTRControllerFactory sharedInstance ] shutdown ];
178
197
}
179
198
180
- #if !MANUAL_INDIVIDUAL_TEST
181
199
- (void )test000_SetUp
182
200
{
183
- [self initStack ];
201
+ // Nothing to do here; our setUp method handled this already. This test
202
+ // just exists to make the setup not look like it's happening inside other
203
+ // tests.
184
204
}
185
- #endif
186
205
187
206
#define CHECK_RETURN_TYPE (sig, type ) \
188
207
do { \
@@ -1177,12 +1196,10 @@ - (void)test046_MTRThreadOperationalDataset
1177
1196
CHECK_RETURN_TYPE (sig, NSData *);
1178
1197
}
1179
1198
1180
- #if !MANUAL_INDIVIDUAL_TEST
1181
1199
- (void )test999_TearDown
1182
1200
{
1183
1201
ResetCommissionee (GetConnectedDevice (), dispatch_get_main_queue (), self, kTimeoutInSeconds );
1184
- [self shutdownStack ];
1202
+ [[ self class ] shutdownStack ];
1185
1203
}
1186
- #endif
1187
1204
1188
1205
@end
0 commit comments