Example #1
0
bool path_stack_push( path_stack_type * path_stack , const char * path ) {
    if (path != NULL)
        if (chdir( path ) != 0)
            return false;

    path_stack_push_cwd( path_stack );
    return true;
}
Example #2
0
int main(int argc , char ** argv) {
  char * cwd     = util_alloc_cwd( );
  char * path1   = argv[1];
  char * path2   = argv[2];
  {
    path_stack_type * path_stack = path_stack_alloc();

    path_stack_push_cwd( path_stack );
    
    if (path_stack_push( path_stack , "NotExist-1111"))
      test_error_exit("Pushed unexisting path\n");
    
    if (!path_stack_push( path_stack, path1 ))
      test_error_exit("Failed to push:%s \n",path1 );
    
    util_chdir( path2 );
    if (util_is_cwd( path1 ))
      test_error_exit("Failed to chdir(%s) \n",path2 );
    
    {
      if (path_stack_size( path_stack ) != 2)
        test_error_exit("Wrong stack size");
    
      if (strcmp( path1 , path_stack_peek( path_stack )) != 0)
        test_error_exit("peek error");
    }
    
    path_stack_pop( path_stack );
    printf("After pop: cwd:%s   path1:%s  \n",util_alloc_cwd() , path1);
    if (!util_is_cwd( path1 ))
      test_error_exit("path_stack_pop failed \n");

    path_stack_pop( path_stack );
    if (!util_is_cwd( cwd ))
      test_error_exit("path_stack_pop failed \n");

    if (path_stack_size( path_stack ) != 0)
      test_error_exit("Wrong stack size");
    
    if (!path_stack_push(path_stack , NULL))
      test_error_exit("Hmmm - push(NULL) failed \n");

    if (path_stack_size( path_stack ) != 1)
      test_error_exit("Wrong stack size");
    
    path_stack_pop( path_stack );
    path_stack_free( path_stack);
  }
  exit(0);
}
Example #3
0
void test_case_no_path( const char * sum_case , bool expected_exist) {
  path_stack_type * path_stack = path_stack_alloc();
  path_stack_push_cwd( path_stack );
  {
    char * basename , *path;

    util_alloc_file_components( sum_case , &path , &basename , NULL );
    if (path)
      chdir( path );
    test_assert_bool_equal(expected_exist ,  ecl_sum_case_exists( basename ));

    free( path );
    free( basename );
  }
  path_stack_pop( path_stack );
  path_stack_free( path_stack );
}