Skip to content
Snippets Groups Projects
Commit 00590f98 authored by Steven Murray's avatar Steven Murray
Browse files

AcsCmdLine::str2DriveId now throws InvalidDriveId instead of InvalidArgument

parent 8410bdba
No related branches found
No related tags found
No related merge requests found
......@@ -46,8 +46,7 @@ DRIVEID cta::mediachanger::acs::AcsCmdLine::str2DriveId(const std::string &str)
// The drive ID should consist of 4 components: ACS, LSM, Panel and Transport
if(4 != components.size()) {
//cta::exception::InvalidArgument ex;
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Invalid number of components in drive ID"
": expected=4, actual=" << components.size();
throw ex;
......@@ -60,25 +59,25 @@ DRIVEID cta::mediachanger::acs::AcsCmdLine::str2DriveId(const std::string &str)
// Each of the 4 components must be between 1 and than 3 characters long
if(1 > acsStr.length() || 3 < acsStr.length()) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Invalid ACS string length"
": expected=1..3, actual=" << acsStr.length();
throw ex;
}
if(1 > lsmStr.length() || 3 < lsmStr.length()) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Invalid LSM string length"
": expected=1..3, actual=" << lsmStr.length();
throw ex;
}
if(1 > panStr.length() || 3 < panStr.length()) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Invalid panel string length"
": expected=1..3, actual=" << panStr.length();
throw ex;
}
if(1 > drvStr.length() || 3 < drvStr.length()) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Invalid drive string length"
": expected=1..3, actual=" << drvStr.length();
throw ex;
......@@ -86,22 +85,22 @@ DRIVEID cta::mediachanger::acs::AcsCmdLine::str2DriveId(const std::string &str)
// Each of the 4 components must only contain numerals
if(!onlyContainsNumerals(acsStr)) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "ACS must only contain numerals: value=" << acsStr;
throw ex;
}
if(!onlyContainsNumerals(lsmStr)) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "LSM must only contain numerals: value=" << acsStr;
throw ex;
}
if(!onlyContainsNumerals(panStr)) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Panel must only contain numerals: value=" << acsStr;
throw ex;
}
if(!onlyContainsNumerals(drvStr)) {
cta::exception::InvalidArgument ex;
InvalidDriveId ex;
ex.getMessage() << "Drive/Transport must only contain numerals: value=" <<
acsStr;
throw ex;
......
......@@ -18,6 +18,8 @@
#pragma once
#include "common/exception/Exception.hpp"
extern "C" {
#include "acssys.h"
#include "acsapi.h"
......@@ -36,14 +38,20 @@ namespace acs {
class AcsCmdLine {
public:
/**
* Invalid drive identifier.
*/
struct InvalidDriveId: public exception::Exception {
InvalidDriveId(const std::string &context = "", const bool embedBacktrace = true):
cta::exception::Exception(context, embedBacktrace) {}
};
/**
* Parses the specified string and returns the corresponding drive ID object.
*
* This method throws a cta::exception::InvalidArgument if the syntax of
* the string is invalid.
*
* @param str The string to be parsed.
* @return The drive ID object.
* @throw InvalidDriveId if the syntax of the string is invalid.
*/
static DRIVEID str2DriveId(const std::string &str);
......
......@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/InvalidArgument.hpp"
#include "mediachanger/acs/AcsCmdLine.hpp"
#include <gtest/gtest.h>
......@@ -53,7 +52,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, goodDayStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooManyComponentsStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2:3:4:5");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -62,7 +61,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooManyComponentsStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooFewComponentsStr2DriveIdgoodDayStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2:3");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -71,7 +70,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooFewComponentsStr2DriveIdgoodDaySt
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongAcsComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1111:2:3:4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -80,7 +79,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongAcsComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongLsmComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2222:3:4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -89,7 +88,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongLsmComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongPanComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2:3333:4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -98,7 +97,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongPanComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongDrvComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2:3:4444");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -107,7 +106,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongDrvComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyAcsComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str(":2:3:4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -116,7 +115,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyAcsComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyLsmComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1::3:4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -125,7 +124,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyLsmComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyPanComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2::4");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
/**
......@@ -134,7 +133,7 @@ TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyPanComponentStr2DriveId) {
TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyDrvComponentStr2DriveId) {
using namespace cta::mediachanger::acs;
const std::string str("1:2:3:");
ASSERT_THROW(AcsCmdLine::str2DriveId(str), cta::exception::InvalidArgument);
ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId);
}
} // namespace unitTests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment