diff --git a/src/smartools.h b/src/smartools.h index 23af6e1aad8de47890e776d253a81630cb92e330..5ee4b813ec9027bf0b449405ba185fb8a13c3b2a 100644 --- a/src/smartools.h +++ b/src/smartools.h @@ -26,6 +26,11 @@ namespace ring { class Smartools { + // Use for the unit tests + #ifdef TESTING + friend class SmartoolsTest; + #endif + public: static Smartools& getInstance(); void start(std::chrono::milliseconds refreshTimeMs); diff --git a/test/.gitignore b/test/.gitignore index 8cbb7b54d92ee397e6e40fa62850db109733d940..c166fb3d8ffc09ce07dba3f691763f198147e541 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -9,4 +9,4 @@ test_* *.trs .dirstamp -dring-sample.yml.bak \ No newline at end of file +dring-sample.yml.bak diff --git a/test/sip/.gitignore b/test/sip/.gitignore index 508976e42163e5fee85a0b9c7e7b1627ada5f147..c28306c38ae53d7535d7e27647c0b092236f5f6b 100644 --- a/test/sip/.gitignore +++ b/test/sip/.gitignore @@ -1,4 +1,2 @@ #test binaries sip - -dring-sample.yml.bak diff --git a/test/unitTest/Makefile.am b/test/unitTest/Makefile.am index 0f39a2af2605df810c8a3cb35b77a2cefa624eb4..59851162c15c1b15aabdc8feda62a5d9ecb185b2 100644 --- a/test/unitTest/Makefile.am +++ b/test/unitTest/Makefile.am @@ -14,7 +14,13 @@ check_PROGRAMS += ut_base64 ut_base64_SOURCES = base64/base64.cpp # -# video_input testsuite +# smartools +# +check_PROGRAMS += ut_smartools +ut_smartools_SOURCES = smartools/testSmartools.cpp + +# +# video_input # check_PROGRAMS += ut_video_input ut_video_input_SOURCES = media/video/testVideo_input.cpp diff --git a/test/unitTest/smartools/testSmartools.cpp b/test/unitTest/smartools/testSmartools.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c870cdd916ca571652e0e7f6492a1eb1dbe6530 --- /dev/null +++ b/test/unitTest/smartools/testSmartools.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2017 Savoir-Faire Linux Inc. + * Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com> + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#define TESTING +#include "smartools.h" +#include "../../test_runner.h" + +namespace ring { +class SmartoolsTest : public CppUnit::TestFixture { +public: + static std::string name() { return "smartools"; } + +private: + void testSetLocalInformation(); + void testSetRemoteInformation(); + + CPPUNIT_TEST_SUITE(SmartoolsTest); + CPPUNIT_TEST(testSetLocalInformation); + CPPUNIT_TEST(testSetRemoteInformation); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SmartoolsTest, SmartoolsTest::name()); + +template <typename Map> +bool map_compare (Map const &lhs, Map const &rhs) { + return std::equal(lhs.begin(), lhs.end(), rhs.begin()); +} + +void +SmartoolsTest::testSetLocalInformation() +{ + std::map<std::string, std::string> localInformation; + + // initialisation localInformation + localInformation["local FPS"]= "32"; + localInformation["local width"]="326"; + localInformation["local height"] ="532"; + localInformation["remote audio codec"]= "remoteAudioCodec"; + localInformation["local audio codec"]= "localAudioCodec"; + localInformation["local video codec"]= "localVideoCodec"; + + Smartools::getInstance().setFrameRate("local", "32"); + Smartools::getInstance().setResolution("local", 326, 532); + Smartools::getInstance().setRemoteAudioCodec("remoteAudioCodec"); + Smartools::getInstance().setLocalAudioCodec("localAudioCodec"); + Smartools::getInstance().setLocalVideoCodec("localVideoCodec"); + + CPPUNIT_ASSERT(map_compare(localInformation, Smartools::getInstance().information_)); + + // Clear information_ + Smartools::getInstance().sendInfo(); + + CPPUNIT_ASSERT(Smartools::getInstance().information_.empty()); +} + +void +SmartoolsTest::testSetRemoteInformation() +{ + std::map<std::string, std::string> remoteInformation; + + // initialisation remoteInformation + remoteInformation["remote FPS"]= "42"; + remoteInformation["remote width"]="874"; + remoteInformation["remote height"] ="253"; + + Smartools::getInstance().setFrameRate("remote", "42"); + Smartools::getInstance().setResolution("remote", 874, 253); + + CPPUNIT_ASSERT(map_compare(remoteInformation, Smartools::getInstance().information_)); + + // Clear information_ + Smartools::getInstance().sendInfo(); + + CPPUNIT_ASSERT(Smartools::getInstance().information_.empty()); +} + +} // namespace ring + +RING_TEST_RUNNER(ring::SmartoolsTest::name())