2022-10-23 19:51:39 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-23 19:51:39 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "mocks.h"
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/protobuf_util.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "generated/piscsi_interface.pb.h"
|
|
|
|
#include "piscsi/piscsi_image.h"
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
using namespace piscsi_interface;
|
2022-10-23 19:51:39 +00:00
|
|
|
using namespace protobuf_util;
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, SetGetDepth)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
image.SetDepth(1);
|
|
|
|
EXPECT_EQ(1, image.GetDepth());
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, SetGetDefaultFolder)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
EXPECT_NE(string::npos, image.GetDefaultFolder().find("/images"));
|
|
|
|
|
|
|
|
EXPECT_TRUE(!image.SetDefaultFolder("").empty());
|
|
|
|
EXPECT_TRUE(!image.SetDefaultFolder("/not_in_home").empty());
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, CreateImage)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
|
|
|
MockCommandContext context;
|
|
|
|
PbCommand command;
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-03-28 08:21:36 +00:00
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(image.CreateImage(context, command)) << "Filename must be reported as missing";
|
|
|
|
|
|
|
|
SetParam(command, "file", "/a/b/c/filename");
|
|
|
|
EXPECT_FALSE(image.CreateImage(context, command)) << "Depth must be reported as invalid";
|
|
|
|
|
|
|
|
SetParam(command, "file", "filename");
|
|
|
|
SetParam(command, "size", "-1");
|
|
|
|
EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as invalid";
|
|
|
|
|
|
|
|
SetParam(command, "size", "1");
|
|
|
|
EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as invalid";
|
|
|
|
|
|
|
|
SetParam(command, "size", "513");
|
2022-10-25 08:29:57 +00:00
|
|
|
EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as not a multiple of 512";
|
2022-10-23 19:51:39 +00:00
|
|
|
|
|
|
|
// Further tests would modify the filesystem
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, DeleteImage)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
|
|
|
MockCommandContext context;
|
|
|
|
PbCommand command;
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-03-28 08:21:36 +00:00
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(image.DeleteImage(context, command)) << "Filename must be reported as missing";
|
|
|
|
|
|
|
|
SetParam(command, "file", "/a/b/c/filename");
|
|
|
|
EXPECT_FALSE(image.DeleteImage(context, command)) << "Depth must be reported as invalid";
|
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
MockStorageDevice device;
|
|
|
|
device.ReserveFile("filename", 0, 0);
|
|
|
|
SetParam(command, "file", "filename");
|
|
|
|
EXPECT_FALSE(image.DeleteImage(context, command)) << "File must be reported as in use";
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
// Further testing would modify the filesystem
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, RenameImage)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
|
|
|
MockCommandContext context;
|
|
|
|
PbCommand command;
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-03-28 08:21:36 +00:00
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(image.RenameImage(context, command)) << "Source filename must be reported as missing";
|
|
|
|
|
|
|
|
SetParam(command, "from", "/a/b/c/filename_from");
|
|
|
|
EXPECT_FALSE(image.RenameImage(context, command)) << "Depth must be reported as invalid";
|
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
SetParam(command, "from", "filename_from");
|
|
|
|
EXPECT_FALSE(image.RenameImage(context, command)) << "Source file must be reported as missing";
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
// Further testing would modify the filesystem
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, CopyImage)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
|
|
|
MockCommandContext context;
|
|
|
|
PbCommand command;
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-03-28 08:21:36 +00:00
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(image.CopyImage(context, command)) << "Source filename must be reported as missing";
|
|
|
|
|
|
|
|
SetParam(command, "from", "/a/b/c/filename_from");
|
|
|
|
EXPECT_FALSE(image.CopyImage(context, command)) << "Depth must be reported as invalid";
|
|
|
|
|
2022-10-25 08:29:57 +00:00
|
|
|
SetParam(command, "from", "filename_from");
|
|
|
|
EXPECT_FALSE(image.CopyImage(context, command)) << "Source file must be reported as missing";
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
// Further testing would modify the filesystem
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
TEST(PiscsiImageTest, SetImagePermissions)
|
2022-10-23 19:51:39 +00:00
|
|
|
{
|
|
|
|
MockCommandContext context;
|
|
|
|
PbCommand command;
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiImage image;
|
2022-10-23 19:51:39 +00:00
|
|
|
|
2023-03-28 08:21:36 +00:00
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
EXPECT_FALSE(image.SetImagePermissions(context, command)) << "Filename must be reported as missing";
|
|
|
|
|
|
|
|
SetParam(command, "file", "/a/b/c/filename");
|
|
|
|
EXPECT_FALSE(image.SetImagePermissions(context, command)) << "Depth must be reported as invalid";
|
|
|
|
|
|
|
|
SetParam(command, "file", "filename");
|
|
|
|
EXPECT_FALSE(image.CopyImage(context, command)) << "Source file must be reported as missing";
|
|
|
|
|
|
|
|
// Further testing would modify the filesystem
|
|
|
|
}
|