Validate SCSI error codes (sense key, asc) in unit tests (issue #895) (#950)

This commit is contained in:
Uwe Seimet 2022-10-29 18:16:03 +02:00 committed by GitHub
parent f84a13b3e2
commit 9a4f433baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 259 additions and 116 deletions

View File

@ -110,10 +110,14 @@ TEST(AbstractControllerTest, ProcessPhase)
controller.ProcessPhase();
controller.SetPhase(BUS::phase_t::reselection);
EXPECT_THROW(controller.ProcessPhase(), scsi_exception);
EXPECT_THAT([&controller]() { controller.ProcessPhase(); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))));
controller.SetPhase(BUS::phase_t::reserved);
EXPECT_THROW(controller.ProcessPhase(), scsi_exception);
EXPECT_THAT([&controller]() { controller.ProcessPhase(); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))));
}
TEST(AbstractControllerTest, DeviceLunLifeCycle)

View File

@ -24,11 +24,7 @@ TEST(DiskTest, Dispatch)
controller.AddDevice(disk);
EXPECT_FALSE(disk->Dispatch(scsi_command::eCmdIcd));
disk->SetRemovable(true);
disk->MediumChanged();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_FALSE(disk->Dispatch(scsi_command::eCmdIcd)) << "Command is not supported by this class";
}
TEST(DiskTest, Rezero)
@ -38,7 +34,9 @@ TEST(DiskTest, Rezero)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdRezero), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdRezero); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "REZERO must fail because drive is not ready";
disk->SetReady(true);
@ -57,7 +55,10 @@ TEST(DiskTest, FormatUnit)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdFormat), scsi_exception);
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdFormat); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "FORMAT UNIT must fail because drive is not ready";
disk->SetReady(true);
@ -67,7 +68,9 @@ TEST(DiskTest, FormatUnit)
cmd[1] = 0x10;
cmd[4] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdFormat), scsi_exception);
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdFormat); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))));
}
TEST(DiskTest, ReassignBlocks)
@ -77,7 +80,9 @@ TEST(DiskTest, ReassignBlocks)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReassign), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReassign); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "REASSIGN must fail because drive is not ready";
disk->SetReady(true);
@ -96,17 +101,21 @@ TEST(DiskTest, Seek6)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdSeek6), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdSeek6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "SEEK(6) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdSeek6), scsi_exception)
// Block count
cmd[4] = 1;
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdSeek6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "SEEK(6) must fail because drive is not ready";
disk->SetReady(true);
// Block count
cmd[4] = 1;
EXPECT_CALL(controller, Status());
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdSeek6));
EXPECT_EQ(status::GOOD, controller.GetStatus());
@ -121,50 +130,43 @@ TEST(DiskTest, Seek10)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdSeek10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdSeek10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "SEEK(10) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdSeek10), scsi_exception)
// Block count
cmd[5] = 1;
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdSeek10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "SEEK(10) must fail because drive is not ready";
disk->SetReady(true);
// Block count
cmd[5] = 1;
EXPECT_CALL(controller, Status());
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdSeek10));
EXPECT_EQ(status::GOOD, controller.GetStatus());
}
TEST(DiskTest, ReadCapacity)
TEST(DiskTest, ReadCapacity10)
{
MockAbstractController controller(make_shared<MockBus>(), 0);
auto disk = make_shared<MockDisk>();
controller.AddDevice(disk);
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16), scsi_exception)
<< "Neithed READ CAPACITY(16) nor READ LONG(16)";
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "READ CAPACITY(10) must fail because drive is not ready";
// READ CAPACITY(16), not READ LONG(16)
cmd[1] = 0x10;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16), scsi_exception)
<< "READ CAPACITY(16) must fail because drive is not ready";
cmd[1] = 0x00;
disk->SetReady(true);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "READ CAPACITY(10) must fail because the medium has no capacity";
// READ CAPACITY(16), not READ LONG(16)
cmd[1] = 0x10;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16), scsi_exception)
<< "READ CAPACITY(16) must fail because the medium has no capacity";
cmd[1] = 0x00;
disk->SetBlockCount(0x12345678);
EXPECT_CALL(controller, DataIn());
@ -181,10 +183,38 @@ TEST(DiskTest, ReadCapacity)
EXPECT_EQ(0xff, controller.GetBuffer()[1]);
EXPECT_EQ(0xff, controller.GetBuffer()[2]);
EXPECT_EQ(0xff, controller.GetBuffer()[3]);
}
TEST(DiskTest, ReadCapacity16)
{
MockAbstractController controller(make_shared<MockBus>(), 0);
auto disk = make_shared<MockDisk>();
controller.AddDevice(disk);
vector<int>& cmd = controller.GetCmd();
cmd[1] = 0x00;
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Neither READ CAPACITY(16) nor READ LONG(16)";
disk->SetSectorSizeInBytes(1024);
// READ CAPACITY(16), not READ LONG(16)
cmd[1] = 0x10;
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "READ CAPACITY(16) must fail because drive is not ready";
disk->SetReady(true);
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "READ CAPACITY(16) must fail because the medium has no capacity";
disk->SetBlockCount(0x1234567887654321);
disk->SetSectorSizeInBytes(1024);
EXPECT_CALL(controller, DataIn());
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16));
EXPECT_EQ(0x12, controller.GetBuffer()[0]);
@ -208,7 +238,9 @@ TEST(DiskTest, Read6)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdRead6), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdRead6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "READ(6) must fail for a medium with 0 blocks";
// Further testing requires filesystem access
@ -221,7 +253,9 @@ TEST(DiskTest, Read10)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdRead10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdRead10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "READ(10) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
@ -239,7 +273,9 @@ TEST(DiskTest, Read16)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdRead16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdRead16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "READ(16) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
@ -257,7 +293,9 @@ TEST(DiskTest, Write6)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWrite6), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "WRIte(6) must fail for a medium with 0 blocks";
// Further testing requires filesystem access
@ -270,7 +308,9 @@ TEST(DiskTest, Write10)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWrite10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWrite10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "WRITE(10) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
@ -288,7 +328,9 @@ TEST(DiskTest, Write16)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWrite16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWrite16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "WRITE(16) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
@ -306,12 +348,14 @@ TEST(DiskTest, Verify10)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdVerify10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdVerify10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "VERIFY(10) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
EXPECT_CALL(controller, Status());
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdWrite10));
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdVerify10));
EXPECT_EQ(status::GOOD, controller.GetStatus());
// Further testing requires filesystem access
@ -324,12 +368,14 @@ TEST(DiskTest, Verify16)
controller.AddDevice(disk);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdVerify16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdVerify16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "VERIFY(16) must fail for a medium with 0 blocks";
disk->SetBlockCount(1);
EXPECT_CALL(controller, Status());
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdWrite16));
EXPECT_TRUE(disk->Dispatch(scsi_command::eCmdVerify16));
EXPECT_EQ(status::GOOD, controller.GetStatus());
// Further testing requires filesystem access
@ -349,12 +395,16 @@ TEST(DiskTest, ReadLong10)
EXPECT_EQ(status::GOOD, controller.GetStatus());
cmd[2] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadLong10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadLong10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "READ LONG(10) must fail because the capacity is exceeded";
cmd[2] = 0;
cmd[7] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadLong10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadLong10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "READ LONG(10) must fail because it currently only supports 0 bytes transfer length";
}
@ -370,7 +420,9 @@ TEST(DiskTest, ReadLong16)
// READ LONG(16), not READ CAPACITY(16)
cmd[1] = 0x11;
cmd[2] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "READ LONG(16) must fail because the capacity is exceeded";
cmd[2] = 0;
@ -379,7 +431,9 @@ TEST(DiskTest, ReadLong16)
EXPECT_EQ(status::GOOD, controller.GetStatus());
cmd[13] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdReadCapacity16_ReadLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "READ LONG(16) must fail because it currently only supports 0 bytes transfer length";
}
@ -397,12 +451,16 @@ TEST(DiskTest, WriteLong10)
EXPECT_EQ(status::GOOD, controller.GetStatus());
cmd[2] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWriteLong10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWriteLong10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "WRITE LONG(10) must fail because the capacity is exceeded";
cmd[2] = 0;
cmd[7] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWriteLong10), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWriteLong10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "WRITE LONG(10) must fail because it currently only supports 0 bytes transfer length";
}
@ -416,7 +474,9 @@ TEST(DiskTest, WriteLong16)
vector<int>& cmd = controller.GetCmd();
cmd[2] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWriteLong16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWriteLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LBA_OUT_OF_RANGE))))
<< "WRITE LONG(16) must fail because the capacity is exceeded";
cmd[2] = 0;
@ -425,7 +485,9 @@ TEST(DiskTest, WriteLong16)
EXPECT_EQ(status::GOOD, controller.GetStatus());
cmd[13] = 1;
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdWriteLong16), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdWriteLong16); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "WRITE LONG(16) must fail because it currently only supports 0 bytes transfer length";
}
@ -458,12 +520,16 @@ TEST(DiskTest, StartStopUnit)
disk->SetReady(false);
EXPECT_CALL(*disk, FlushCache).Times(0);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdStartStop), scsi_exception);
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdStartStop); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LOAD_OR_EJECT_FAILED))));
disk->SetReady(true);
disk->SetLocked(true);
EXPECT_CALL(*disk, FlushCache).Times(0);
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdStartStop), scsi_exception);
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdStartStop); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::LOAD_OR_EJECT_FAILED))));
// Start/Unload
cmd[4] = 0x01;
@ -488,7 +554,9 @@ TEST(DiskTest, PreventAllowMediumRemoval)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(disk->Dispatch(scsi_command::eCmdRemoval), scsi_exception)
EXPECT_THAT([&disk]() { disk->Dispatch(scsi_command::eCmdRemoval); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))))
<< "REMOVAL must fail because drive is not ready";
disk->SetReady(true);

View File

@ -69,7 +69,9 @@ TEST(HostServicesTest, StartStopUnit)
// START
cmd[4] = 0x01;
EXPECT_THROW(services->Dispatch(scsi_command::eCmdStartStop), scsi_exception);
EXPECT_THAT([&services]() { services->Dispatch(scsi_command::eCmdStartStop); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))));
}
TEST(HostServicesTest, ModeSense6)
@ -79,11 +81,15 @@ TEST(HostServicesTest, ModeSense6)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(services->Dispatch(scsi_command::eCmdModeSense6), scsi_exception)
EXPECT_THAT([&services]() { services->Dispatch(scsi_command::eCmdModeSense6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Unsupported mode page was returned";
cmd[2] = 0x20;
EXPECT_THROW(services->Dispatch(scsi_command::eCmdModeSense6), scsi_exception)
EXPECT_THAT([&services]() { services->Dispatch(scsi_command::eCmdModeSense6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Block descriptors are not supported";
cmd[1] = 0x08;
@ -116,11 +122,15 @@ TEST(HostServicesTest, ModeSense10)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(services->Dispatch(scsi_command::eCmdModeSense10), scsi_exception)
EXPECT_THAT([&services]() { services->Dispatch(scsi_command::eCmdModeSense10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Unsupported mode page was returned";
cmd[2] = 0x20;
EXPECT_THROW(services->Dispatch(scsi_command::eCmdModeSense10), scsi_exception)
EXPECT_THAT([&services]() { services->Dispatch(scsi_command::eCmdModeSense10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Block descriptors are not supported";
cmd[1] = 0x08;

View File

@ -125,7 +125,8 @@ class MockAbstractController : public AbstractController //NOSONAR Having many f
FRIEND_TEST(DiskTest, Write16);
FRIEND_TEST(DiskTest, Verify10);
FRIEND_TEST(DiskTest, Verify16);
FRIEND_TEST(DiskTest, ReadCapacity);
FRIEND_TEST(DiskTest, ReadCapacity10);
FRIEND_TEST(DiskTest, ReadCapacity16);
FRIEND_TEST(DiskTest, ReadLong10);
FRIEND_TEST(DiskTest, ReadLong16);
FRIEND_TEST(DiskTest, WriteLong10);
@ -180,6 +181,7 @@ public:
MOCK_METHOD(void, Execute, (), ());
using ScsiController::ScsiController;
explicit MockScsiController(shared_ptr<NiceMock<MockBus>> bus, int target_id) : ScsiController(bus, target_id) {}
explicit MockScsiController(shared_ptr<MockBus> bus, int target_id) : ScsiController(bus, target_id) {}
MockScsiController(shared_ptr<MockBus> bus) : ScsiController(bus, 0) {}
~MockScsiController() override = default;
@ -299,7 +301,8 @@ class MockDisk : public Disk
FRIEND_TEST(DiskTest, Write16);
FRIEND_TEST(DiskTest, Verify10);
FRIEND_TEST(DiskTest, Verify16);
FRIEND_TEST(DiskTest, ReadCapacity);
FRIEND_TEST(DiskTest, ReadCapacity10);
FRIEND_TEST(DiskTest, ReadCapacity16);
FRIEND_TEST(DiskTest, ReadLong10);
FRIEND_TEST(DiskTest, ReadLong16);
FRIEND_TEST(DiskTest, WriteLong10);

View File

@ -127,8 +127,10 @@ TEST(ModePageDeviceTest, ModeSelect6)
EXPECT_TRUE(device->Dispatch(scsi_command::eCmdModeSelect6));
cmd[1] = 0x01;
EXPECT_THROW(device->Dispatch(scsi_command::eCmdModeSelect6), scsi_exception)
<< "Saving parameters is not supported for most device types";
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdModeSelect6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Saving parameters is not supported by base class";
}
TEST(ModePageDeviceTest, ModeSelect10)
@ -144,6 +146,8 @@ TEST(ModePageDeviceTest, ModeSelect10)
EXPECT_TRUE(device->Dispatch(scsi_command::eCmdModeSelect10));
cmd[1] = 0x01;
EXPECT_THROW(device->Dispatch(scsi_command::eCmdModeSelect10), scsi_exception)
<< "Saving parameters is not supported for most device types";
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdModeSelect10); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Saving parameters is not supported for by base class";
}

View File

@ -141,25 +141,35 @@ TEST(PrimaryDeviceTest, TestUnitReady)
device->SetAttn(true);
device->SetReady(false);
EXPECT_CALL(controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdTestUnitReady); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::UNIT_ATTENTION),
Property(&scsi_exception::get_asc, asc::POWER_ON_OR_RESET))));
device->SetReset(false);
EXPECT_CALL(controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdTestUnitReady); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::UNIT_ATTENTION),
Property(&scsi_exception::get_asc, asc::NOT_READY_TO_READY_CHANGE))));
device->SetReset(true);
device->SetAttn(false);
EXPECT_CALL(controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdTestUnitReady); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::UNIT_ATTENTION),
Property(&scsi_exception::get_asc, asc::POWER_ON_OR_RESET))));
device->SetReset(false);
device->SetAttn(true);
EXPECT_CALL(controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdTestUnitReady); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::UNIT_ATTENTION),
Property(&scsi_exception::get_asc, asc::NOT_READY_TO_READY_CHANGE))));
device->SetAttn(false);
EXPECT_CALL(controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdTestUnitReady), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdTestUnitReady); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))));
device->SetReady(true);
EXPECT_CALL(controller, Status());
@ -212,11 +222,17 @@ TEST(PrimaryDeviceTest, Inquiry)
cmd[1] = 0x01;
EXPECT_CALL(*controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdInquiry), scsi_exception) << "EVPD bit is not supported";
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdInquiry); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "EVPD bit is not supported";
cmd[2] = 0x01;
EXPECT_CALL(*controller, DataIn()).Times(0);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdInquiry), scsi_exception) << "PAGE CODE field is not supported";
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdInquiry); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "PAGE CODE field is not supported";
cmd[1] = 0x00;
cmd[2] = 0x00;
@ -241,7 +257,9 @@ TEST(PrimaryDeviceTest, RequestSense)
cmd[4] = 255;
device->SetReady(false);
EXPECT_THROW(device->Dispatch(scsi_command::eCmdRequestSense), scsi_exception);
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdRequestSense); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))));
device->SetReady(true);
EXPECT_CALL(controller, DataIn());
@ -263,16 +281,22 @@ TEST(PrimaryDeviceTest, SendDiagnostic)
EXPECT_EQ(status::GOOD, controller.GetStatus());
cmd[1] = 0x10;
EXPECT_THROW(device->Dispatch(scsi_command::eCmdSendDiag), scsi_exception)
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdSendDiag); }, Throws<scsi_exception>(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";
cmd[1] = 0;
cmd[3] = 1;
EXPECT_THROW(device->Dispatch(scsi_command::eCmdSendDiag), scsi_exception)
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdSendDiag); }, Throws<scsi_exception>(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";
cmd[3] = 0;
cmd[4] = 1;
EXPECT_THROW(device->Dispatch(scsi_command::eCmdSendDiag), scsi_exception)
EXPECT_THAT([&device]() { device->Dispatch(scsi_command::eCmdSendDiag); }, Throws<scsi_exception>(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";
}
@ -319,7 +343,10 @@ TEST(PrimaryDeviceTest, ReportLuns)
EXPECT_EQ(LUN2, buffer[23]) << "Wrong LUN2 number";
cmd[2] = 0x01;
EXPECT_THROW(device1->Dispatch(scsi_command::eCmdReportLuns), scsi_exception) << "Only SELECT REPORT mode 0 is supported";
EXPECT_THAT([&device1]() { device1->Dispatch(scsi_command::eCmdReportLuns); }, Throws<scsi_exception>(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";
}
TEST(PrimaryDeviceTest, UnknownCommand)

View File

@ -18,7 +18,7 @@ TEST(ScsiControllerTest, GetInitiatorId)
{
const int ID = 2;
MockScsiController controller(make_shared<MockBus>());
MockScsiController controller(make_shared<NiceMock<MockBus>>());
controller.Process(ID);
EXPECT_EQ(ID, controller.GetInitiatorId());
@ -55,7 +55,7 @@ TEST(ScsiControllerTest, Process)
TEST(ScsiControllerTest, BusFree)
{
MockScsiController controller(make_shared<MockBus>());
MockScsiController controller(make_shared<NiceMock<MockBus>>());
controller.SetPhase(BUS::phase_t::busfree);
controller.BusFree();
@ -86,7 +86,7 @@ TEST(ScsiControllerTest, BusFree)
TEST(ScsiControllerTest, Selection)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::selection);
@ -99,6 +99,7 @@ TEST(ScsiControllerTest, Selection)
ON_CALL(*bus, GetSEL).WillByDefault(Return(true));
ON_CALL(*bus, GetBSY).WillByDefault(Return(false));
EXPECT_CALL(*bus, GetATN).Times(0);
EXPECT_CALL(controller, Status);
controller.Selection();
EXPECT_EQ(BUS::phase_t::selection, controller.GetPhase());
@ -141,10 +142,11 @@ TEST(ScsiControllerTest, Selection)
TEST(ScsiControllerTest, Command)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::command);
EXPECT_CALL(controller, Status);
controller.Command();
EXPECT_EQ(BUS::phase_t::command, controller.GetPhase());
@ -167,7 +169,7 @@ TEST(ScsiControllerTest, Command)
TEST(ScsiControllerTest, MsgIn)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::reserved);
@ -182,7 +184,7 @@ TEST(ScsiControllerTest, MsgIn)
TEST(ScsiControllerTest, MsgOut)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::reserved);
@ -197,7 +199,7 @@ TEST(ScsiControllerTest, MsgOut)
TEST(ScsiControllerTest, DataIn)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::reserved);
@ -217,7 +219,7 @@ TEST(ScsiControllerTest, DataIn)
TEST(ScsiControllerTest, DataOut)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
controller.SetPhase(BUS::phase_t::reserved);
@ -237,7 +239,7 @@ TEST(ScsiControllerTest, DataOut)
TEST(ScsiControllerTest, Error)
{
auto bus = make_shared<MockBus>();
auto bus = make_shared<NiceMock<MockBus>>();
MockScsiController controller(bus, 0);
ON_CALL(*bus, GetRST).WillByDefault(Return(true));
@ -280,7 +282,7 @@ TEST(ScsiControllerTest, Error)
TEST(ScsiControllerTest, RequestSense)
{
MockScsiController controller(make_shared<MockBus>());
MockScsiController controller(make_shared<NiceMock<MockBus>>());
auto device = make_shared<MockPrimaryDevice>(0);
controller.AddDevice(device);

View File

@ -22,16 +22,6 @@ TEST(ScsiDaynaportTest, Dispatch)
auto daynaport = CreateDevice(SCDP, controller);
EXPECT_FALSE(daynaport->Dispatch(scsi_command::eCmdIcd)) << "Command is not supported by this class";
// TODO Remove tests below as soon as Daynaport does not inherit from Disk anymore
EXPECT_FALSE(daynaport->Dispatch(scsi_command::eCmdModeSense6))
<< "Non-DaynaPort commands inherited from Disk must not be supported";
EXPECT_FALSE(daynaport->Dispatch(scsi_command::eCmdModeSelect6))
<< "Non-DaynaPort commands inherited from Disk must not be supported";
EXPECT_FALSE(daynaport->Dispatch(scsi_command::eCmdModeSense10))
<< "Non-DaynaPort commands inherited from Disk must not be supported";
EXPECT_FALSE(daynaport->Dispatch(scsi_command::eCmdModeSelect10))
<< "Non-DaynaPort commands inherited from Disk must not be supported";
}
TEST(ScsiDaynaportTest, TestUnitReady)
@ -78,7 +68,10 @@ TEST(ScsiDaynaportTest, Read6)
vector<int>& cmd = controller.GetCmd();
cmd[5] = 0xff;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdRead6), scsi_exception) << "Invalid data format";
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdRead6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Invalid data format";
}
TEST(ScsiDaynaportTest, Write6)
@ -89,17 +82,26 @@ TEST(ScsiDaynaportTest, Write6)
vector<int>& cmd = controller.GetCmd();
cmd[5] = 0x00;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdWrite6), scsi_exception) << "Invalid transfer length";
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Invalid transfer length";
cmd[3] = -1;
cmd[4] = -8;
cmd[5] = 0x80;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdWrite6), scsi_exception) << "Invalid transfer length";
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Invalid transfer length";
cmd[3] = 0;
cmd[4] = 0;
cmd[5] = 0xff;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdWrite6), scsi_exception) << "Invalid transfer length";
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdWrite6); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Invalid transfer length";
}
TEST(ScsiDaynaportTest, TestRetrieveStats)
@ -123,7 +125,9 @@ TEST(ScsiDaynaportTest, SetInterfaceMode)
vector<int>& cmd = controller.GetCmd();
// Unknown interface command
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdSetIfaceMode), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_COMMAND_OPERATION_CODE))));
// Not implemented, do nothing
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_SETMODE;
@ -137,15 +141,21 @@ TEST(ScsiDaynaportTest, SetInterfaceMode)
// Not implemented
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_STATS;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdSetIfaceMode), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_COMMAND_OPERATION_CODE))));
// Not implemented
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_ENABLE;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdSetIfaceMode), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_COMMAND_OPERATION_CODE))));
// Not implemented
cmd[5] = SCSIDaynaPort::CMD_SCSILINK_SET;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdSetIfaceMode), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdSetIfaceMode); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_COMMAND_OPERATION_CODE))));
}
TEST(ScsiDaynaportTest, SetMcastAddr)
@ -155,7 +165,10 @@ TEST(ScsiDaynaportTest, SetMcastAddr)
vector<int>& cmd = controller.GetCmd();
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdSetMcastAddr), scsi_exception) << "Length of 0 is not supported";
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdSetMcastAddr); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Length of 0 is not supported";
cmd[4] = 1;
EXPECT_CALL(controller, DataOut());
@ -170,11 +183,15 @@ TEST(ScsiDaynaportTest, EnableInterface)
vector<int>& cmd = controller.GetCmd();
// Enable
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdEnableInterface), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))));
// Disable
cmd[5] = 0x80;
EXPECT_THROW(daynaport->Dispatch(scsi_command::eCmdEnableInterface), scsi_exception);
EXPECT_THAT([&daynaport]() { daynaport->Dispatch(scsi_command::eCmdEnableInterface); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))));
}
TEST(ScsiDaynaportTest, GetSendDelay)

View File

@ -91,7 +91,10 @@ TEST(ScsiPrinterTest, Print)
cmd[3] = 0xff;
cmd[4] = 0xff;
EXPECT_THROW(printer->Dispatch(scsi_command::eCmdPrint), scsi_exception) << "Buffer overflow was not reported";
EXPECT_THAT([&printer]() { printer->Dispatch(scsi_command::eCmdPrint); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ILLEGAL_REQUEST),
Property(&scsi_exception::get_asc, asc::INVALID_FIELD_IN_CDB))))
<< "Buffer overflow was not reported";
}
TEST(ScsiPrinterTest, StopPrint)
@ -109,7 +112,10 @@ TEST(ScsiPrinterTest, SynchronizeBuffer)
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
auto printer = CreateDevice(SCLP, controller);
EXPECT_THROW(printer->Dispatch(scsi_command::eCmdSynchronizeBuffer), scsi_exception) << "Nothing to print";
EXPECT_THAT([&printer]() { printer->Dispatch(scsi_command::eCmdSynchronizeBuffer); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))))
<< "Nothing to print";
// Further testing would use the printing system
}

View File

@ -123,7 +123,9 @@ TEST(ScsiCdTest, ReadToc)
controller.AddDevice(cd);
EXPECT_THROW(cd->Dispatch(scsi_command::eCmdReadToc), scsi_exception) << "Drive is not ready";
EXPECT_THAT([&cd]() { cd->Dispatch(scsi_command::eCmdReadToc); }, Throws<scsi_exception>(AllOf(
Property(&scsi_exception::get_sense_key, sense_key::NOT_READY),
Property(&scsi_exception::get_asc, asc::MEDIUM_NOT_PRESENT))));
// Further testing requires filesystem access
}