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