@@ -51,26 +51,26 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
51
51
FileHandle_stub fh1;
52
52
FileHandle_stub fh2;
53
53
FileHandle_stub fh3;
54
- AT_CellularDevice dev (&fh1);
54
+ AT_CellularDevice dev (&fh1); // AT fh1 ref count 1
55
55
56
- EXPECT_TRUE (dev.open_network (&fh1));
56
+ EXPECT_TRUE (dev.open_network (&fh1)); // AT fh1 ref count 2
57
57
EXPECT_TRUE (dev.open_sms (&fh2));
58
58
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
59
59
EXPECT_TRUE (dev.open_information (&fh3));
60
60
ATHandler_stub::fh_value = &fh1;
61
- EXPECT_TRUE (dev.open_power (&fh1));
61
+ EXPECT_TRUE (dev.open_power (&fh1)); // AT fh1 ref count 3
62
62
63
63
ATHandler_stub::fh_value = NULL ;
64
64
65
- AT_CellularDevice *dev2 = new AT_CellularDevice (&fh1);
66
- EXPECT_TRUE (dev2->open_information (&fh1));
67
- ATHandler *at = dev2->get_at_handler ();
65
+ AT_CellularDevice *dev2 = new AT_CellularDevice (&fh1); // AT fh1 ref count 4
66
+ EXPECT_TRUE (dev2->open_information (&fh1)); // AT fh1 ref count 5
67
+ ATHandler *at = dev2->get_at_handler (); // AT fh1 ref count 6
68
+ EXPECT_TRUE (at->get_ref_count () == 6 );
69
+ delete dev2; // AT fh1 2 refs deleted -> ref count 4
68
70
EXPECT_TRUE (at->get_ref_count () == 4 );
69
- delete dev2;
70
- EXPECT_TRUE (at->get_ref_count () == 3 );
71
- AT_CellularDevice dev3 (&fh1);
72
- EXPECT_TRUE (dev3.release_at_handler (at) == NSAPI_ERROR_OK);
73
- EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
71
+ AT_CellularDevice dev3 (&fh1); // AT fh1 ref count 5
72
+ EXPECT_TRUE (dev3.release_at_handler (at) == NSAPI_ERROR_OK); // AT fh1 ref count 4
73
+ EXPECT_TRUE (ATHandler_stub::ref_count == 4 );
74
74
}
75
75
76
76
TEST_F (TestAT_CellularDevice, test_AT_CellularDevice_open_network)
@@ -129,42 +129,39 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
129
129
{
130
130
FileHandle_stub fh1;
131
131
AT_CellularDevice dev (&fh1);
132
- ATHandler_stub::ref_count = 0 ;
133
132
134
133
EXPECT_TRUE (dev.open_network (&fh1));
135
134
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
136
- EXPECT_TRUE (ATHandler_stub::ref_count == 1 );
135
+ EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
137
136
138
137
dev.close_network ();
139
- EXPECT_TRUE (ATHandler_stub::ref_count == kATHandler_destructor_ref_ount );
138
+ EXPECT_TRUE (ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount );
140
139
}
141
140
142
141
TEST_F (TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
143
142
{
144
143
FileHandle_stub fh1;
145
144
AT_CellularDevice dev (&fh1);
146
- ATHandler_stub::ref_count = 0 ;
147
145
148
146
EXPECT_TRUE (dev.open_sms (&fh1));
149
147
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
150
- EXPECT_TRUE (ATHandler_stub::ref_count == 1 );
148
+ EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
151
149
152
150
dev.close_sms ();
153
- EXPECT_TRUE (ATHandler_stub::ref_count == kATHandler_destructor_ref_ount );
151
+ EXPECT_TRUE (ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount );
154
152
}
155
153
156
154
TEST_F (TestAT_CellularDevice, test_AT_CellularDevice_close_power)
157
155
{
158
156
FileHandle_stub fh1;
159
157
AT_CellularDevice dev (&fh1);
160
- ATHandler_stub::ref_count = 0 ;
161
158
162
159
EXPECT_TRUE (dev.open_power (&fh1));
163
160
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
164
- EXPECT_TRUE (ATHandler_stub::ref_count == 1 );
161
+ EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
165
162
166
163
dev.close_power ();
167
- EXPECT_TRUE (ATHandler_stub::ref_count == kATHandler_destructor_ref_ount );
164
+ EXPECT_TRUE (ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount );
168
165
}
169
166
170
167
TEST_F (TestAT_CellularDevice, test_AT_CellularDevice_close_information)
@@ -188,7 +185,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
188
185
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
189
186
190
187
dev.close_information ();
191
- EXPECT_TRUE (ATHandler_stub::ref_count == kATHandler_destructor_ref_ount );
188
+ EXPECT_TRUE (ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount );
192
189
193
190
ATHandler_stub::fh_value = NULL ;
194
191
}
@@ -205,7 +202,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
205
202
EXPECT_TRUE (ATHandler_stub::default_timeout == true );
206
203
207
204
EXPECT_TRUE (dev.open_sms (&fh1));
208
- EXPECT_TRUE (ATHandler_stub::ref_count == 1 );
205
+ EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
209
206
210
207
dev.set_timeout (5000 );
211
208
EXPECT_TRUE (ATHandler_stub::timeout == 5000 );
@@ -224,7 +221,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
224
221
EXPECT_TRUE (ATHandler_stub::debug_on == true );
225
222
226
223
EXPECT_TRUE (dev.open_sms (&fh1));
227
- EXPECT_TRUE (ATHandler_stub::ref_count == 1 );
224
+ EXPECT_TRUE (ATHandler_stub::ref_count == 2 );
228
225
229
226
dev.modem_debug_on (true );
230
227
EXPECT_TRUE (ATHandler_stub::debug_on == true );
@@ -305,20 +302,20 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
305
302
AT_CellularDevice *dev = new AT_CellularDevice (&fh1);
306
303
307
304
ATHandler *at = dev->get_at_handler ();
308
- EXPECT_TRUE (at->get_ref_count () == 1 );
305
+ EXPECT_TRUE (at->get_ref_count () == 2 );
309
306
EXPECT_TRUE (dev->release_at_handler (at) == NSAPI_ERROR_OK);
310
307
311
308
CellularContext *ctx = dev->create_context (NULL );
312
309
delete dev;
313
310
314
311
dev = new AT_CellularDevice (&fh1);
315
312
at = dev->get_at_handler ();
316
- EXPECT_TRUE (at->get_ref_count () == 1 );
313
+ EXPECT_TRUE (at->get_ref_count () == 2 );
317
314
ctx = dev->create_context (NULL );
318
315
CellularContext *ctx1 = dev->create_context (&fh1);
319
- EXPECT_TRUE (at->get_ref_count () == 3 );
320
- CellularContext *ctx2 = dev->create_context (&fh1);
321
316
EXPECT_TRUE (at->get_ref_count () == 4 );
317
+ CellularContext *ctx2 = dev->create_context (&fh1);
318
+ EXPECT_TRUE (at->get_ref_count () == 5 );
322
319
323
320
EXPECT_TRUE (ctx);
324
321
EXPECT_TRUE (ctx1);
@@ -329,20 +326,20 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
329
326
EXPECT_TRUE (xx);
330
327
331
328
dev->delete_context (ctx);
332
- EXPECT_TRUE (at->get_ref_count () == 3 );
329
+ EXPECT_TRUE (at->get_ref_count () == 4 );
333
330
dev->delete_context (ctx1);
334
- EXPECT_TRUE (at->get_ref_count () == 2 );
331
+ EXPECT_TRUE (at->get_ref_count () == 3 );
335
332
dev->delete_context (NULL );
336
- EXPECT_TRUE (at->get_ref_count () == 2 );
333
+ EXPECT_TRUE (at->get_ref_count () == 3 );
337
334
dev->delete_context (ctx2);
338
- EXPECT_TRUE (at->get_ref_count () == 1 );
335
+ EXPECT_TRUE (at->get_ref_count () == 2 );
339
336
340
337
ctx = dev->create_context (NULL );
341
- EXPECT_TRUE (at->get_ref_count () == 2 );
342
- ctx1 = dev->create_context (&fh1);
343
338
EXPECT_TRUE (at->get_ref_count () == 3 );
344
- ctx2 = dev->create_context (&fh1);
339
+ ctx1 = dev->create_context (&fh1);
345
340
EXPECT_TRUE (at->get_ref_count () == 4 );
341
+ ctx2 = dev->create_context (&fh1);
342
+ EXPECT_TRUE (at->get_ref_count () == 5 );
346
343
EXPECT_TRUE (dev->release_at_handler (at) == NSAPI_ERROR_OK);
347
344
EXPECT_TRUE (ctx);
348
345
EXPECT_TRUE (ctx1);
0 commit comments