Skip to content
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

Bug/6 close serial #12

Merged
merged 2 commits into from
Jan 16, 2018
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
1 change: 1 addition & 0 deletions utils/cpp/include/Comm/Serial/Port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Comm{
class Comm::Serial::Port : public Comm::BinaryPort{
public:
Port(std::string portName, unsigned int speed);
~Port();
void connect();
void disconnect();
bool isConnected();
Expand Down
4 changes: 4 additions & 0 deletions utils/cpp/src/Comm/Serial/Port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Comm::Serial::Port::Port(std::string portName, unsigned int speed)
this->lock();
}

Comm::Serial::Port::~Port(){
this->disconnect();
}

bool Comm::Serial::Port::isConnected(){
return this->connected;
}
Expand Down
23 changes: 23 additions & 0 deletions utils/cpp/src/Comm/Serial/Port.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ TEST_CASE("can connect to port", "[Serial][.]"){
serial.disconnect();
}

TEST_CASE("can disconnect and reconnect to port", "[Serial][.]"){
Comm::Serial::Port serial(TEST_PORT_1, B9600);
serial.connect();
REQUIRE( serial.isConnected() );
serial.disconnect();
Comm::Serial::Port serial2(TEST_PORT_1, B9600);
serial2.connect();
REQUIRE( serial2.isConnected() );
serial2.disconnect();
}

TEST_CASE("disconnects when leaving scope", "[Serial][.]"){
{
Comm::Serial::Port serial(TEST_PORT_1, B9600);
serial.connect();
REQUIRE( serial.isConnected() );
}
Comm::Serial::Port serial2(TEST_PORT_1, B9600);
serial2.connect();
REQUIRE( serial2.isConnected() );
serial2.disconnect();
}

TEST_CASE("can't connect to non-existent port", "[Serial][.]"){
Comm::Serial::Port serial(ERROR_TEST_PORT, B9600);
serial.connect();
Expand Down