LCOV - code coverage report
Current view: top level - test/unitTest/media/video - test_video_scaler.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 40 40 100.0 %
Date: 2024-03-29 09:30:40 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, write to the Free Software
      18             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      19             :  */
      20             : 
      21             : #include <cppunit/TestAssert.h>
      22             : #include <cppunit/TestFixture.h>
      23             : #include <cppunit/extensions/HelperMacros.h>
      24             : 
      25             : #include "jami.h"
      26             : #include "videomanager_interface.h"
      27             : #include "media/video/video_scaler.h"
      28             : 
      29             : #include "../../../test_runner.h"
      30             : 
      31             : namespace jami { namespace video { namespace test {
      32             : 
      33             : class VideoScalerTest : public CppUnit::TestFixture {
      34             : public:
      35           2 :     static std::string name() { return "video_scaler"; }
      36             : 
      37             :     void setUp();
      38             :     void tearDown();
      39             : 
      40             : private:
      41             :     void testConvertFrame();
      42             :     void testScale();
      43             :     void testScaleWithAspect();
      44             : 
      45           2 :     CPPUNIT_TEST_SUITE(VideoScalerTest);
      46           1 :     CPPUNIT_TEST(testConvertFrame);
      47           1 :     CPPUNIT_TEST(testScale);
      48           1 :     CPPUNIT_TEST(testScaleWithAspect);
      49           4 :     CPPUNIT_TEST_SUITE_END();
      50             : 
      51             :     std::unique_ptr<VideoScaler> scaler_;
      52             : };
      53             : 
      54             : 
      55             : CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(VideoScalerTest, VideoScalerTest::name());
      56             : 
      57             : void
      58           3 : VideoScalerTest::setUp()
      59             : {
      60           3 :     libjami::init(libjami::InitFlag(libjami::LIBJAMI_FLAG_DEBUG | libjami::LIBJAMI_FLAG_CONSOLE_LOG));
      61           3 : }
      62             : 
      63             : void
      64           3 : VideoScalerTest::tearDown()
      65             : {
      66           3 :     libjami::fini();
      67           3 : }
      68             : 
      69             : void
      70           1 : VideoScalerTest::testConvertFrame()
      71             : {
      72           1 :     scaler_.reset(new VideoScaler);
      73             : 
      74           1 :     libjami::VideoFrame input;
      75           1 :     input.reserve(AV_PIX_FMT_YUV420P, 100, 100);
      76           1 :     auto output = scaler_->convertFormat(input, AV_PIX_FMT_RGB24);
      77           1 :     CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output->format()) == AV_PIX_FMT_RGB24);
      78           1 : }
      79             : 
      80             : void
      81           1 : VideoScalerTest::testScale()
      82             : {
      83           1 :     scaler_.reset(new VideoScaler);
      84             : 
      85           1 :     libjami::VideoFrame input, output;
      86           1 :     input.reserve(AV_PIX_FMT_YUV420P, 100, 100);
      87           1 :     output.reserve(AV_PIX_FMT_YUV420P, 200, 200);
      88           1 :     scaler_->scale(input, output);
      89           1 :     CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output.format()) == AV_PIX_FMT_YUV420P);
      90           1 :     CPPUNIT_ASSERT(output.width() == 200);
      91           1 :     CPPUNIT_ASSERT(output.height() == 200);
      92           1 : }
      93             : 
      94             : void
      95           1 : VideoScalerTest::testScaleWithAspect()
      96             : {
      97           1 :     scaler_.reset(new VideoScaler);
      98             : 
      99           1 :     libjami::VideoFrame input, output;
     100           1 :     input.reserve(AV_PIX_FMT_YUV420P, 320, 240); // 4:3
     101           1 :     output.reserve(AV_PIX_FMT_YUV420P, 640, 360); // 16:9
     102           1 :     scaler_->scale_with_aspect(input, output);
     103           1 :     CPPUNIT_ASSERT(static_cast<AVPixelFormat>(output.format()) == AV_PIX_FMT_YUV420P);
     104           1 :     CPPUNIT_ASSERT(output.width() == 640);
     105           1 :     CPPUNIT_ASSERT(output.height() == 360);
     106           1 : }
     107             : 
     108             : }}} // namespace jami::test
     109             : 
     110           1 : RING_TEST_RUNNER(jami::video::test::VideoScalerTest::name());

Generated by: LCOV version 1.14