mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
c98c52ffb8
* Cleaned up dependencies on controller manager * Removed global fields * Simplified setting up RascsiResponse and RascsiExecutor * Got rid of remaining raw pointers * Use references instead of pointers * Improved encapsulation
67 lines
2.4 KiB
C++
67 lines
2.4 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "mocks.h"
|
|
#include "devices/device_factory.h"
|
|
#include "controllers/controller_manager.h"
|
|
|
|
TEST(ControllerManagerTest, LifeCycle)
|
|
{
|
|
const int ID = 4;
|
|
const int LUN1 = 0;
|
|
const int LUN2 = 3;
|
|
|
|
auto bus = make_shared<MockBus>();
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
DeviceFactory device_factory;
|
|
|
|
auto device = device_factory.CreateDevice(SCHS, -1, "");
|
|
EXPECT_FALSE(controller_manager->AttachToScsiController(ID, device));
|
|
|
|
device = device_factory.CreateDevice(SCHS, LUN1, "");
|
|
EXPECT_TRUE(controller_manager->AttachToScsiController(ID, device));
|
|
auto controller = controller_manager->FindController(ID);
|
|
EXPECT_NE(nullptr, controller);
|
|
EXPECT_EQ(1, controller->GetLunCount());
|
|
EXPECT_NE(nullptr, controller_manager->IdentifyController(1 << ID));
|
|
EXPECT_EQ(nullptr, controller_manager->IdentifyController(0));
|
|
EXPECT_EQ(nullptr, controller_manager->FindController(0));
|
|
EXPECT_NE(nullptr, controller_manager->GetDeviceByIdAndLun(ID, LUN1));
|
|
EXPECT_EQ(nullptr, controller_manager->GetDeviceByIdAndLun(0, 0));
|
|
|
|
device = device_factory.CreateDevice(SCHS, LUN2, "");
|
|
EXPECT_TRUE(controller_manager->AttachToScsiController(ID, device));
|
|
controller = controller_manager->FindController(ID);
|
|
EXPECT_TRUE(controller_manager->DeleteController(controller));
|
|
EXPECT_EQ(nullptr, controller_manager->FindController(ID));
|
|
|
|
controller_manager->DeleteAllControllers();
|
|
EXPECT_EQ(nullptr, controller_manager->FindController(ID));
|
|
EXPECT_EQ(nullptr, controller_manager->GetDeviceByIdAndLun(ID, LUN1));
|
|
}
|
|
|
|
TEST(ControllerManagerTest, AttachToScsiController)
|
|
{
|
|
const int ID = 4;
|
|
const int LUN1 = 3;
|
|
const int LUN2 = 0;
|
|
|
|
auto bus = make_shared<MockBus>();
|
|
auto controller_manager = make_shared<ControllerManager>(*bus);
|
|
DeviceFactory device_factory;
|
|
|
|
auto device1 = device_factory.CreateDevice(SCHS, LUN1, "");
|
|
EXPECT_FALSE(controller_manager->AttachToScsiController(ID, device1)) << "LUN 0 is missing";
|
|
|
|
auto device2 = device_factory.CreateDevice(SCLP, LUN2, "");
|
|
EXPECT_TRUE(controller_manager->AttachToScsiController(ID, device2));
|
|
EXPECT_TRUE(controller_manager->AttachToScsiController(ID, device1));
|
|
EXPECT_FALSE(controller_manager->AttachToScsiController(ID, device1));
|
|
}
|