Skip to content

ATHandler refactoring #12122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
EXPECT_EQ(at->get_ref_count(), 6);
delete dev2; // AT fh1 2 refs deleted -> ref count 3
EXPECT_EQ(at->get_ref_count(), 4);

AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
EXPECT_EQ(ATHandler_stub::ref_count, 4);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
Expand Down Expand Up @@ -272,20 +270,16 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);

ATHandler *at = dev->get_at_handler();
EXPECT_EQ(at->get_ref_count(), 1);
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);

CellularContext *ctx = dev->create_context(NULL);
delete dev;

dev = new AT_CellularDevice(&fh1);
at = dev->get_at_handler();
EXPECT_EQ(at->get_ref_count(), 1);
ctx = dev->create_context(NULL);
CellularContext *ctx1 = dev->create_context(&fh1);
EXPECT_EQ(at->get_ref_count(), 3);
CellularContext *ctx2 = dev->create_context(&fh1);
EXPECT_EQ(at->get_ref_count(), 4);

EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1);
Expand All @@ -296,20 +290,13 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
EXPECT_TRUE(xx);

dev->delete_context(ctx);
EXPECT_EQ(at->get_ref_count(), 3);
dev->delete_context(ctx1);
EXPECT_EQ(at->get_ref_count(), 2);
dev->delete_context(NULL);
EXPECT_EQ(at->get_ref_count(), 2);
dev->delete_context(ctx2);
EXPECT_EQ(at->get_ref_count(), 1);

ctx = dev->create_context(NULL);
EXPECT_EQ(at->get_ref_count(), 2);
ctx1 = dev->create_context(&fh1);
EXPECT_EQ(at->get_ref_count(), 3);
ctx2 = dev->create_context(&fh1);
EXPECT_EQ(at->get_ref_count(), 4);
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,18 @@ TEST_F(TestATHandler, test_ATHandler_list)
ATHandler::set_debug_list(false);

ATHandler *at1 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
EXPECT_TRUE(at1->get_ref_count() == 1);

ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(true);

EXPECT_TRUE(ATHandler::get_instance(NULL, que, 0, ",", 0, 0) == NULL);

ATHandler *at2 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
EXPECT_TRUE(at1->get_ref_count() == 2);
EXPECT_TRUE(at2->get_ref_count() == 2);

ATHandler::set_at_timeout_list(2000, true);
ATHandler::set_debug_list(false);

EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
EXPECT_TRUE(at2->get_ref_count() == 1);
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);

ATHandler::set_at_timeout_list(1000, false);
Expand Down Expand Up @@ -204,43 +200,6 @@ TEST_F(TestATHandler, test_ATHandler_get_last_device_error)
EXPECT_TRUE(0 == at.get_last_device_error().errCode);
}

TEST_F(TestATHandler, test_ATHandler_inc_ref_count)
{
EventQueue que;
FileHandle_stub fh1;

ATHandler at(&fh1, que, 0, ",");
at.inc_ref_count();
}

TEST_F(TestATHandler, test_ATHandler_dec_ref_count)
{
EventQueue que;
FileHandle_stub fh1;

ATHandler at(&fh1, que, 0, ",");
at.dec_ref_count();
}

TEST_F(TestATHandler, test_ATHandler_get_ref_count)
{
EventQueue que;
FileHandle_stub fh1;

ATHandler at(&fh1, que, 0, ",");
EXPECT_TRUE(1 == at.get_ref_count());

at.inc_ref_count();
EXPECT_TRUE(2 == at.get_ref_count());

at.inc_ref_count();
EXPECT_TRUE(3 == at.get_ref_count());

at.dec_ref_count();
at.dec_ref_count();
EXPECT_TRUE(1 == at.get_ref_count());
}

TEST_F(TestATHandler, test_ATHandler_set_at_timeout)
{
EventQueue que;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ set(unittest-includes ${unittest-includes}

# Source files
set(unittest-sources
../features/cellular/framework/AT/ATHandler.cpp
../features/cellular/framework/device/ATHandler.cpp
)

# Test files
set(unittest-test-sources
features/cellular/framework/AT/athandler/athandlertest.cpp
features/cellular/framework/device/athandler/athandlertest.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/us_ticker_stub.cpp
Expand Down
10 changes: 5 additions & 5 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ bool ATHandler::get_debug() const
return ATHandler_stub::debug_on;
}

void ATHandler::set_debug_list(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}

ATHandler::~ATHandler()
{
ATHandler_stub::urc_handlers.clear();
Expand Down Expand Up @@ -409,11 +414,6 @@ void ATHandler::set_at_timeout_list(uint32_t timeout_milliseconds, bool default_
ATHandler_stub::default_timeout = default_timeout;
}

void ATHandler::set_debug_list(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}

void ATHandler::set_send_delay(uint16_t send_delay)
{
}
Expand Down
Loading