Skip to content

Commit

Permalink
Settings: Unit test LIBOPENSHOT_DEBUG envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed May 15, 2021
1 parent 37f5e4d commit 266455c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 17 additions & 0 deletions tests/CMakeLists.txt
Expand Up @@ -24,6 +24,11 @@
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
################################################################################

# Allow spaces in test names
if(POLICY CMP0110)
cmake_policy(SET CMP0110 NEW)
endif()

# Test media path, used by unit tests for input data
file(TO_NATIVE_PATH "${PROJECT_SOURCE_DIR}/examples/" TEST_MEDIA_PATH)

Expand Down Expand Up @@ -103,6 +108,18 @@ foreach(tname ${OPENSHOT_TESTS})
list(APPEND CATCH2_TEST_TARGETS openshot-${tname}-test)
list(APPEND CATCH2_TEST_NAMES ${tname})
endforeach()
# Add an additional special-case test, for an envvar-dependent setting
add_test(NAME [=["Settings:Debug logging (enabled)"]=]
COMMAND
openshot-Settings-test "[environment]"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties([=["Settings:Debug logging (enabled)"]=]
PROPERTIES
LABELS Settings
ENVIRONMENT "LIBOPENSHOT_DEBUG=1"
)

# Export target list for coverage use
set(UNIT_TEST_TARGETS ${CATCH2_TEST_TARGETS} PARENT_SCOPE)
set(UNIT_TEST_NAMES ${CATCH2_TEST_NAMES} PARENT_SCOPE)
13 changes: 11 additions & 2 deletions tests/Settings.cpp
Expand Up @@ -34,7 +34,7 @@

using namespace openshot;

TEST_CASE( "Default_Constructor", "[libopenshot][settings]" )
TEST_CASE( "Constructor", "[libopenshot][settings]" )
{
// Create an empty color
Settings *s = Settings::Instance();
Expand All @@ -43,7 +43,7 @@ TEST_CASE( "Default_Constructor", "[libopenshot][settings]" )
CHECK_FALSE(s->HIGH_QUALITY_SCALING);
}

TEST_CASE( "Change_Settings", "[libopenshot][settings]" )
TEST_CASE( "Change settings", "[libopenshot][settings]" )
{
// Create an empty color
Settings *s = Settings::Instance();
Expand All @@ -56,3 +56,12 @@ TEST_CASE( "Change_Settings", "[libopenshot][settings]" )
CHECK(Settings::Instance()->OMP_THREADS == 8);
CHECK(Settings::Instance()->HIGH_QUALITY_SCALING == true);
}

TEST_CASE( "Debug logging", "[libopenshot][settings][environment]")
{
// Check the environment
auto envvar = std::getenv("LIBOPENSHOT_DEBUG");
const auto is_enabled = bool(envvar != nullptr);

CHECK(Settings::Instance()->DEBUG_TO_STDERR == is_enabled);
}

0 comments on commit 266455c

Please sign in to comment.