2022-10-08 17:26:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-08 17:26:04 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-08 17:26:04 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "shared/piscsi_exceptions.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include "devices/scsi_printer.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2023-10-30 10:24:18 +00:00
|
|
|
TEST(ScsiPrinterTest, GetDefaultParams)
|
|
|
|
{
|
|
|
|
const auto [controller, printer] = CreateDevice(SCLP);
|
|
|
|
const auto params = printer->GetDefaultParams();
|
|
|
|
EXPECT_EQ(1, params.size());
|
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiPrinterTest, Init)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
|
|
|
EXPECT_TRUE(printer->Init({}));
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
param_map params;
|
2022-10-23 19:51:39 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdTestUnitReady);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, Inquiry)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
TestInquiry::Inquiry(SCLP, device_type::printer, scsi_level::scsi_2, "PiSCSI SCSI PRINTER ", 0x1f, false);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, ReserveUnit)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdReserve6);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, ReleaseUnit)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdRelease6);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, SendDiagnostic)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status()).Times(1);
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdSendDiagnostic);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
TEST(ScsiPrinterTest, Print)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
|
|
|
// Required by the bullseye clang++ compiler
|
|
|
|
auto p = printer;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-11-04 07:22:32 +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
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
controller->SetCmdByte(3, 0xff);
|
|
|
|
controller->SetCmdByte(4, 0xff);
|
|
|
|
EXPECT_THAT([&] { p->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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "Buffer overflow was not reported";
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
TEST(ScsiPrinterTest, StopPrint)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
EXPECT_CALL(*controller, Status());
|
2022-11-02 14:36:19 +00:00
|
|
|
printer->Dispatch(scsi_command::eCmdStopPrint);
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(status::good, controller->GetStatus());
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
TEST(ScsiPrinterTest, SynchronizeBuffer)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
|
|
|
// Required by the bullseye clang++ compiler
|
|
|
|
auto p = printer;
|
|
|
|
|
|
|
|
EXPECT_THAT([&] { p->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))))
|
2022-10-29 16:16:03 +00:00
|
|
|
<< "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)
|
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
auto [controller, printer] = CreateDevice(SCLP);
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
const vector<uint8_t> buf(1);
|
|
|
|
EXPECT_TRUE(printer->WriteByteSequence(buf));
|
2022-10-23 19:51:39 +00:00
|
|
|
}
|