void gfal2_test_plugin_access_file() { GError* tmp_err=NULL; gfal_handle handle = gfal_initG(&tmp_err); assert_true_with_message(handle != NULL, " must init properly"); if(handle == NULL) return; gfal_plugins_instance(handle, &tmp_err); assert_true_with_message(tmp_err== NULL, " must be instance properly"); if(tmp_err) return; test_mock_lfc(handle, &tmp_err); assert_true_with_message(tmp_err== NULL, " must be mocked properly"); if(tmp_err) return; #if USE_MOCK will_respond(lfc_mock_access, 0, want_string(path, TEST_LFC_VALID_ACCESS+4), want(mode, F_OK)); will_respond(lfc_mock_access, ENOENT, want_string(path, TEST_LFC_NOEXIST_ACCESS+4), want(mode, F_OK)); always_return(lfc_mock_access, EINVAL); #endif int ret = gfal_plugins_accessG(handle, TEST_LFC_VALID_ACCESS, F_OK, &tmp_err); assert_true_with_message(ret == 0, " must be a valid access"); ret = gfal_plugins_accessG(handle, TEST_LFC_NOEXIST_ACCESS, F_OK, &tmp_err); assert_true_with_message(ret!=0 && tmp_err!=NULL && tmp_err->code == ENOENT, " must be a non-existing file %d %ld %d", (int)ret, (long)tmp_err, (int) (tmp_err)?(tmp_err->code):0); g_clear_error(&tmp_err); gfal_handle_freeG(handle); }
void double_item_breadcrumb_does_calls_walker_only_once() { expect(mock_walker, want_string(name, "Hello")); expect(mock_walker, want_string(name, "Goodbye")); Breadcrumb *breadcrumb = create_breadcrumb(); push_breadcrumb(breadcrumb, "Hello"); push_breadcrumb(breadcrumb, "Goodbye"); walk_breadcrumb(breadcrumb, &mock_walker, NULL); }
void gfal2_test__plugin_lstat() { struct stat resu; memset(&resu, 0, sizeof(struct stat)); GError* tmp_err=NULL; gfal_handle handle = gfal_initG(&tmp_err); assert_true_with_message(handle != NULL, " must init properly"); if(handle == NULL) return; gfal_plugins_instance(handle, &tmp_err); assert_true_with_message(tmp_err==NULL, " must be a valid instance call"); if(tmp_err) return; test_mock_lfc(handle, &tmp_err); assert_true_with_message(tmp_err==NULL, " must be a valid mock call"); if(tmp_err) return; #if USE_MOCK struct lfc_filestat f; f.filemode = TEST_GFAL_LFC_FILE_STAT_MODE_VALUE; f.uid = TEST_GFAL_LFC_FILE_STAT_UID_VALUE ; f.gid=TEST_GFAL_LFC_FILE_STAT_GID_VALUE ; will_respond(lfc_mock_lstatg, 0, want_string(lfn, TEST_GFAL_LFC_FILE_STAT_OK+4)); defined_filestat = &f; will_respond(lfc_mock_lstatg, 0, want_string(lfn, TEST_GFAL_LFC_LINK_STAT_OK+4)); defined_filestat = &f; will_respond(lfc_mock_lstatg, ENOENT, want_string(lfn, TEST_GFAL_LFC_FILE_STAT_NONEXIST+4)); always_return(lfc_mock_lstatg, EINVAL); #endif int ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_FILE_STAT_OK, &resu, &tmp_err); assert_true_with_message(ret==0 && tmp_err==NULL, " must be a success convertion"); ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_LINK_STAT_OK, &resu, &tmp_err); assert_true_with_message(ret==0 && tmp_err==NULL, " must be a success convertion"); //g_printerr(" extract from the stat struct : right : %o, owner : %d, group : %d, size : %lu", resu.st_mode, resu.st_uid, resu.st_gid, resu.st_size); ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_FILE_STAT_NONEXIST, &resu, &tmp_err); assert_true_with_message(ret != 0 && tmp_err!=NULL && tmp_err->code == ENOENT, " must be a failure"); g_clear_error(&tmp_err); gfal_handle_freeG(handle); }
void test_mock_guid_open_invalid(const char * guid1){ #if USE_MOCK gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); will_respond(lfc_mock_getlinks, ENOENT, want_string(guid, ((char*)guid1)+5), want(path, NULL), want_non_null(nbentries), want_non_null(linkinfos)); #endif }
void test_mock_guid_open_valid(const char * guid1){ #if USE_MOCK int i1; test_mock_lfc_open_valid(TEST_LFC_OPEN_EXIST); define_linkinfos= calloc(sizeof(struct lfc_linkinfo),3); define_numberlinkinfos=3; for(i1=0; i1< define_numberlinkinfos; ++i1) g_strlcpy(define_linkinfos[i1].path, TEST_LFC_OPEN_EXIST+4, 2048); will_respond(lfc_mock_getlinks, 0, want_string(guid, ((char*)guid1)+5), want(path, NULL), want_non_null(nbentries), want_non_null(linkinfos)); #endif }
void test_srm_mock_chmod(char* url, int retcode){ #if USE_MOCK gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); setup_mock_srm(); define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL)); will_respond(srm_mock_srm_setpermission, retcode, want_non_null(context), want_non_null(input)); #endif }
void test_mock_lfc_open_eacces(const char* lfc_url){ #if USE_MOCK GError* mock_err=NULL; gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); test_mock_lfc(handle, &mock_err); setup_mock_srm(); if( gfal_check_GError(&mock_err)) return; will_respond(lfc_mock_getreplica, EACCES, want_string(path, ((char*)lfc_url)+4), want_non_null(nbentries), want_non_null(rep_entries)); #endif }
void test_mock_srm_open_invalid(char** tab, char** tab_exp, int* res){ #if USE_MOCK test_rfio_mock_all(); setup_mock_srm(); gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); // mock the mds for the srm endpoitn resolution will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL)); define_mock_srmv2_pinfilestatus(1, tab, tab_exp, NULL , res); will_respond(srm_mock_srm_prepare_to_get, 1, want_non_null(context), want_non_null(input), want_non_null(output)); #endif }
void gfal2_test_gfal_srm_getTURLS_pipeline_success() { setup_mock_srm(); setup_mock_bdii(); int i1; #if USE_MOCK define_se_endpoints = calloc(sizeof(char*), 4); // set the response of the MDS layer for endpoint for(i1=0;i1 <3; ++i1) define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL); define_se_types= calloc(sizeof(char*), 4); char* types[] = { "srm_v1", "srm_v2", "srm_v1"}; for(i1=0;i1 <3; ++i1) define_se_types[i1]= strdup(types[i1]); will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL)); defined_get_output = calloc(sizeof(struct srmv2_pinfilestatus),3); defined_get_output[0].turl= strdup(TEST_SRM_TURL_EXAMPLE1); defined_get_output[1].status= ENOENT; defined_get_output[1].explanation = strdup("err msg"); defined_get_output[2].turl = strdup(TEST_SRM_TURL_EXAMPLE1); will_respond(srm_mock_srm_prepare_to_get, 3, want_non_null(context), want_non_null(input), want_non_null(output)); always_return(srm_mock_srm_srmv2_filestatus_delete,0); always_return(srm_mock_srm_srmv2_pinfilestatus_delete,0); #endif GError* tmp_err=NULL; gfal_handle handle = gfal_initG(&tmp_err); assert_true_with_message(handle != NULL, " handle is not properly allocated"); if(handle==NULL) return; gfal_srmv2_opt opts; gfal_srm_opt_initG(&opts, handle); gfal_plugins_instance(handle, NULL); gfal_srm_result* resu=NULL; char* surls[] = {TEST_SRM_VALID_SURL_EXAMPLE1, TEST_SRM_INVALID_SURL_EXAMPLE2, TEST_SRM_VALID_SURL_EXAMPLE1, NULL}; int ret = gfal_srm_getTURLS(&opts, surls, &resu, &tmp_err); assert_true_with_message(ret ==g_strv_length(surls) && resu != NULL && tmp_err == NULL, " must be a successfull request"); gfal_check_GError(&tmp_err); assert_true_with_message(resu[0].err_code == 0 && *(resu[0].err_str)== '\0' && strings_are_equal(resu[0].turl, TEST_SRM_TURL_EXAMPLE1), " must be a valid turl, maybe the turl has changed %d %ld %s",resu[0].err_code, resu[0].err_str, resu[0].turl); assert_true_with_message(resu[1].err_code == ENOENT && *(resu[1].err_str)!= '\0' && *(resu[1].turl) == '\0', " must be a invalid turl 2 "); assert_true_with_message(resu[2].err_code == 0 && *(resu[2].err_str)== '\0' && strings_are_equal(resu[2].turl, TEST_SRM_TURL_EXAMPLE1), " must be a valid turl 3, maybe the turl has changed "); free(resu); gfal_handle_freeG(handle); }
void mock_srm_access_error_response(char* surl, int merror){ #if USE_MOCK GError* mock_err=NULL; gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); test_mock_lfc(handle, &mock_err); setup_mock_srm(); if( gfal_check_GError(&mock_err)) return; char* explanation2[] = { "enoent mock", NULL }; int status2[] = { merror, 0 }; char* surls[] = { surl, NULL }; define_mock_srmv2_filestatus(1, surls, explanation2, NULL, status2); define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL)); will_respond(srm_mock_srm_check_permission, 1, want_non_null(context), want_non_null(statuses), want_non_null(input)); #endif }
void test_mock_lfc_open_valid(const char* lfc_url){ #if USE_MOCK char* tab[]= { TEST_SRM_VALID_SURL_EXAMPLE1, NULL }; char* tab_turl[] = { TEST_SRM_TURL_EXAMPLE1, NULL }; int res[] = { 0, 0 }; test_mock_srm_open_valid(tab, tab_turl, res); GError* mock_err=NULL; gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); test_mock_lfc(handle, &mock_err); if( gfal_check_GError(&mock_err)) return; define_mock_filereplica(1, tab); will_respond(lfc_mock_getreplica, 0, want_string(path, ((char*)lfc_url)+4), want_non_null(nbentries), want_non_null(rep_entries)); #endif }
void test_mock_srm_open_write_valid(char** tab, char** tab_turl, int* res){ #if USE_MOCK test_rfio_mock_all(); setup_mock_srm(); gfal_handle handle = gfal_posix_instance(); gfal_plugins_instance(handle,NULL); int status[] = { 0,0 }; char* turls[] = { "rfio://mockedturl", NULL }; char* surls[] = { "srm://mockedsurl", NULL }; define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); // mock the mds for the srm endpoitn resolution will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL)); define_mock_srmv2_putoutput(1, tab, NULL, tab_turl, res); will_respond(srm_mock_srm_prepare_to_put, 1, want_non_null(context), want_non_null(input), want_non_null(output)); will_respond(rfio_mock_open, 15, want_non_null(path)); define_put_done(1, surls, NULL, turls, status); will_respond(srm_mock_srm_put_done,1, want_non_null(context)); will_respond(rfio_mock_close, 0, want(fd, 15)); #endif }
Ensure can_expect_null_strings_as_well_as_real_ones() { Constraint *want_hello = want_string(label, NULL); assert_equal(compare_constraint(want_hello, NULL), 1); assert_equal(compare_constraint(want_hello, "Hello"), 0); destroy_constraint(want_hello); }
Ensure can_compare_strings_as_equal() { Constraint *want_hello = want_string(label, "Hello"); assert_equal(compare_constraint(want_hello, "Hello"), 1); assert_equal(compare_constraint(want_hello, "Goodbye"), 0); destroy_constraint(want_hello); }
Ensure can_construct_and_destroy_a_want_string_constraint() { Constraint *any_old_string_want = want_string(label, "Hello"); destroy_constraint(any_old_string_want); }