Skip to content

Commit ccb75d2

Browse files
author
Teppo Järvelin
committed
Cellular: fixed CellularDevice unittests by doing proper initializations between tests.
1 parent deb905d commit ccb75d2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

features/cellular/UNITTESTS/at/at_cellulardevice/test_at_cellulardevice.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_network()
118118
ATHandler_stub::ref_count = 0;
119119

120120
CHECK(dev.open_network(&fh1));
121+
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
121122
CHECK(ATHandler_stub::ref_count == 1);
122123

123124
dev.close_network();
124-
CHECK(ATHandler_stub::ref_count == 0);
125+
CHECK(ATHandler_stub::ref_count == -909);
125126
}
126127

127128
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
@@ -132,10 +133,11 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
132133
ATHandler_stub::ref_count = 0;
133134

134135
CHECK(dev.open_sms(&fh1));
136+
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
135137
CHECK(ATHandler_stub::ref_count == 1);
136138

137139
dev.close_sms();
138-
CHECK(ATHandler_stub::ref_count == 0);
140+
CHECK(ATHandler_stub::ref_count == -909);
139141
}
140142

141143
void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
@@ -146,10 +148,11 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
146148
ATHandler_stub::ref_count = 0;
147149

148150
CHECK(dev.open_power(&fh1));
151+
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
149152
CHECK(ATHandler_stub::ref_count == 1);
150153

151154
dev.close_power();
152-
CHECK(ATHandler_stub::ref_count == 0);
155+
CHECK(ATHandler_stub::ref_count == -909);
153156
}
154157

155158
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
@@ -161,11 +164,13 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
161164

162165

163166
CHECK(dev.open_sim(&fh1));
167+
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
168+
164169
dev.close_sms(); // this should not affect to refcount as it's not opened
165170
CHECK(ATHandler_stub::ref_count == 1);
166171

167172
dev.close_sim();
168-
CHECK(ATHandler_stub::ref_count == 0);
173+
CHECK(ATHandler_stub::ref_count == -909);
169174
}
170175

171176
void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
@@ -174,21 +179,28 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
174179
AT_CellularDevice dev(que);
175180
FileHandle_stub fh1;
176181
ATHandler_stub::int_value = 0;
182+
ATHandler_stub::ref_count = 0;
183+
ATHandler_stub::fh_value = NULL;
184+
AT_CellularBase_stub::handler_value = NULL;
177185

178186
CHECK(dev.open_information(&fh1));
187+
CHECK(ATHandler_stub::ref_count == 1);
179188

180-
ATHandler_stub::fh_value = NULL;
181-
AT_CellularBase_stub::handler_value = NULL;
189+
// at handler is not found as it's NULL (e.g. AT_CellularBase_stub::handler_value is NULL)
182190
dev.close_information();
191+
CHECK(ATHandler_stub::ref_count == 1);
183192

193+
// same filehandle but different at
184194
ATHandler_stub::fh_value = &fh1;
185195
ATHandler at(&fh1, que, 0, ",");
186196
AT_CellularBase_stub::handler_value = &at;
187197

188198
CHECK(dev.open_information(&fh1));
189-
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
199+
// refcount is two it's one when we create athandler and then in open_information it's incremented by one
200+
CHECK(ATHandler_stub::ref_count == 2);
190201

191202
dev.close_information();
203+
CHECK(ATHandler_stub::ref_count == 1);
192204

193205
ATHandler_stub::fh_value = NULL;
194206
}

0 commit comments

Comments
 (0)