2022-10-04 15:23:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-04 15:23:42 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-04 15:23:42 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "shared/piscsi_exceptions.h"
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
using namespace scsi_defs;
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiExceptionsTest, IoException)
|
2022-10-04 15:23:42 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
throw io_exception("msg");
|
|
|
|
}
|
|
|
|
catch(const io_exception& e) {
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_STREQ("msg", e.what());
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiExceptionsTest, FileNotFoundException)
|
2022-10-04 15:23:42 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
throw file_not_found_exception("msg");
|
|
|
|
}
|
|
|
|
catch(const file_not_found_exception& e) {
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_STREQ("msg", e.what());
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiExceptionsTest, ScsiErrorException)
|
2022-10-04 15:23:42 +00:00
|
|
|
{
|
|
|
|
try {
|
2023-10-15 06:38:15 +00:00
|
|
|
throw scsi_exception(sense_key::unit_attention);
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
catch(const scsi_exception& e) {
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(sense_key::unit_attention, e.get_sense_key());
|
|
|
|
EXPECT_EQ(asc::no_additional_sense_information, e.get_asc());
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-10-15 06:38:15 +00:00
|
|
|
throw scsi_exception(sense_key::illegal_request, asc::lba_out_of_range);
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
catch(const scsi_exception& e) {
|
2023-10-15 06:38:15 +00:00
|
|
|
EXPECT_EQ(sense_key::illegal_request, e.get_sense_key());
|
|
|
|
EXPECT_EQ(asc::lba_out_of_range, e.get_asc());
|
2022-10-04 15:23:42 +00:00
|
|
|
}
|
|
|
|
}
|