mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-25 16:29:48 +00:00
* Added unit tests, add convenience methods, fixed SonarCloud issues * Replaced C-style arrays by C++ arrays * Replaced ASSERT * Constants cleanup * Include cleanup * Moved _LARGEFILE64_SOURCE to Makefile, so that os.h is not always needed * os.h cleanup * Fixed clang++ warnings * Split protobuf_util * Fixed SonarCloud issues * Removed duplicate code * DeviceFactory is not a singleton anymore * Replaced macros * Removed obsolete interface * Replaced DWORD * Improved locality of code * Removed duplicate code * Extracted CDTrack * Split disk_track_cache * Replaced localtime by localtime_r * Moved CTapDriver cleanup to destructor * Removed redunant struct keywords
62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "testing.h"
|
|
#include "rascsi_interface.pb.h"
|
|
#include "command_util.h"
|
|
|
|
using namespace rascsi_interface;
|
|
using namespace command_util;
|
|
|
|
void TestSpecialDevice(const string& name)
|
|
{
|
|
PbDeviceDefinition device;
|
|
ParseParameters(device, name);
|
|
EXPECT_EQ(name, GetParam(device, "file"));
|
|
EXPECT_EQ("", GetParam(device, "interfaces"));
|
|
}
|
|
|
|
TEST(CommandUtil, AddGetParam)
|
|
{
|
|
PbCommand command;
|
|
AddParam(command, "key", "value");
|
|
EXPECT_EQ("value", GetParam(command, "key"));
|
|
EXPECT_EQ("", GetParam(command, "xyz"));
|
|
|
|
PbDeviceDefinition definition;
|
|
AddParam(definition, "key", "value");
|
|
EXPECT_EQ("value", GetParam(definition, "key"));
|
|
EXPECT_EQ("", GetParam(definition, "xyz"));
|
|
|
|
PbDevice device;
|
|
AddParam(device, "key", "value");
|
|
const auto& it = device.params().find("key");
|
|
EXPECT_EQ("value", it->second);
|
|
}
|
|
|
|
TEST(CommandUtil, ParseParameters)
|
|
{
|
|
PbDeviceDefinition device1;
|
|
ParseParameters(device1, "a=b:c=d:e");
|
|
EXPECT_EQ("b", GetParam(device1, "a"));
|
|
EXPECT_EQ("d", GetParam(device1, "c"));
|
|
EXPECT_EQ("", GetParam(device1, "e"));
|
|
|
|
// Old style parameters
|
|
PbDeviceDefinition device2;
|
|
ParseParameters(device2, "a");
|
|
EXPECT_EQ("a", GetParam(device2, "file"));
|
|
EXPECT_EQ("a", GetParam(device2, "interfaces"));
|
|
|
|
TestSpecialDevice("bridge");
|
|
TestSpecialDevice("daynaport");
|
|
TestSpecialDevice("printer");
|
|
TestSpecialDevice("services");
|
|
}
|