mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: added more unit tests for CellularDevice.
parent
2aa5c32aa4
commit
3311a6e456
|
@ -97,3 +97,17 @@ TEST(AT_CellularDevice, test_AT_CellularDevice_close_information)
|
|||
unit->test_AT_CellularDevice_close_information();
|
||||
}
|
||||
|
||||
TEST(AT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
||||
{
|
||||
unit->test_AT_CellularDevice_set_timeout();
|
||||
}
|
||||
|
||||
TEST(AT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
||||
{
|
||||
unit->test_AT_CellularDevice_modem_debug_on();
|
||||
}
|
||||
|
||||
TEST(AT_CellularDevice, test_AT_CellularDevice_get_stack)
|
||||
{
|
||||
unit->test_AT_CellularDevice_get_stack();
|
||||
}
|
||||
|
|
|
@ -112,22 +112,56 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_open_information()
|
|||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_close_network()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
CHECK(dev.open_network(&fh1));
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_network();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
CHECK(dev.open_sms(&fh1));
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_sms();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
CHECK(dev.open_power(&fh1));
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_power();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
|
||||
CHECK(dev.open_sim(&fh1));
|
||||
dev.close_sms(); // this should not affect to refcount as it's not opened
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_sim();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
|
||||
|
@ -155,3 +189,61 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
|
|||
ATHandler_stub::fh_value = NULL;
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_set_timeout()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::timeout = 0;
|
||||
ATHandler_stub::default_timeout = false;
|
||||
|
||||
// no interfaces open so settings timeout should not change anything
|
||||
dev.set_timeout(5000);
|
||||
CHECK(ATHandler_stub::timeout == 0);
|
||||
CHECK(ATHandler_stub::default_timeout == false);
|
||||
|
||||
CHECK(dev.open_sim(&fh1));
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.set_timeout(5000);
|
||||
CHECK(ATHandler_stub::timeout == 5000);
|
||||
CHECK(ATHandler_stub::default_timeout == true);
|
||||
|
||||
dev.close_sim();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_modem_debug_on()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::debug_on = false;
|
||||
|
||||
// no interfaces open so debug toggling should not affect
|
||||
dev.modem_debug_on(true);
|
||||
CHECK(ATHandler_stub::debug_on == false);
|
||||
|
||||
CHECK(dev.open_sim(&fh1));
|
||||
CHECK(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.modem_debug_on(true);
|
||||
CHECK(ATHandler_stub::debug_on == true);
|
||||
|
||||
dev.close_sim();
|
||||
}
|
||||
|
||||
void Test_AT_CellularDevice::test_AT_CellularDevice_get_stack()
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
NetworkStack *stack = dev.get_stack();
|
||||
CHECK(stack == NULL);
|
||||
|
||||
CHECK(dev.open_network(&fh1));
|
||||
|
||||
stack = dev.get_stack();
|
||||
CHECK(stack == NULL); // Not in PPP so also null but this is got from the network class
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,12 @@ public:
|
|||
void test_AT_CellularDevice_close_sim();
|
||||
|
||||
void test_AT_CellularDevice_close_information();
|
||||
|
||||
void test_AT_CellularDevice_set_timeout();
|
||||
|
||||
void test_AT_CellularDevice_modem_debug_on();
|
||||
|
||||
void test_AT_CellularDevice_get_stack();
|
||||
};
|
||||
|
||||
#endif // TEST_AT_CELLULARDEVICE_H
|
||||
|
|
|
@ -31,6 +31,10 @@ const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds
|
|||
nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
|
||||
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
|
||||
int ATHandler_stub::int_value = -1;
|
||||
int ATHandler_stub::ref_count = 0;
|
||||
int ATHandler_stub::timeout = 0;
|
||||
bool ATHandler_stub::default_timeout = 0;
|
||||
bool ATHandler_stub::debug_on = 0;
|
||||
ssize_t ATHandler_stub::ssize_value = 0;
|
||||
char* ATHandler_stub::read_string_value = NULL;
|
||||
size_t ATHandler_stub::size_value = 0;
|
||||
|
@ -47,27 +51,32 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
|
|||
_fileHandle(fh),
|
||||
_queue(queue)
|
||||
{
|
||||
ATHandler_stub::ref_count = 1;
|
||||
}
|
||||
|
||||
void ATHandler::enable_debug(bool enable)
|
||||
{
|
||||
ATHandler_stub::debug_on = enable;
|
||||
}
|
||||
|
||||
ATHandler::~ATHandler()
|
||||
{
|
||||
ATHandler_stub::ref_count = -909;
|
||||
}
|
||||
|
||||
void ATHandler::inc_ref_count()
|
||||
{
|
||||
ATHandler_stub::ref_count++;
|
||||
}
|
||||
|
||||
void ATHandler::dec_ref_count()
|
||||
{
|
||||
ATHandler_stub::ref_count--;
|
||||
}
|
||||
|
||||
int ATHandler::get_ref_count()
|
||||
{
|
||||
return ATHandler_stub::int_value;
|
||||
return ATHandler_stub::ref_count;
|
||||
}
|
||||
|
||||
FileHandle *ATHandler::get_file_handle()
|
||||
|
@ -113,6 +122,8 @@ nsapi_error_t ATHandler::unlock_return_error()
|
|||
|
||||
void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout)
|
||||
{
|
||||
ATHandler_stub::timeout = timeout_milliseconds;
|
||||
ATHandler_stub::default_timeout = default_timeout;
|
||||
}
|
||||
|
||||
void ATHandler::restore_at_timeout()
|
||||
|
|
|
@ -28,6 +28,10 @@ namespace ATHandler_stub {
|
|||
extern nsapi_error_t nsapi_error_value;
|
||||
extern uint8_t nsapi_error_ok_counter;
|
||||
extern int int_value;
|
||||
extern int ref_count;
|
||||
extern int timeout;
|
||||
extern bool default_timeout;
|
||||
extern bool debug_on;
|
||||
extern ssize_t ssize_value;
|
||||
extern char* read_string_value;
|
||||
extern size_t size_value;
|
||||
|
|
Loading…
Reference in New Issue