Commit 274542fe authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

CryptAuth: Make Connection::Status enum class.

For compiler protection in switch statements, etc.

R=khorimoto@chromium.org

Bug: none
Test: none
Change-Id: Icf86013c87d89b233d6bc27646bad8f79830af6e
Reviewed-on: https://chromium-review.googlesource.com/1043098
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555895}
parent eba6af48
...@@ -24,11 +24,11 @@ const char kEasyUnlockFeatureName[] = "easy_unlock"; ...@@ -24,11 +24,11 @@ const char kEasyUnlockFeatureName[] = "easy_unlock";
api::easy_unlock_private::ConnectionStatus ToApiConnectionStatus( api::easy_unlock_private::ConnectionStatus ToApiConnectionStatus(
Connection::Status status) { Connection::Status status) {
switch (status) { switch (status) {
case Connection::DISCONNECTED: case Connection::Status::DISCONNECTED:
return api::easy_unlock_private::CONNECTION_STATUS_DISCONNECTED; return api::easy_unlock_private::CONNECTION_STATUS_DISCONNECTED;
case Connection::IN_PROGRESS: case Connection::Status::IN_PROGRESS:
return api::easy_unlock_private::CONNECTION_STATUS_IN_PROGRESS; return api::easy_unlock_private::CONNECTION_STATUS_IN_PROGRESS;
case Connection::CONNECTED: case Connection::Status::CONNECTED:
return api::easy_unlock_private::CONNECTION_STATUS_CONNECTED; return api::easy_unlock_private::CONNECTION_STATUS_CONNECTED;
} }
return api::easy_unlock_private::CONNECTION_STATUS_NONE; return api::easy_unlock_private::CONNECTION_STATUS_NONE;
......
...@@ -251,7 +251,7 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged( ...@@ -251,7 +251,7 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged(
FROM_HERE, FROM_HERE,
base::BindOnce(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync, base::BindOnce(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} else if (old_status == cryptauth::Connection::IN_PROGRESS) { } else if (old_status == cryptauth::Connection::Status::IN_PROGRESS) {
PA_LOG(WARNING) << "Connection failed. Retrying."; PA_LOG(WARNING) << "Connection failed. Retrying.";
connection_->RemoveObserver(this); connection_->RemoveObserver(this);
connection_.reset(); connection_.reset();
......
...@@ -322,8 +322,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ...@@ -322,8 +322,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Creating a connection. // Creating a connection.
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_FALSE(last_found_connection_); EXPECT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS); connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED); connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
EXPECT_TRUE(last_found_connection_); EXPECT_TRUE(last_found_connection_);
} }
...@@ -341,7 +341,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ...@@ -341,7 +341,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Trying to create a connection. // Trying to create a connection.
connection_finder_.DeviceAdded(adapter_.get(), device_.get()); connection_finder_.DeviceAdded(adapter_.get(), device_.get());
ASSERT_FALSE(last_found_connection_); ASSERT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS); connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
// Preparing to restart the discovery session. // Preparing to restart the discovery session.
device::BluetoothAdapter::DiscoverySessionCallback discovery_callback; device::BluetoothAdapter::DiscoverySessionCallback discovery_callback;
...@@ -353,7 +353,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ...@@ -353,7 +353,7 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Connection fails. // Connection fails.
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
connection->SetStatus(cryptauth::Connection::DISCONNECTED); connection->SetStatus(cryptauth::Connection::Status::DISCONNECTED);
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
} }
...@@ -375,8 +375,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ...@@ -375,8 +375,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_FALSE(last_found_connection_); EXPECT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS); connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED); connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
} }
EXPECT_TRUE(last_found_connection_); EXPECT_TRUE(last_found_connection_);
...@@ -426,8 +426,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest, ...@@ -426,8 +426,8 @@ TEST_F(ProximityAuthBluetoothLowEnergyConnectionFinderTest,
// Completing the connection. // Completing the connection.
base::RunLoop run_loop; base::RunLoop run_loop;
ASSERT_FALSE(last_found_connection_); ASSERT_FALSE(last_found_connection_);
connection->SetStatus(cryptauth::Connection::IN_PROGRESS); connection->SetStatus(cryptauth::Connection::Status::IN_PROGRESS);
connection->SetStatus(cryptauth::Connection::CONNECTED); connection->SetStatus(cryptauth::Connection::Status::CONNECTED);
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
EXPECT_TRUE(last_found_connection_); EXPECT_TRUE(last_found_connection_);
} }
......
...@@ -271,7 +271,7 @@ void MessengerImpl::OnConnectionStatusChanged( ...@@ -271,7 +271,7 @@ void MessengerImpl::OnConnectionStatusChanged(
cryptauth::Connection::Status old_status, cryptauth::Connection::Status old_status,
cryptauth::Connection::Status new_status) { cryptauth::Connection::Status new_status) {
DCHECK_EQ(connection, connection_.get()); DCHECK_EQ(connection, connection_.get());
if (new_status == cryptauth::Connection::DISCONNECTED) { if (new_status == cryptauth::Connection::Status::DISCONNECTED) {
PA_LOG(INFO) << "Secure channel disconnected..."; PA_LOG(INFO) << "Secure channel disconnected...";
connection_->RemoveObserver(this); connection_->RemoveObserver(this);
for (auto& observer : observers_) for (auto& observer : observers_)
......
...@@ -405,7 +405,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -405,7 +405,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
mock_bluetooth_device_.get(), should_set_low_connection_latency)); mock_bluetooth_device_.get(), should_set_low_connection_latency));
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
// Add the mock observer to observe on OnDidMessageSend. // Add the mock observer to observe on OnDidMessageSend.
connection_observer_ = connection_observer_ =
...@@ -445,14 +445,14 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -445,14 +445,14 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
// Handle setting the connection latency. // Handle setting the connection latency.
EXPECT_EQ(connection->sub_status(), EXPECT_EQ(connection->sub_status(),
SubStatus::WAITING_CONNECTION_LATENCY); SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null()); ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null()); ASSERT_FALSE(connection_latency_error_callback_.is_null());
connection_latency_callback_.Run(); connection_latency_callback_.Run();
} }
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Preparing |connection| to run |create_gatt_connection_success_callback_|. // Preparing |connection| to run |create_gatt_connection_success_callback_|.
EXPECT_FALSE(create_gatt_connection_error_callback_.is_null()); EXPECT_FALSE(create_gatt_connection_error_callback_.is_null());
...@@ -468,7 +468,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -468,7 +468,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
adapter_, kTestRemoteDeviceBluetoothAddress)); adapter_, kTestRemoteDeviceBluetoothAddress));
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
} }
// Transitions |connection| from WAITING_CHARACTERISTICS to // Transitions |connection| from WAITING_CHARACTERISTICS to
...@@ -487,7 +487,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -487,7 +487,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
{rx_characteristic_uuid_, kRXCharacteristicID}); {rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
} }
// Transitions |connection| from WAITING_NOTIFY_SESSION to // Transitions |connection| from WAITING_NOTIFY_SESSION to
...@@ -516,7 +516,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -516,7 +516,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
EXPECT_EQ(last_value_written_on_tx_characteristic_, kConnectionRequest); EXPECT_EQ(last_value_written_on_tx_characteristic_, kConnectionRequest);
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_RESPONSE); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_RESPONSE);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
} }
// Transitions |connection| from WAITING_CONNECTION_RESPONSE to CONNECTED. // Transitions |connection| from WAITING_CONNECTION_RESPONSE to CONNECTED.
...@@ -547,7 +547,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -547,7 +547,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
} }
EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_IDLE); EXPECT_EQ(connection->sub_status(), SubStatus::CONNECTED_AND_IDLE);
EXPECT_EQ(connection->status(), Connection::CONNECTED); EXPECT_EQ(connection->status(), Connection::Status::CONNECTED);
} }
// Transitions |connection| to a DISCONNECTED state regardless of its initial // Transitions |connection| to a DISCONNECTED state regardless of its initial
...@@ -570,7 +570,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest ...@@ -570,7 +570,7 @@ class CryptAuthBluetoothLowEnergyWeaveClientConnectionTest
} }
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
} }
void DeleteConnectionWithoutCallingDisconnect( void DeleteConnectionWithoutCallingDisconnect(
...@@ -775,7 +775,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -775,7 +775,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback(); RunWriteCharacteristicSuccessCallback();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
BLE_WEAVE_CONNECTION_RESULT_CLOSED_NORMALLY); BLE_WEAVE_CONNECTION_RESULT_CLOSED_NORMALLY);
...@@ -849,7 +849,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -849,7 +849,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
{rx_characteristic_uuid_, kRXCharacteristicID}); {rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent(); VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
...@@ -876,7 +876,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -876,7 +876,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
{rx_characteristic_uuid_, kRXCharacteristicID}); {rx_characteristic_uuid_, kRXCharacteristicID});
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent(); VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
...@@ -901,7 +901,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -901,7 +901,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
VerifyGattNotifySessionResult(false); VerifyGattNotifySessionResult(false);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -940,7 +940,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -940,7 +940,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
} }
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1112,7 +1112,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1112,7 +1112,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
} }
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1130,7 +1130,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1130,7 +1130,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(receiver_->GetReasonForClose(), ReasonForClose::UNKNOWN_ERROR); EXPECT_EQ(receiver_->GetReasonForClose(), ReasonForClose::UNKNOWN_ERROR);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1160,7 +1160,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1160,7 +1160,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback(); RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 2 /* num_writes */); VerifyGattWriteCharacteristicResult(true /* success */, 2 /* num_writes */);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1204,7 +1204,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1204,7 +1204,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
RunWriteCharacteristicSuccessCallback(); RunWriteCharacteristicSuccessCallback();
VerifyGattWriteCharacteristicResult(true /* success */, 3 /* num_writes */); VerifyGattWriteCharacteristicResult(true /* success */, 3 /* num_writes */);
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1320,7 +1320,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1320,7 +1320,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
} }
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1344,7 +1344,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1344,7 +1344,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// No GATT connection should be created before the delay. // No GATT connection should be created before the delay.
connection->Connect(); connection->Connect();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
EXPECT_TRUE(create_gatt_connection_error_callback_.is_null()); EXPECT_TRUE(create_gatt_connection_error_callback_.is_null());
EXPECT_TRUE(create_gatt_connection_success_callback_.is_null()); EXPECT_TRUE(create_gatt_connection_success_callback_.is_null());
...@@ -1439,7 +1439,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1439,7 +1439,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// Call Connect(), which should set the connection latency. // Call Connect(), which should set the connection latency.
connection->Connect(); connection->Connect();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null()); ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null()); ASSERT_FALSE(connection_latency_error_callback_.is_null());
...@@ -1447,7 +1447,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1447,7 +1447,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1474,19 +1474,19 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1474,19 +1474,19 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
// Handle setting the connection latency. // Handle setting the connection latency.
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CONNECTION_LATENCY);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
ASSERT_FALSE(connection_latency_callback_.is_null()); ASSERT_FALSE(connection_latency_callback_.is_null());
ASSERT_FALSE(connection_latency_error_callback_.is_null()); ASSERT_FALSE(connection_latency_error_callback_.is_null());
connection_latency_callback_.Run(); connection_latency_callback_.Run();
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_GATT_CONNECTION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout. // Simulate a timeout.
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1499,13 +1499,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1499,13 +1499,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
CreateConnection(true /* should_set_low_connection_latency */)); CreateConnection(true /* should_set_low_connection_latency */));
ConnectGatt(connection.get()); ConnectGatt(connection.get());
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_CHARACTERISTICS);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout. // Simulate a timeout.
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyGattServicesUnavailableEventSent(); VerifyGattServicesUnavailableEventSent();
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
...@@ -1520,13 +1520,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1520,13 +1520,13 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
ConnectGatt(connection.get()); ConnectGatt(connection.get());
CharacteristicsFound(connection.get()); CharacteristicsFound(connection.get());
EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION); EXPECT_EQ(connection->sub_status(), SubStatus::WAITING_NOTIFY_SESSION);
EXPECT_EQ(connection->status(), Connection::IN_PROGRESS); EXPECT_EQ(connection->status(), Connection::Status::IN_PROGRESS);
// Simulate a timeout. // Simulate a timeout.
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1545,7 +1545,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1545,7 +1545,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
...@@ -1569,7 +1569,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest, ...@@ -1569,7 +1569,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
test_timer_->Fire(); test_timer_->Fire();
EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED); EXPECT_EQ(connection->sub_status(), SubStatus::DISCONNECTED);
EXPECT_EQ(connection->status(), Connection::DISCONNECTED); EXPECT_EQ(connection->status(), Connection::Status::DISCONNECTED);
VerifyBleWeaveConnectionResult( VerifyBleWeaveConnectionResult(
BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult:: BluetoothLowEnergyWeaveClientConnection::BleWeaveConnectionResult::
......
...@@ -16,13 +16,13 @@ namespace cryptauth { ...@@ -16,13 +16,13 @@ namespace cryptauth {
Connection::Connection(const RemoteDevice& remote_device) Connection::Connection(const RemoteDevice& remote_device)
: remote_device_(remote_device), : remote_device_(remote_device),
status_(DISCONNECTED), status_(Status::DISCONNECTED),
is_sending_message_(false) {} is_sending_message_(false) {}
Connection::~Connection() {} Connection::~Connection() {}
bool Connection::IsConnected() const { bool Connection::IsConnected() const {
return status_ == CONNECTED; return status_ == Status::CONNECTED;
} }
void Connection::SendMessage(std::unique_ptr<WireMessage> message) { void Connection::SendMessage(std::unique_ptr<WireMessage> message) {
......
...@@ -22,7 +22,7 @@ class WireMessage; ...@@ -22,7 +22,7 @@ class WireMessage;
// persistent bidirectional channel for sending and receiving wire messages. // persistent bidirectional channel for sending and receiving wire messages.
class Connection { class Connection {
public: public:
enum Status { enum class Status {
DISCONNECTED, DISCONNECTED,
IN_PROGRESS, IN_PROGRESS,
CONNECTED, CONNECTED,
......
...@@ -101,19 +101,19 @@ TEST(CryptAuthConnectionTest, IsConnected) { ...@@ -101,19 +101,19 @@ TEST(CryptAuthConnectionTest, IsConnected) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
EXPECT_FALSE(connection.IsConnected()); EXPECT_FALSE(connection.IsConnected());
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
EXPECT_TRUE(connection.IsConnected()); EXPECT_TRUE(connection.IsConnected());
connection.SetStatus(Connection::DISCONNECTED); connection.SetStatus(Connection::Status::DISCONNECTED);
EXPECT_FALSE(connection.IsConnected()); EXPECT_FALSE(connection.IsConnected());
connection.SetStatus(Connection::IN_PROGRESS); connection.SetStatus(Connection::Status::IN_PROGRESS);
EXPECT_FALSE(connection.IsConnected()); EXPECT_FALSE(connection.IsConnected());
} }
TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) { TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
connection.SetStatus(Connection::IN_PROGRESS); connection.SetStatus(Connection::Status::IN_PROGRESS);
EXPECT_CALL(connection, GetDeviceAddress()).Times(1); EXPECT_CALL(connection, GetDeviceAddress()).Times(1);
EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0); EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0);
...@@ -123,7 +123,7 @@ TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) { ...@@ -123,7 +123,7 @@ TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) {
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
SendMessage_FailsWhenAnotherMessageSendIsInProgress) { SendMessage_FailsWhenAnotherMessageSendIsInProgress) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>()); connection.SendMessage(std::unique_ptr<WireMessage>());
EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0); EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0);
...@@ -132,7 +132,7 @@ TEST(CryptAuthConnectionTest, ...@@ -132,7 +132,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) { TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
EXPECT_CALL(connection, SendMessageImplProxy(_)); EXPECT_CALL(connection, SendMessageImplProxy(_));
connection.SendMessage(std::unique_ptr<WireMessage>()); connection.SendMessage(std::unique_ptr<WireMessage>());
...@@ -141,7 +141,7 @@ TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) { ...@@ -141,7 +141,7 @@ TEST(CryptAuthConnectionTest, SendMessage_SucceedsWhenConnected) {
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
SendMessage_SucceedsAfterPreviousMessageSendCompletes) { SendMessage_SucceedsAfterPreviousMessageSendCompletes) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>()); connection.SendMessage(std::unique_ptr<WireMessage>());
connection.OnDidSendMessage(TestWireMessage(), true /* success */); connection.OnDidSendMessage(TestWireMessage(), true /* success */);
...@@ -151,33 +151,33 @@ TEST(CryptAuthConnectionTest, ...@@ -151,33 +151,33 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, SetStatus_NotifiesObserversOfStatusChange) { TEST(CryptAuthConnectionTest, SetStatus_NotifiesObserversOfStatusChange) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
EXPECT_EQ(Connection::DISCONNECTED, connection.status()); EXPECT_EQ(Connection::Status::DISCONNECTED, connection.status());
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
EXPECT_CALL(observer, EXPECT_CALL(observer, OnConnectionStatusChanged(
OnConnectionStatusChanged(&connection, Connection::DISCONNECTED, &connection, Connection::Status::DISCONNECTED,
Connection::CONNECTED)); Connection::Status::CONNECTED));
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
} }
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
SetStatus_DoesntNotifyObserversIfStatusUnchanged) { SetStatus_DoesntNotifyObserversIfStatusUnchanged) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
EXPECT_EQ(Connection::DISCONNECTED, connection.status()); EXPECT_EQ(Connection::Status::DISCONNECTED, connection.status());
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
EXPECT_CALL(observer, OnConnectionStatusChanged(_, _, _)).Times(0); EXPECT_CALL(observer, OnConnectionStatusChanged(_, _, _)).Times(0);
connection.SetStatus(Connection::DISCONNECTED); connection.SetStatus(Connection::Status::DISCONNECTED);
} }
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnDidSendMessage_NotifiesObserversIfMessageSendInProgress) { OnDidSendMessage_NotifiesObserversIfMessageSendInProgress) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
connection.SendMessage(std::unique_ptr<WireMessage>()); connection.SendMessage(std::unique_ptr<WireMessage>());
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
...@@ -190,7 +190,7 @@ TEST(CryptAuthConnectionTest, ...@@ -190,7 +190,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnDidSendMessage_DoesntNotifyObserversIfNoMessageSendInProgress) { OnDidSendMessage_DoesntNotifyObserversIfNoMessageSendInProgress) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
...@@ -202,7 +202,7 @@ TEST(CryptAuthConnectionTest, ...@@ -202,7 +202,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnBytesReceived_NotifiesObserversOnValidMessage) { OnBytesReceived_NotifiesObserversOnValidMessage) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
...@@ -217,7 +217,7 @@ TEST(CryptAuthConnectionTest, ...@@ -217,7 +217,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfNotConnected) { OnBytesReceived_DoesntNotifyObserversIfNotConnected) {
StrictMock<MockConnection> connection; StrictMock<MockConnection> connection;
connection.SetStatus(Connection::IN_PROGRESS); connection.SetStatus(Connection::Status::IN_PROGRESS);
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
...@@ -230,7 +230,7 @@ TEST(CryptAuthConnectionTest, ...@@ -230,7 +230,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfMessageIsIncomplete) { OnBytesReceived_DoesntNotifyObserversIfMessageIsIncomplete) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
...@@ -244,7 +244,7 @@ TEST(CryptAuthConnectionTest, ...@@ -244,7 +244,7 @@ TEST(CryptAuthConnectionTest,
TEST(CryptAuthConnectionTest, TEST(CryptAuthConnectionTest,
OnBytesReceived_DoesntNotifyObserversIfMessageIsInvalid) { OnBytesReceived_DoesntNotifyObserversIfMessageIsInvalid) {
NiceMock<MockConnection> connection; NiceMock<MockConnection> connection;
connection.SetStatus(Connection::CONNECTED); connection.SetStatus(Connection::Status::CONNECTED);
StrictMock<MockConnectionObserver> observer; StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer); connection.AddObserver(&observer);
......
...@@ -224,7 +224,7 @@ void DeviceToDeviceAuthenticator::OnConnectionStatusChanged( ...@@ -224,7 +224,7 @@ void DeviceToDeviceAuthenticator::OnConnectionStatusChanged(
Connection::Status old_status, Connection::Status old_status,
Connection::Status new_status) { Connection::Status new_status) {
// We do not expect the connection to drop during authentication. // We do not expect the connection to drop during authentication.
if (new_status == Connection::DISCONNECTED) { if (new_status == Connection::Status::DISCONNECTED) {
Fail("Disconnected while authentication is in progress", Fail("Disconnected while authentication is in progress",
Result::DISCONNECTED); Result::DISCONNECTED);
} }
......
...@@ -28,14 +28,14 @@ FakeConnection::~FakeConnection() { ...@@ -28,14 +28,14 @@ FakeConnection::~FakeConnection() {
void FakeConnection::Connect() { void FakeConnection::Connect() {
if (should_auto_connect_) { if (should_auto_connect_) {
SetStatus(CONNECTED); SetStatus(Status::CONNECTED);
} else { } else {
SetStatus(IN_PROGRESS); SetStatus(Status::IN_PROGRESS);
} }
} }
void FakeConnection::Disconnect() { void FakeConnection::Disconnect() {
SetStatus(DISCONNECTED); SetStatus(Status::DISCONNECTED);
} }
std::string FakeConnection::GetDeviceAddress() { std::string FakeConnection::GetDeviceAddress() {
...@@ -56,12 +56,12 @@ void FakeConnection::RemoveObserver(ConnectionObserver* observer) { ...@@ -56,12 +56,12 @@ void FakeConnection::RemoveObserver(ConnectionObserver* observer) {
void FakeConnection::CompleteInProgressConnection(bool success) { void FakeConnection::CompleteInProgressConnection(bool success) {
DCHECK(!should_auto_connect_); DCHECK(!should_auto_connect_);
DCHECK(status() == IN_PROGRESS); DCHECK(status() == Status::IN_PROGRESS);
if (success) { if (success) {
SetStatus(CONNECTED); SetStatus(Status::CONNECTED);
} else { } else {
SetStatus(DISCONNECTED); SetStatus(Status::DISCONNECTED);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment