diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f93c6f..3406f7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ OPTION( BUILD_APP "Build GUI Application" ON ) OPTION( BUILD_TOOLS "Build Command Line Application" ON ) OPTION( BUILD_EXAMPLES "Build Examples" OFF ) OPTION( BUILD_DOC "Build Documentation" OFF ) -OPTION( BUILD_TESTS "Build Google Tests" ON ) +OPTION( BUILD_TESTS "Build Google Tests" OFF ) OPTION( USE_FERVOR "Add Fervor support" OFF ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ab80be4..e353aef 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -95,3 +95,7 @@ IF( NOT USE_STATIC ) INSTALL(FILES ${Calyp_Lib_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CalypConfig.cmake DESTINATION share/calyp ) ENDIF() + +IF( BUILD_TESTS ) + ADD_SUBDIRECTORY( tests ) +ENDIF() diff --git a/lib/tests/CMakeLists.txt b/lib/tests/CMakeLists.txt new file mode 100644 index 0000000..53d0de0 --- /dev/null +++ b/lib/tests/CMakeLists.txt @@ -0,0 +1,10 @@ +### +### CMakeLists for playuver lib tests component +### + +INCLUDE_DIRECTORIES( ${GTEST_INCLUDE_DIRS} ) + +ADD_EXECUTABLE(PlaYUVerFrameQualityTests PlaYUVerFrameQualityTests.cpp ) +TARGET_LINK_LIBRARIES(PlaYUVerFrameQualityTests ${PROJECT_LIBRARY} ${PlaYUVerLib_DEPS} gtest gtest_main ) +ADD_TEST(PlaYUVerFrameQualityTests PlaYUVerFrameQualityTests) + diff --git a/lib/tests/PlaYUVerFrameQualityTests.cpp b/lib/tests/PlaYUVerFrameQualityTests.cpp new file mode 100644 index 0000000..9726b5e --- /dev/null +++ b/lib/tests/PlaYUVerFrameQualityTests.cpp @@ -0,0 +1,93 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2017 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.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 2 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. + */ + +/** + * \file CalypFrameQualityTests.cpp + * \brief CalypFrame quality metrics tests + */ + +#include "gtest/gtest.h" +#include "CalypStream.h" +#include "CalypFrame.h" + +class CalypFrameQualityTest : public ::testing::Test +{ + protected: + // Per-test-case set-up. + // Called before the first test in this test case. + // Can be omitted if not needed. + static void SetUpTestCase() + { + pcStreamPast = new CalypStream; + pcStreamPast->open( "../../../tests_data/BasketballDrill_F10_832x480_yuv420p.yuv", 832, 480, 0, 8, + CLP_BIG_ENDIAN, 1, true ); + pcFramePast = pcStreamPast->getCurrFrame(); + + pcStreamFuture = new CalypStream; + pcStreamFuture->open( "../../../tests_data//BasketballDrill_F15_832x480_yuv420p.yuv", 832, 480, 0, 8, + CLP_BIG_ENDIAN, 1, true ); + pcFrameFuture = pcStreamFuture->getCurrFrame(); + } + + // Per-test-case tear-down. + // Called after the last test in this test case. + // Can be omitted if not needed. + static void TearDownTestCase() + { + pcStreamPast->close(); + delete pcStreamPast; + pcStreamPast = NULL; + + pcStreamFuture->close(); + delete pcStreamFuture; + pcStreamFuture = NULL; + } + + // Some expensive resource shared by all tests. + static CalypStream* pcStreamPast; + static CalypFrame* pcFramePast; + + static CalypStream* pcStreamFuture; + static CalypFrame* pcFrameFuture; +}; + +CalypStream* CalypFrameQualityTest::pcStreamPast = NULL; +CalypStream* CalypFrameQualityTest::pcStreamFuture = NULL; +CalypFrame* CalypFrameQualityTest::pcFramePast = NULL; +CalypFrame* CalypFrameQualityTest::pcFrameFuture = NULL; + +TEST_F( CalypFrameQualityTest, MSE ) +{ + for( int c = 0; c < 3; c++ ) + EXPECT_EQ( pcFramePast->getQuality( CalypFrame::MSE_METRIC, pcFramePast, c ), 0 ); + + EXPECT_NE( pcFrameFuture->getQuality( CalypFrame::MSE_METRIC, pcFramePast, 0 ), 0 ); +} + +TEST_F( CalypFrameQualityTest, PSNR ) +{ + for( int c = 0; c < 3; c++ ) + EXPECT_EQ( pcFramePast->getQuality( CalypFrame::PSNR_METRIC, pcFramePast, c ), 100 ); +} + +TEST_F( CalypFrameQualityTest, SSIM ) +{ + for( int c = 0; c < 3; c++ ) + EXPECT_EQ( pcFramePast->getQuality( CalypFrame::SSIM_METRIC, pcFramePast, c ), 1.0 ); +}