diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5b4d0263..ddf00cd3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,7 @@ enable_testing() include( GoogleTest ) set ( TESTS + auxiliary.cpp interface_c.cpp ) diff --git a/test/auxiliary.cpp b/test/auxiliary.cpp new file mode 100644 index 00000000..1293647e --- /dev/null +++ b/test/auxiliary.cpp @@ -0,0 +1,86 @@ +#include + + +extern "C" { + int show_debug_output(); + void update_depot_path(const char * project_directory, const char * depot_path); +} + +// Julia project path defined via cmake +const char * julia_project_path = JULIA_PROJECT_PATH; + +const char* default_depot_path = "julia-depot"; + + +TEST(AuxiliaryTest, DebugOutput) { + + const char * envvar = "LIBTRIXI_DEBUG"; + + // environment variable not set -> no debug output + unsetenv(envvar); + EXPECT_EQ( show_debug_output(), 0 ); + + // environment variable set to "all" -> debug output + setenv(envvar, "all", /*overwrite*/ 1 ); + EXPECT_EQ( show_debug_output(), 1 ); + + // environment variable set to "c" -> debug output + setenv(envvar, "c", /*overwrite*/ 1 ); + EXPECT_EQ( show_debug_output(), 1 ); + + // environment variable set to "julia" -> no debug output + setenv(envvar, "julia", /*overwrite*/ 1 ); + EXPECT_EQ( show_debug_output(), 0 ); +} + + +TEST(AuxiliaryTest, DepotPath) { + + const char * depot_envvar = "JULIA_DEPOT_PATH"; + const char * custom_depot_path = "/tmp/julia-depot"; + + // unset depot path environment variable + unsetenv(depot_envvar); + + // let it be set explictly and check + update_depot_path( julia_project_path, custom_depot_path ); + EXPECT_STREQ( getenv(depot_envvar), custom_depot_path ); + + // unset depot path environment variable + unsetenv(depot_envvar); + + // let it be set to default location and check + update_depot_path( julia_project_path, NULL ); + std::string expected_depot_path( julia_project_path ); + expected_depot_path.append("/"); + expected_depot_path.append( default_depot_path ); + EXPECT_STREQ( getenv(depot_envvar), expected_depot_path.c_str() ); + + // unset depot path environment variable + unsetenv(depot_envvar); + + // be evil + const char * garbage = "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long" + "this_string_is_just_way_toooooooooooooooooooo_long"; + EXPECT_DEATH( update_depot_path( garbage, NULL ), + "buffer size not sufficient for depot path construction"); +}