From bcbc6fcc60c7604fd59249fabf7c62770ac7f111 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez Date: Thu, 17 Aug 2017 16:43:18 -0400 Subject: [PATCH] test: refactoring test files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * moved unit-tests into the dedicated directory unitTest * removed no-more-used files * common code style for test and usage of test_runner.h everywhere * imported video_input changes by Olivier Grégoire (GSoC-2017) Change-Id: Ifbb5585caaa2618c4ab943681814c9afbfc76311 Reviewed-by: Olivier Soldano --- Makefile.am | 2 +- configure.ac | 7 +- test/.gitignore | 5 ++ test/Makefile.am | 5 +- test/base64/.gitignore | 10 --- test/base64/Makefile.am | 41 ---------- test/base64/base64.cpp | 53 ------------- test/media/Makefile.am | 3 - test/media/video/.gitignore | 1 - test/media/video/Makefile.am | 11 --- test/media/video/README | 1 - test/media/video/test_video_input.h | 33 -------- test/sip/Makefile.am | 14 ++-- .../{base64/test_runner.hpp => test_runner.h} | 0 test/unitTest/Makefile.am | 22 ++++++ test/unitTest/base64/base64.cpp | 79 +++++++++++++++++++ .../media/video/testVideo_input.cpp} | 52 ++++++++---- 17 files changed, 158 insertions(+), 181 deletions(-) delete mode 100644 test/base64/.gitignore delete mode 100644 test/base64/Makefile.am delete mode 100644 test/base64/base64.cpp delete mode 100644 test/media/Makefile.am delete mode 100644 test/media/video/.gitignore delete mode 100644 test/media/video/Makefile.am delete mode 100644 test/media/video/README delete mode 100644 test/media/video/test_video_input.h rename test/{base64/test_runner.hpp => test_runner.h} (100%) create mode 100644 test/unitTest/Makefile.am create mode 100644 test/unitTest/base64/base64.cpp rename test/{media/video/test_video_input.cpp => unitTest/media/video/testVideo_input.cpp} (55%) diff --git a/Makefile.am b/Makefile.am index 9185c6936..7accd4555 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,7 @@ SOURCES= ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src ringtones man $(TESTS_DIR) doc bin test +SUBDIRS = src ringtones man doc bin test EXTRA_DIST = m4/libtool.m4 \ m4/lt~obsolete.m4 \ diff --git a/configure.ac b/configure.ac index 3c87dfe7a..c658ffbbc 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,7 @@ AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_BUILD AC_CANONICAL_HOST -AM_INIT_AUTOMAKE([-Wno-portability]) +AM_INIT_AUTOMAKE([-Wno-portability subdir-objects]) m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # required by automake 1.12 AC_CONFIG_HEADERS([config.h]) @@ -725,9 +725,8 @@ AC_CONFIG_FILES([Makefile \ ringtones/Makefile \ test/Makefile\ test/sip/Makefile \ - test/base64/Makefile \ - test/media/Makefile \ - test/media/video/Makefile \ + test/unitTest/Makefile \ + man/Makefile \ doc/Makefile \ doc/doxygen/Makefile]) diff --git a/test/.gitignore b/test/.gitignore index c2cf4ab8e..8cbb7b54d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,7 +1,12 @@ *.o +# test binaries +ut_* +test_* + # test result files *.log *.trs .dirstamp +dring-sample.yml.bak \ No newline at end of file diff --git a/test/Makefile.am b/test/Makefile.am index 2a2326301..19aad19f5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,3 +1,2 @@ -SUBDIRS=sip -SUBDIRS+=base64 -SUBDIRS+=media +SUBDIRS = sip +SUBDIRS += unitTest diff --git a/test/base64/.gitignore b/test/base64/.gitignore deleted file mode 100644 index 633b4680f..000000000 --- a/test/base64/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*.o - -# test result files -*.log -*.trs - -#test binaries -sip - -base64 diff --git a/test/base64/Makefile.am b/test/base64/Makefile.am deleted file mode 100644 index f7cc7239d..000000000 --- a/test/base64/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -include $(top_srcdir)/globals.mk - -AM_CXXFLAGS=-I$(top_srcdir)/src/media/video -I$(top_srcdir)/src -check_PROGRAMS= - -# -# base64 testsuite -# -check_PROGRAMS+= base64 -base64_SOURCES= base64.cpp -base64_LDADD= $(CPPUNIT_LIBS) $(top_builddir)/src/libring.la - -# -# video_input testsuite -# -#check_PROGRAMS+= test_video_input -#test_video_input_SOURCES= media/video/test_video_input.cpp media/video/test_video_input.h -#test_video_input_LDADD= $(top_builddir)/src/libring.la $(top_builddir)/src/media/video/libvideo.la $(YAML_LIBS) - -################## -# EXCLUDED_TEST SUITES # -################## -# test_video_rtp -# reason: compilation fails -# test_video_rtp.cpp:38:19: error: no matching function for call to ‘ring::video::VideoRtpSession::start()’ -# -# test_video_rtp_SOURCES= media/video/test_video_rtp.cpp -# test_video_rtp_LDADD= $(top_builddir)/src/libring.la $(top_builddir)/src/media/video/libvideo.la $(YAML_LIBS) -# -# -# test_shm (compilation fails, include file not in repository?) -# reason: compilation fails, include file not in repository: -# test_video_input.cpp.cpp:21:22: fatal error: shm_sink.h: No such file or directory -# -# if HAVE_LINUX -# test_shm_SOURCES= media/video/test_shm.cpp media/video/shm_src.cpp media/video/shm_src.h -# test_shm_LDADD= $(top_builddir)/src/libring.la $(top_builddir)/src/media/video/libvideo.la $(YAML_LIBS) -lrt -# test_shm_CXXFLAGS=$(AM_CXXFLAGS) -# endif - -TESTS= $(check_PROGRAMS) diff --git a/test/base64/base64.cpp b/test/base64/base64.cpp deleted file mode 100644 index 8ad6e7c7f..000000000 --- a/test/base64/base64.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -#include "test_runner.hpp" -#include "base64.h" - -namespace ring_test { - class Base64Test : public CppUnit::TestFixture { - public: - static std::string name() { return "base64"; } - - private: - void encodingTest(); - void decodingTestSuccess(); - void decodingTestFail(); - - CPPUNIT_TEST_SUITE(Base64Test); - CPPUNIT_TEST(encodingTest); - CPPUNIT_TEST(decodingTestSuccess); - CPPUNIT_TEST(decodingTestFail); - CPPUNIT_TEST_SUITE_END(); - - const std::vector test_bytes = { 23, 45, 67, 87, 89, 34, 2, 45, 9, 10 }; - const std::string test_base64 = "Fy1DV1kiAi0JCg=="; - const std::string test_invalid_base64 = "ERSAÄÖöädt4-++asd=="; - }; - - CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Base64Test, Base64Test::name()); - - void Base64Test::encodingTest() - { - const std::string output = ring::base64::encode(test_bytes); - CPPUNIT_ASSERT(test_base64.compare(output) == 0); - } - - void Base64Test::decodingTestSuccess() - { - const std::vector output = ring::base64::decode(test_base64); - CPPUNIT_ASSERT(std::equal(test_bytes.begin(), test_bytes.end(), output.begin())); - } - - void Base64Test::decodingTestFail() - { - // Currently, the input is not validated, i.e. the function most not throw an - // exception if decoding fails to make sure calling code not expecting any - // is no broken. (Some validation should be implemented sometimes later, though. - ring::base64::decode(test_invalid_base64); - CPPUNIT_ASSERT(true); - } -} // namespace tests - -RING_TEST_RUNNER(ring_test::Base64Test::name()) diff --git a/test/media/Makefile.am b/test/media/Makefile.am deleted file mode 100644 index 32b8fca2a..000000000 --- a/test/media/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -include $(top_srcdir)/globals.mk - -SUBDIRS= video diff --git a/test/media/video/.gitignore b/test/media/video/.gitignore deleted file mode 100644 index 2e3b6e6e0..000000000 --- a/test/media/video/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test_video_input diff --git a/test/media/video/Makefile.am b/test/media/video/Makefile.am deleted file mode 100644 index 248ad056b..000000000 --- a/test/media/video/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -include $(top_srcdir)/globals.mk - -check_PROGRAMS= -# -# video_input testsuite -# -check_PROGRAMS+= test_video_input -test_video_input_SOURCES= test_video_input.cpp test_video_input.h -test_video_input_LDADD= $(top_builddir)/src/libring.la - -TESTS= $(check_PROGRAMS) diff --git a/test/media/video/README b/test/media/video/README deleted file mode 100644 index 9ef0c4f1e..000000000 --- a/test/media/video/README +++ /dev/null @@ -1 +0,0 @@ -c++ shm_src.cpp shmclient.cpp -o shmclient `pkg-config --cflags --libs clutter-1.0` -lrt -pthread -O2 diff --git a/test/media/video/test_video_input.h b/test/media/video/test_video_input.h deleted file mode 100644 index aeeb2acd3..000000000 --- a/test/media/video/test_video_input.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2011-2017 Savoir-faire Linux Inc. - * - * Author: Tristan Matthews - * - * 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. - */ - -#ifndef _VIDEO_INPUT_TEST_ -#define _VIDEO_INPUT_TEST_ - -namespace ring { namespace video { namespace test { - -class VideoInputTest { -public: - void testInput(); -}; - -}}} // namespace ring::video::test - -#endif // _VIDEO_INPUT_TEST_ diff --git a/test/sip/Makefile.am b/test/sip/Makefile.am index 73a2d3a4f..0a6b33b39 100644 --- a/test/sip/Makefile.am +++ b/test/sip/Makefile.am @@ -1,8 +1,10 @@ # Rules for the test code (use `make check` to execute) include $(top_srcdir)/globals.mk -TESTS = sip -check_PROGRAMS = $(TESTS) -sip_LDADD = $(top_builddir)/src/libring.la -sip_SOURCES = sip.cpp test_SIP.h test_SIP.cpp ../../manager.h -sip_CXXFLAGS = $(CPPUNIT_CFLAGS) -sip_LDFLAGS = $(CPPUNIT_LIBS) -ldl + +AM_CXXFLAGS = -I$(top_srcdir)/src +AM_LDFLAGS = $(CPPUNIT_LIBS) $(top_builddir)/src/libring.la + +check_PROGRAMS = test_sip +test_sip_SOURCES = sip.cpp test_SIP.h test_SIP.cpp + +TESTS = $(check_PROGRAMS) diff --git a/test/base64/test_runner.hpp b/test/test_runner.h similarity index 100% rename from test/base64/test_runner.hpp rename to test/test_runner.h diff --git a/test/unitTest/Makefile.am b/test/unitTest/Makefile.am new file mode 100644 index 000000000..0f39a2af2 --- /dev/null +++ b/test/unitTest/Makefile.am @@ -0,0 +1,22 @@ +# Rules for the test code (use `make check` to execute) +include $(top_srcdir)/globals.mk + +AM_CXXFLAGS = -I$(top_srcdir)/src +AM_LDFLAGS = $(CPPUNIT_LIBS) $(top_builddir)/src/libring.la +check_PROGRAMS = + +####### Unit Test ######## + +# +# base64 +# +check_PROGRAMS += ut_base64 +ut_base64_SOURCES = base64/base64.cpp + +# +# video_input testsuite +# +check_PROGRAMS += ut_video_input +ut_video_input_SOURCES = media/video/testVideo_input.cpp + +TESTS = $(check_PROGRAMS) diff --git a/test/unitTest/base64/base64.cpp b/test/unitTest/base64/base64.cpp new file mode 100644 index 000000000..a60de858f --- /dev/null +++ b/test/unitTest/base64/base64.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2011-2017 Savoir-faire Linux Inc. + * + * Author: florian Wiesweg + * + * 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 +#include +#include + +#include "test_runner.h" + +#include "base64.h" + +namespace ring { namespace test { + +class Base64Test : public CppUnit::TestFixture { +public: + static std::string name() { return "base64"; } + +private: + void encodingTest(); + void decodingTestSuccess(); + void decodingTestFail(); + + CPPUNIT_TEST_SUITE(Base64Test); + CPPUNIT_TEST(encodingTest); + CPPUNIT_TEST(decodingTestSuccess); + CPPUNIT_TEST(decodingTestFail); + CPPUNIT_TEST_SUITE_END(); + + const std::vector test_bytes = { 23, 45, 67, 87, 89, 34, 2, 45, 9, 10 }; + const std::string test_base64 = "Fy1DV1kiAi0JCg=="; + const std::string test_invalid_base64 = "ERSAÄÖöädt4-++asd=="; +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Base64Test, Base64Test::name()); + +void +Base64Test::encodingTest() +{ + const std::string output = ring::base64::encode(test_bytes); + CPPUNIT_ASSERT(test_base64.compare(output) == 0); +} + +void +Base64Test::decodingTestSuccess() +{ + const std::vector output = ring::base64::decode(test_base64); + CPPUNIT_ASSERT(std::equal(test_bytes.begin(), test_bytes.end(), output.begin())); +} + +void +Base64Test::decodingTestFail() +{ + // Currently, the input is not validated, i.e. the function most not throw an + // exception if decoding fails to make sure calling code not expecting any + // is no broken. (Some validation should be implemented sometimes later, though. + ring::base64::decode(test_invalid_base64); + CPPUNIT_ASSERT(true); +} + +}} // namespace ring::test + +RING_TEST_RUNNER(ring::test::Base64Test::name()); diff --git a/test/media/video/test_video_input.cpp b/test/unitTest/media/video/testVideo_input.cpp similarity index 55% rename from test/media/video/test_video_input.cpp rename to test/unitTest/media/video/testVideo_input.cpp index d089ae8dd..255cf900c 100644 --- a/test/media/video/test_video_input.cpp +++ b/test/unitTest/media/video/testVideo_input.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2011-2017 Savoir-faire Linux Inc. * * Author: Tristan Matthews + * Author: Olivier Gregoire * * 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 @@ -18,30 +19,53 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "test_video_input.h" +#include +#include +#include + +#include "test_runner.h" + #include "media/video/video_input.h" #include "media_const.h" +#include "dring.h" + #include #include -namespace ring { namespace video { namespace test { +namespace ring { namespace test { -void VideoInputTest::testInput() +class VideoInputTest : public CppUnit::TestFixture { +public: + static std::string name() { return "video_input"; } + +private: + void testInput(); + void init_daemon(); + + CPPUNIT_TEST_SUITE(VideoInputTest); + CPPUNIT_TEST(init_daemon); + CPPUNIT_TEST(testInput); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(VideoInputTest, VideoInputTest::name()); + +void +VideoInputTest::init_daemon() +{ + DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG | DRing::DRING_FLAG_CONSOLE_LOG)); + DRing::start("dring-sample.yml"); +} + +void +VideoInputTest::testInput() { static const std::string sep = DRing::Media::VideoProtocolPrefix::SEPARATOR; std::string resource = DRing::Media::VideoProtocolPrefix::DISPLAY + sep + std::string(getenv("DISPLAY") ? : ":0.0"); - VideoInput video; + video::VideoInput video; video.switchInput(resource); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); } -}}} // namespace ring::video::test +}} // namespace ring::test -int main () -{ - for (int i = 0; i < 20; ++i) { - ring::video::test::VideoInputTest test; - test.testInput(); - } - return 0; -} +RING_TEST_RUNNER(ring::test::VideoInputTest::name());