diff --git a/cta.spec.in b/cta.spec.in index f60f7340ddb3732ed9302eee774ebb25aeba71d4..efddfa5141a22c4a8febca2a2a8b44dab7cbd1f2 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -238,6 +238,7 @@ Unit tests and system tests with virtual tape drives %{_libdir}/libctadaemonunittests.so* %{_libdir}/libctamediachangerunittests.so* %{_libdir}/libctamediachangeracsdaemonunittests.so* +%{_libdir}/libctamediachangeracsunittests.so* %{_bindir}/cta-systemTests %{_libdir}/libctadaemonunittests-multiprocess.so* %attr(0644,root,root) %{_datadir}/%{name}-%{ctaVersion}/unittest/*.suppr diff --git a/mediachanger/acs/AcsTest.cpp b/mediachanger/acs/AcsTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..718e13389aeb43e8fc3b7da6f79b2c794a1ac429 --- /dev/null +++ b/mediachanger/acs/AcsTest.cpp @@ -0,0 +1,104 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "common/exception/InvalidArgument.hpp" +#include "mediachanger/acs/Acs.hpp" + +#include <gtest/gtest.h> + +namespace unitTests { + +class cta_mediachanger_acs_AcsTest: public ::testing::Test { +protected: + + virtual void SetUp() { + } + + virtual void TearDown() { + } +}; + +/** + * Tests good day senario with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, goodDayStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2:3:4"); + const auto driveId = Acs::str2DriveId(str); + + ASSERT_EQ(1, driveId.panel_id.lsm_id.acs); + ASSERT_EQ(2, driveId.panel_id.lsm_id.lsm); + ASSERT_EQ(3, driveId.panel_id.panel); + ASSERT_EQ(4, driveId.drive); +} + +/** + * Tests too many components with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooManyComponentsStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2:3:4:5"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +/** + * Tests too few components with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooFewComponentsStr2DriveIdgoodDayStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2:3"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +/** + * Tests tool long component with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooLongAcsComponentStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1111:2:3:4"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +/** + * Tests tool long component with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooLongLsmComponentStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2222:3:4"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +/** + * Tests tool long component with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooLongPanComponentStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2:3333:4"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +/** + * Tests tool long component with Acs::strToDrveId. + */ +TEST_F(cta_mediachanger_acs_AcsTest, tooLongDrvComponentStr2DriveId) { + using namespace cta::mediachanger::acs; + const std::string str("1:2:3:4444"); + ASSERT_THROW(Acs::str2DriveId(str), cta::exception::InvalidArgument); +} + +} // namespace unitTests diff --git a/mediachanger/acs/CMakeLists.txt b/mediachanger/acs/CMakeLists.txt index 560f4b119f3237f5a40ccf0b93fc9725b2688a50..0563763b6ab5af86ffc5560bc03174148228bdb6 100644 --- a/mediachanger/acs/CMakeLists.txt +++ b/mediachanger/acs/CMakeLists.txt @@ -41,6 +41,27 @@ set_target_properties (cta-acs PROPERTIES COMPILE_FLAGS -I/usr/include/CDK COMPILE_DEFINITIONS LINUX) +################################################################################ +# Rules to build and install unit-tests +################################################################################ + +set(MEDIACHANGER_ACS_UNIT_TESTS_LIB_SRC_FILES + AcsTest.cpp) + +add_library (ctamediachangeracsunittests SHARED + ${MEDIACHANGER_ACS_UNIT_TESTS_LIB_SRC_FILES}) +set_property(TARGET ctamediachangeracsunittests PROPERTY SOVERSION "${CTA_SOVERSION}") +set_property(TARGET ctamediachangeracsunittests PROPERTY VERSION "${CTA_LIBVERSION}") + +target_link_libraries (ctamediachangeracsunittests + cta-acs) + +set_target_properties (ctamediachangeracsunittests PROPERTIES + COMPILE_FLAGS -I/usr/include/CDK + COMPILE_DEFINITIONS LINUX) + +install(TARGETS ctamediachangeracsunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) + ################################################################################ # Rules to build and install castor-tape-acs-dismount ################################################################################ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d118913deb4dc0f726fd93e0b244c7b46225543a..82bb8ab8b67eb50ff392254ed52451037258c2c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries(cta-unitTests ctadaemonunittests ctamediachangerunittests ctamediachangeracsdaemonunittests + ctamediachangeracsunittests ${GMOCK_LIB} gtest pthread)