Example #1
0
config_path_elm_type * config_content_add_path_elm( config_content_type * content , const char * path ) {
  const config_path_elm_type * current_path_elm;

  if (vector_get_size( content->path_elm_stack ) == 0)
    current_path_elm = NULL;
  else
    current_path_elm = vector_get_last_const(content->path_elm_stack);

  {
    config_path_elm_type * new_path_elm;

    {
      char * rel_path = NULL;
      config_root_path_type * invoke_path = config_content_get_invoke_path( content );
      if (path != NULL) {
        if (current_path_elm == NULL)
          rel_path = util_alloc_rel_path( config_root_path_get_abs_path(invoke_path) , path);
        else
          rel_path = config_path_elm_alloc_relpath( current_path_elm , path );
      }
      new_path_elm = config_path_elm_alloc( invoke_path , rel_path );
      util_safe_free( rel_path );
    }
    vector_append_owned_ref( content->path_elm_storage , new_path_elm , config_path_elm_free__);
    vector_append_ref( content->path_elm_stack , new_path_elm );
    return new_path_elm;
  }
}
Example #2
0
int main(int argc , char ** argv) {
#ifdef ERT_LINUX
  const char * rel_path = "rel/path";
  const char * rel_true = "rel/path/XXX";
  const char * path_true1 = "rel/path/XXX";
  
  
#endif
  test_work_area_type * work_area = test_work_area_alloc( "config_path_elm" );
  const char * root = test_work_area_get_cwd( work_area );
  char * abs_path = util_alloc_filename( root , "rel/path" , NULL);
  char * abs_true = util_alloc_filename( root , "rel/path/XXX" , NULL);
  char * path_true2 = util_alloc_filename( root , "rel/path/XXX" , NULL);

  util_chdir( test_work_area_get_original_cwd( work_area ));
  config_root_path_type * root_path = config_root_path_alloc( root );
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path );
    
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true2 );

    
    config_path_elm_free( path_elm );
  }
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , abs_path );
  
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true2 );
    
    config_path_elm_free( path_elm );
  }
  config_root_path_free( root_path );

  util_chdir( root );
  root_path = config_root_path_alloc( NULL );
  {
    config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path );
    
    test_assert_string_equal( config_path_elm_get_relpath( path_elm ) , rel_path );
    test_assert_string_equal( config_path_elm_get_abspath( path_elm ) , abs_path );

    test_assert_string_equal( config_path_elm_alloc_relpath( path_elm , "XXX" ) , rel_true);
    test_assert_string_equal( config_path_elm_alloc_abspath( path_elm , "XXX" ) , abs_true);
    test_assert_string_equal( config_path_elm_alloc_path( path_elm , "XXX" ) , path_true1 );

    
    config_path_elm_free( path_elm );
  }
  
  exit(0);
}