Skip to content

Commit

Permalink
add tests for auxiliary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
benegee committed Aug 21, 2023
1 parent 42b44e8 commit 95b3f1e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enable_testing()
include( GoogleTest )

set ( TESTS
auxiliary.cpp
interface_c.cpp )


Expand Down
86 changes: 86 additions & 0 deletions test/auxiliary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <gtest/gtest.h>


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

Check warning on line 45 in test/auxiliary.cpp

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"explictly" should be "explicitly".
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");
}

0 comments on commit 95b3f1e

Please sign in to comment.