diff --git a/cpp/test/primary_device_test.cpp b/cpp/test/primary_device_test.cpp index 5fd80fff..9abe5114 100644 --- a/cpp/test/primary_device_test.cpp +++ b/cpp/test/primary_device_test.cpp @@ -55,10 +55,10 @@ TEST(PrimaryDeviceTest, Reset) device->Dispatch(scsi_command::cmd_reserve6); EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for initiator ID 1"; + << "Device must be reserved for initiator ID 1"; device->Reset(); EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved anymore for initiator ID 1"; + << "Device must not be reserved anymore for initiator ID 1"; } TEST(PrimaryDeviceTest, CheckReservation) @@ -66,26 +66,26 @@ TEST(PrimaryDeviceTest, CheckReservation) auto [controller, device] = CreatePrimaryDevice(); EXPECT_TRUE(device->CheckReservation(0, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved for initiator ID 0"; + << "Device must not be reserved for initiator ID 0"; device->Dispatch(scsi_command::cmd_reserve6); EXPECT_TRUE(device->CheckReservation(0, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved for initiator ID 0"; + << "Device must not be reserved for initiator ID 0"; EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for initiator ID 1"; + << "Device must be reserved for initiator ID 1"; EXPECT_FALSE(device->CheckReservation(-1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for unknown initiator"; + << "Device must be reserved for unknown initiator"; EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_inquiry, false)) - << "Device must not be reserved for INQUIRY"; + << "Device must not be reserved for INQUIRY"; EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_request_sense, false)) - << "Device must not be reserved for REQUEST SENSE"; + << "Device must not be reserved for REQUEST SENSE"; EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_release6, false)) - << "Device must not be reserved for RELEASE (6)"; + << "Device must not be reserved for RELEASE (6)"; EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_prevent_allow_medium_removal, false)) - << "Device must not be reserved for PREVENT ALLOW MEDIUM REMOVAL with prevent bit not set"; + << "Device must not be reserved for PREVENT ALLOW MEDIUM REMOVAL with prevent bit not set"; EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_prevent_allow_medium_removal, true)) - << "Device must be reserved for PREVENT ALLOW MEDIUM REMOVAL with prevent bit set"; + << "Device must be reserved for PREVENT ALLOW MEDIUM REMOVAL with prevent bit set"; } TEST(PrimaryDeviceTest, ReserveReleaseUnit) @@ -94,20 +94,20 @@ TEST(PrimaryDeviceTest, ReserveReleaseUnit) device->Dispatch(scsi_command::cmd_reserve6); EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for initiator ID 1"; + << "Device must be reserved for initiator ID 1"; device->Dispatch(scsi_command::cmd_release6); EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved anymore for initiator ID 1"; + << "Device must not be reserved anymore for initiator ID 1"; ON_CALL(*controller, GetInitiatorId).WillByDefault(Return(-1)); device->Dispatch(scsi_command::cmd_reserve6); EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for unknown initiator"; + << "Device must be reserved for unknown initiator"; device->Dispatch(scsi_command::cmd_release6); EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved anymore for unknown initiator"; + << "Device must not be reserved anymore for unknown initiator"; } TEST(PrimaryDeviceTest, DiscardReservation) @@ -116,10 +116,10 @@ TEST(PrimaryDeviceTest, DiscardReservation) device->Dispatch(scsi_command::cmd_reserve6); EXPECT_FALSE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must be reserved for initiator ID 1"; + << "Device must be reserved for initiator ID 1"; device->DiscardReservation(); EXPECT_TRUE(device->CheckReservation(1, scsi_command::cmd_test_unit_ready, false)) - << "Device must not be reserved anymore for initiator ID 1"; + << "Device must not be reserved anymore for initiator ID 1"; } TEST(PrimaryDeviceTest, TestUnitReady) @@ -133,10 +133,10 @@ TEST(PrimaryDeviceTest, TestUnitReady) device->SetReady(false); EXPECT_CALL(*controller, DataIn).Times(0); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_test_unit_ready) - ; - }, + { + d->Dispatch(scsi_command::cmd_test_unit_ready) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::unit_attention), Property(&scsi_exception::get_asc, asc::power_on_or_reset)))); @@ -144,10 +144,10 @@ TEST(PrimaryDeviceTest, TestUnitReady) device->SetReset(false); EXPECT_CALL(*controller, DataIn).Times(0); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_test_unit_ready) - ; - }, + { + d->Dispatch(scsi_command::cmd_test_unit_ready) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::unit_attention), Property(&scsi_exception::get_asc, asc::not_ready_to_ready_change)))); @@ -156,10 +156,10 @@ TEST(PrimaryDeviceTest, TestUnitReady) device->SetAttn(false); EXPECT_CALL(*controller, DataIn).Times(0); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_test_unit_ready) - ; - }, + { + d->Dispatch(scsi_command::cmd_test_unit_ready) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::unit_attention), Property(&scsi_exception::get_asc, asc::power_on_or_reset)))); @@ -168,10 +168,10 @@ TEST(PrimaryDeviceTest, TestUnitReady) device->SetAttn(true); EXPECT_CALL(*controller, DataIn).Times(0); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_test_unit_ready) - ; - }, + { + d->Dispatch(scsi_command::cmd_test_unit_ready) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::unit_attention), Property(&scsi_exception::get_asc, asc::not_ready_to_ready_change)))); @@ -179,10 +179,10 @@ TEST(PrimaryDeviceTest, TestUnitReady) device->SetAttn(false); EXPECT_CALL(*controller, DataIn).Times(0); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_test_unit_ready) - ; - }, + { + d->Dispatch(scsi_command::cmd_test_unit_ready) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::not_ready), Property(&scsi_exception::get_asc, asc::medium_not_present)))); @@ -268,10 +268,10 @@ TEST(PrimaryDeviceTest, RequestSense) device->SetReady(false); EXPECT_THAT([&] - { - d->Dispatch(scsi_command::cmd_request_sense) - ; - }, + { + d->Dispatch(scsi_command::cmd_request_sense) + ; + }, Throws( AllOf(Property(&scsi_exception::get_sense_key, sense_key::not_ready), Property(&scsi_exception::get_asc, asc::medium_not_present)))); @@ -296,20 +296,20 @@ TEST(PrimaryDeviceTest, SendDiagnostic) EXPECT_THAT([&] {d->Dispatch(scsi_command::cmd_send_diagnostic);}, Throws(AllOf( Property(&scsi_exception::get_sense_key, sense_key::illegal_request), Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb)))) - << "SEND DIAGNOSTIC must fail because PF bit is not supported"; + << "SEND DIAGNOSTIC must fail because PF bit is not supported"; controller->SetCmdByte(1, 0); controller->SetCmdByte(3, 1); EXPECT_THAT([&] {d->Dispatch(scsi_command::cmd_send_diagnostic);}, Throws(AllOf( Property(&scsi_exception::get_sense_key, sense_key::illegal_request), Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb)))) - << "SEND DIAGNOSTIC must fail because parameter list is not supported"; + << "SEND DIAGNOSTIC must fail because parameter list is not supported"; controller->SetCmdByte(3, 0); controller->SetCmdByte(4, 1); EXPECT_THAT([&] {d->Dispatch(scsi_command::cmd_send_diagnostic);}, Throws(AllOf( Property(&scsi_exception::get_sense_key, sense_key::illegal_request), Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb)))) - << "SEND DIAGNOSTIC must fail because parameter list is not supported"; + << "SEND DIAGNOSTIC must fail because parameter list is not supported"; } TEST(PrimaryDeviceTest, ReportLuns) @@ -349,7 +349,7 @@ TEST(PrimaryDeviceTest, ReportLuns) EXPECT_THAT([&] {device1->Dispatch(scsi_command::cmd_reportLuns);}, Throws(AllOf( Property(&scsi_exception::get_sense_key, sense_key::illegal_request), Property(&scsi_exception::get_asc, asc::invalid_field_in_cdb)))) - << "Only SELECT REPORT mode 0 is supported"; + << "Only SELECT REPORT mode 0 is supported"; } TEST(PrimaryDeviceTest, Dispatch) @@ -373,3 +373,10 @@ TEST(PrimaryDeviceTest, Init) EXPECT_TRUE(device.Init(params)) << "Initialization of primary device must not fail"; } + +TEST(PrimaryDeviceTest, GetStatistics) +{ + MockPrimaryDevice device(0); + + EXPECT_TRUE(device.GetStatistics().empty()); +}