diff --git a/mediachanger/acs/AcsCmdLine.cpp b/mediachanger/acs/AcsCmdLine.cpp index 30cd7faef8b717f8dccebd8a969a16a78c0081aa..982820a62ce70f6b829c9f1ec0649992a5a95d6b 100644 --- a/mediachanger/acs/AcsCmdLine.cpp +++ b/mediachanger/acs/AcsCmdLine.cpp @@ -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; diff --git a/mediachanger/acs/AcsCmdLine.hpp b/mediachanger/acs/AcsCmdLine.hpp index d76ac0f6c16df76cde0f50b66f5c838e474014cf..8d88a1899a13778515b67fa25d8344bdd11d1e34 100644 --- a/mediachanger/acs/AcsCmdLine.hpp +++ b/mediachanger/acs/AcsCmdLine.hpp @@ -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); diff --git a/mediachanger/acs/AcsCmdLineTest.cpp b/mediachanger/acs/AcsCmdLineTest.cpp index 4180415442e3ed52517aef689cdbe5454323b574..8a1e50061df469edf15a088aacbd38165126aed8 100644 --- a/mediachanger/acs/AcsCmdLineTest.cpp +++ b/mediachanger/acs/AcsCmdLineTest.cpp @@ -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