2022-10-08 17:26:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
|
|
|
#include "rascsi_exceptions.h"
|
|
|
|
#include "controllers/controller_manager.h"
|
|
|
|
#include "devices/scsi_printer.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiPrinterTest, Init)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-23 19:51:39 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
|
|
|
unordered_map<string, string> params;
|
|
|
|
EXPECT_TRUE(printer->Init(params));
|
|
|
|
|
|
|
|
params["cmd"] = "missing_filename_specifier";
|
|
|
|
EXPECT_FALSE(printer->Init(params));
|
|
|
|
|
|
|
|
params["cmd"] = "%f";
|
|
|
|
EXPECT_TRUE(printer->Init(params));
|
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
TEST(ScsiPrinterTest, TestUnitReady)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-08 17:26:04 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_CALL(controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdTestUnitReady);
|
2022-10-08 17:26:04 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller.GetStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, Inquiry)
|
|
|
|
{
|
2022-10-23 19:51:39 +00:00
|
|
|
TestInquiry(SCLP, device_type::PRINTER, scsi_level::SCSI_2, "RaSCSI SCSI PRINTER ", 0x1f, false);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, ReserveUnit)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-08 17:26:04 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
|
|
|
EXPECT_CALL(controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdReserve6);
|
2022-10-08 17:26:04 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller.GetStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, ReleaseUnit)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-08 17:26:04 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
|
|
|
EXPECT_CALL(controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdRelease6);
|
2022-10-08 17:26:04 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller.GetStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, SendDiagnostic)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-08 17:26:04 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
|
|
|
EXPECT_CALL(controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdSendDiagnostic);
|
2022-10-08 17:26:04 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller.GetStatus());
|
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiPrinterTest, Print)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-23 19:51:39 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
2022-11-02 14:36:19 +00:00
|
|
|
auto& cmd = controller.GetCmd();
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(controller, DataOut());
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdPrint);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
cmd[3] = 0xff;
|
|
|
|
cmd[4] = 0xff;
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { printer->Dispatch(scsi_command::eCmdPrint); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
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";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, StopPrint)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-08 17:26:04 +00:00
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_CALL(controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdStopPrint);
|
2022-10-08 17:26:04 +00:00
|
|
|
EXPECT_EQ(status::GOOD, controller.GetStatus());
|
|
|
|
}
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
TEST(ScsiPrinterTest, SynchronizeBuffer)
|
|
|
|
{
|
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
|
|
|
auto printer = CreateDevice(SCLP, controller);
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
EXPECT_THAT([&] { printer->Dispatch(scsi_command::eCmdSynchronizeBuffer); }, Throws<scsi_exception>(AllOf(
|
2022-10-29 16:16:03 +00:00
|
|
|
Property(&scsi_exception::get_sense_key, sense_key::ABORTED_COMMAND),
|
|
|
|
Property(&scsi_exception::get_asc, asc::NO_ADDITIONAL_SENSE_INFORMATION))))
|
|
|
|
<< "Nothing to print";
|
2022-10-25 08:29:57 +00:00
|
|
|
|
|
|
|
// Further testing would use the printing system
|
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiPrinterTest, WriteByteSequence)
|
|
|
|
{
|
2022-10-25 00:21:40 +00:00
|
|
|
NiceMock<MockAbstractController> controller(make_shared<MockBus>(), 0);
|
2022-10-23 19:51:39 +00:00
|
|
|
auto printer = dynamic_pointer_cast<SCSIPrinter>(CreateDevice(SCLP, controller));
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
vector<uint8_t> buf(1);
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_TRUE(printer->WriteByteSequence(buf, buf.size()));
|
|
|
|
}
|