Yet Another Intercepting Proxy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.8 KiB

#include "munit/munit.h"
#include "../src/config.c"
#include <unistd.h> //This has getcwd
#include <stdlib.h> //This has getenv
/*
* Ensures that path_exists returns true on current working dir (should to exist)
*/
MunitResult path_that_exists(const MunitParameter params[],
void* user_data_or_fixture){
char cwd[500] = {'\0'};
getcwd(cwd,500);
munit_assert_true( path_exists( cwd ) );
return MUNIT_OK;
}
MunitResult path_that_doesnt_exist(const MunitParameter params[],
void* user_data_or_fixture){
char cwd[500] = {'\0'};
getcwd(cwd,500);
strcat( cwd, "thisshoudldnotexist" );
munit_assert_false( path_exists( cwd ) );
return MUNIT_OK;
}
MunitResult tilde_resolves_correctly(const MunitParameter params[],
void* user_data_or_fixture){
munit_assert_string_equal( getenv("HOME"), resolveTilde("~") );
return MUNIT_OK;
}
MunitResult check_config_dir_with_xdg(const MunitParameter params[],
void* user_data_or_fixture){
char directory[] = "/testing/xdg/directory";
setenv( "XDG_CONFIG_HOME",directory, 1 );
munit_assert_string_equal( directory, getConfigDir() );
return MUNIT_OK;
}
MunitResult check_config_dir_without_xdg(const MunitParameter params[],
void* user_data_or_fixture){
unsetenv( "XDG_CONFIG_HOME" );
char dir[500] = {'\0'};
strcpy( dir, getenv("HOME") );
strcat( dir, "/.config" );
munit_assert_string_equal( dir, getConfigDir() );
return MUNIT_OK;
}
MunitTest tests[] = {
{
"/path_exists/yes", /* name */
path_that_exists, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
{
"/path_exists/no", /* name */
path_that_doesnt_exist, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
{
"/TildeResolves", /* name */
tilde_resolves_correctly, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
{
"/ConfigDir/WithXDG", /* name */
check_config_dir_with_xdg, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
{
"/ConfigDir/WithoutXDG", /* name */
check_config_dir_without_xdg, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
/* Mark the end of the array with an entry where the test
* function is NULL */
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
MunitSuite config_test_suite = {
"/config", /* name */
tests, /* tests */
NULL, /* suites */
1, /* iterations */
MUNIT_SUITE_OPTION_NONE /* options */
};
#ifndef MAINTEST
#define MAINTEST
int main (int argc, char* argv[]) {
return munit_suite_main(&config_test_suite, NULL, argc, argv);
}
#endif /* ifndef MAINTEST */