Example #1
0
void test_update_store() {
  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store1" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , true );
    test_work_area_free( work_area );
    test_assert_true( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store2" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_free( work_area );
    test_assert_false( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store3" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , false );
    test_work_area_free( work_area );
    test_assert_false( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store4" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , true);
    test_work_area_free( work_area );
    test_assert_true( util_entry_exists( work_cwd ));
  }
}
Example #2
0
void test_get_cwd() {
   test_work_area_type * work_area = test_work_area_alloc( "CWD-TEST");
   char * cwd = util_alloc_cwd();
   test_assert_string_equal( cwd , test_work_area_get_cwd( work_area ));
   free( cwd );
   test_work_area_free( work_area );
}
Example #3
0
void test_copy_parent_content( const char * path ) {
  char * full_path = util_alloc_abs_path( path );
  char * parent_path = util_alloc_parent_path( full_path );
  test_work_area_type * work_area = test_work_area_alloc( "copy-parent-content" );

  test_assert_false( test_work_area_copy_parent_content( work_area , "Does/not/exist") );
  test_assert_true( test_work_area_copy_parent_content( work_area , path ) );

  {

    struct dirent ** src_namelist;
    struct dirent ** target_namelist;
    int src_size    = scandir( parent_path                         , &src_namelist    , NULL , alphasort);
    int target_size = scandir( test_work_area_get_cwd( work_area ) , &target_namelist , NULL , alphasort);

    test_assert_int_equal( src_size , target_size );
    for (int i=0; i < src_size; i++) {
      test_assert_string_equal( src_namelist[i]->d_name , target_namelist[i]->d_name);

      free( src_namelist[i] );
      free( target_namelist[i] );
    }

    free( src_namelist );
    free( target_namelist );
  }
  free( parent_path );
  free( full_path );

  test_work_area_free( work_area );
}
void test_predicate_matching() {
  test_work_area_type * work_area = test_work_area_alloc("predicate_test");
  stringlist_type * s = stringlist_alloc_new();
  stringlist_append_copy(s, "s");
  stringlist_select_files(s, "does/not/exist", NULL, NULL);
  test_assert_int_equal(stringlist_get_size(s), 0);


  {
    FILE * f = util_fopen("FILE.txt", "w");
    fclose(f);
  }
  stringlist_select_files(s , test_work_area_get_cwd(work_area), NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , NULL, NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  test_assert_string_equal( "FILE.txt", stringlist_iget(s, 0));

  stringlist_select_files(s , test_work_area_get_cwd(work_area), FILE_predicate, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , test_work_area_get_cwd(work_area), not_FILE_predicate, NULL);
  test_assert_int_equal(0, stringlist_get_size(s));

  stringlist_free(s);
  test_work_area_free(work_area);
}
Example #5
0
void test_chdir() {
  test_work_area_type * work_area = test_work_area_alloc("test-area");
  const char * cwd = test_work_area_get_cwd( work_area );

  test_assert_false( util_chdir_file( "/file/does/not/exist"));
  test_assert_false( util_chdir_file( cwd ));
  {
    FILE * stream = util_mkdir_fopen("path/FILE","w");
    fclose( stream );
  }
  test_assert_true( util_chdir_file( "path/FILE" ));
  test_assert_string_equal( util_alloc_cwd() , util_alloc_filename( cwd, "path", NULL));
  test_work_area_free( work_area );
}
Example #6
0
void create_test_area(const char * test_name , bool store) {
  char * pre_cwd = util_alloc_cwd();
  test_work_area_type * work_area = test_work_area_alloc( test_name , store);
  char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
  
  test_assert_true( util_is_directory( work_path ));
  test_work_area_free( work_area );
  test_assert_bool_equal( store , util_entry_exists( work_path ));
  
  {
    char * post_cwd = util_alloc_cwd();
    test_assert_string_equal( pre_cwd , post_cwd );
    free( post_cwd );
  }
  free( pre_cwd );
  free( work_path );
}
Example #7
0
void submit_jobs_to_queue(job_queue_type * queue, test_work_area_type * work_area, char * executable_to_run, int number_of_jobs, int number_of_slowjobs, char* sleep_short, char* sleep_long, bool multithreaded) {
  int submitted_slowjobs = 0;
  for (int i = 0; i < number_of_jobs; i++) {
    char * runpath = util_alloc_sprintf("%s/%s_%d", test_work_area_get_cwd(work_area), "job", i);
    util_make_path(runpath);

    char * sleeptime = sleep_short;
    if (submitted_slowjobs < number_of_slowjobs) {
      sleeptime = sleep_long;
      submitted_slowjobs++;
    }

    if (multithreaded) {

      job_queue_add_job_mt(queue, executable_to_run, NULL, NULL, NULL, NULL, 1, runpath, "Testjob", 2, (const char *[2]) {
        runpath, sleeptime
      });
    } else {
Example #8
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);
}