int xml_test(void){ Timer::wait_msec(500); if( create_test_file() < 0 ){ return -1; } if( value_test() < 0 ){ return -1; } return 0; }
void test_o_append_existing_file(sqlfs_t *sqlfs) { printf("Testing opening existing file O_APPEND and writing..."); int i, testsize=200; char buf[testsize]; char buf2[testsize]; char testfilename[PATH_MAX]; struct stat sb; struct fuse_file_info ffi; struct fuse_file_info fi = { 0 }; fi.flags |= O_RDONLY; randomfilename(testfilename, PATH_MAX, "append_existing_file"); create_test_file(sqlfs, testfilename, testsize); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == testsize); i = sqlfs_proc_read(sqlfs, testfilename, buf, testsize, 0, &fi); assert(i == testsize); ffi.flags = O_WRONLY | O_APPEND; ffi.direct_io = 0; int rc = sqlfs_proc_open(sqlfs, testfilename, &ffi); assert(rc == 0); sqlfs_proc_write(sqlfs, testfilename, buf, testsize, 0, &ffi); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == testsize*2); i = sqlfs_proc_read(sqlfs, testfilename, buf2, testsize, 0, &fi); assert(!strcmp(buf, buf2)); i = sqlfs_proc_read(sqlfs, testfilename, buf2, testsize, testsize, &fi); assert(!strcmp(buf, buf2)); printf("passed\n"); }
/*! \brief creates count of test files in a directory * \param path direcotry where are test files created * \param count how much of test files is created */ void generate_file_content(char * path, int count) { char local_path[MAX_PATH + 1]; strncpy(local_path, path, MAX_PATH - 1); int local_path_len = strlen(local_path); int i; for (i = 0; i < count; ++i) { get_filename(local_path + local_path_len); create_test_file(local_path); } }
void test_truncate(sqlfs_t *sqlfs, int testsize) { printf("Testing truncating..."); struct stat sb; char testfilename[PATH_MAX]; randomfilename(testfilename, PATH_MAX, "truncate"); create_test_file(sqlfs, testfilename, testsize); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == testsize); sqlfs_proc_truncate(sqlfs, testfilename, 0); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == 0); printf("passed\n"); }
void test_read_bigger_than_buffer(sqlfs_t *sqlfs) { printf("Testing reading while requesting more bytes than will fit in the buffer..."); int i; int bufsize = 200; int filesize = bufsize * 4; char testfilename[PATH_MAX]; char buf[bufsize]; struct fuse_file_info fi = { 0 }; randomfilename(testfilename, PATH_MAX, "read_bigger_than_buffer"); create_test_file(sqlfs, testfilename, filesize); i = sqlfs_proc_read(sqlfs, testfilename, buf, sizeof(buf), bufsize, &fi); assert(i==sizeof(buf)); printf("passed\n"); }
void test_truncate_existing_file(sqlfs_t *sqlfs, int testsize) { printf("Testing opening existing file truncation..."); char testfilename[PATH_MAX]; struct stat sb; struct fuse_file_info ffi; randomfilename(testfilename, PATH_MAX, "truncate"); create_test_file(sqlfs, testfilename, testsize); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == testsize); ffi.flags = O_WRONLY | O_CREAT | O_TRUNC; ffi.direct_io = 0; int rc = sqlfs_proc_open(sqlfs, testfilename, &ffi); assert(rc == 0); sqlfs_proc_getattr(sqlfs, testfilename, &sb); assert(sb.st_size == 0); printf("passed\n"); }
void test_read_byte_with_offset(sqlfs_t *sqlfs, int testsize) { printf("Testing reading a byte with offset 10000 times..."); int i, y, readloc; char buf[200]; char testfilename[PATH_MAX]; struct fuse_file_info fi = { 0 }; randomfilename(testfilename, PATH_MAX, "read_byte_with_offset"); create_test_file(sqlfs, testfilename, testsize); fi.flags |= ~0; for(y=0; y<10000; y++) { readloc = (float)rand() / RAND_MAX * (testsize-1); i = sqlfs_proc_read(sqlfs, testfilename, buf, 1, readloc, &fi); assert(i == 1); assert(buf[0] == (readloc % 90) + 32); } printf("passed\n"); }
static void test_mmio_end_of_file(void) { char test_file[MAX_PATH], buffer[128], data[16]; MMIOINFO mmio; HMMIO hmmio; LONG ret; MMRESULT res; if (!create_test_file(test_file)) return; memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_DOS; mmio.pchBuffer = buffer; mmio.cchBuffer = sizeof(buffer); hmmio = mmioOpen(test_file, &mmio, MMIO_READ); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio == NULL) { DeleteFileA(test_file); return; } ret = mmioSeek(hmmio, 0, SEEK_END); ok(sizeof(RIFF_buf) == ret, "got %d\n", ret); ret = mmioRead(hmmio, data, sizeof(data)); ok(ret == 0, "expected %d, got %d\n", 0, ret); res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); res = mmioAdvance(hmmio, &mmio, MMIO_READ); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.pchNext == mmio.pchEndRead, "expected %p, got %p\n", mmio.pchEndRead, mmio.pchNext); mmioClose(hmmio, 0); DeleteFileA(test_file); }
int main(int argc, char **argv) { mihandle_t vol; midimhandle_t dim[NDIMS]; unsigned int sizes[NDIMS]; unsigned long start[NDIMS]; unsigned long count[NDIMS]; unsigned long howfar[NDIMS]; unsigned long location[NDIMS]; double *buffer,value; int r = 0; static char *dimorder[] = {"xspace", "yspace", "zspace"}; printf("Creating image with slice scaling!! \n"); create_test_file(); printf("Opening hyperslab-test2.mnc! \n"); r = miopen_volume("hyperslab-test2.mnc", MI2_OPEN_READ, &vol); if (r < 0) { TESTRPT("failed to open image", r); } #ifdef APPARENTORDER /* set the apparent dimension order to be xyz */ r = miset_apparent_dimension_order_by_name(vol, 3, dimorder); /* get the apparent dimensions and their sizes */ r = miget_volume_dimensions( vol, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, MI_DIMORDER_APPARENT, 3, dim); r = miget_dimension_sizes( dim, 3, sizes ); #else /* get the apparent dimensions and their sizes */ r = miget_volume_dimensions( vol, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, MI_DIMORDER_FILE, 3, dim); r = miget_dimension_sizes( dim, 3, sizes ); #endif if (r == MI_NOERROR) { printf("Sizes: %d, %d, %d\n", sizes[0], sizes[1], sizes[2]); } else { fprintf(stderr, "Error getting dimension sizes\n"); } /* try to play with hyperslab functions!! */ start[0] = 4; start[1] = 3; start[2] = 5; howfar[0] = 120; howfar[1] = 180; howfar[2] = 110; count[0] = howfar[0] - start[0]; count[1] = howfar[1] - start[1]; count[2] = howfar[2] - start[2]; /* Alocate memory for the hyperslab*/ buffer = (double *)malloc(count[0] * count[1] * count[2] * sizeof(double)); if (buffer == NULL) { fprintf(stderr, "Error allocation memory.\n"); exit(-1); } /* Get real value hyperslab*/ printf("\n"); printf("Getting a real value hyperslab \n"); printf("Starting at %d, %d, %d \n", start[0], start[1], start[2]); printf("Extending to %d, %d, %d \n", howfar[0], howfar[1], howfar[2]); printf("\n"); if (miget_real_value_hyperslab(vol,MI_TYPE_DOUBLE, start, count, buffer) < 0) { fprintf(stderr, "Could not get hyperslab.\n"); exit(-1); } /* set an arbitrary location to print values from */ location[0] = 70; location[1] = 100; location[2] = 104; printf("Test arbitrary location %d, %d, %d \n", location[0], location[1], location[2]); miget_real_value(vol, location, 3, &value); printf("Test from hyperslab: %f \n", *( buffer + (location[0] - start[0])*count[1]*count[2] + (location[1]- start[1]) * count[2] + (location[2]- start[2]))); printf("Test from voxel scaled: %f\n", value); miget_voxel_value(vol, location, 3, &value); printf("Test voxel value itself: %f\n", value); printf("\n"); printf("HMMMMMMMMMM! let's try something else \n"); printf("\n"); /* set another arbitrary location to print values from */ location[0] = 104; location[1] = 100; location[2] = 70; printf("Test arbitrary location %d, %d, %d \n", location[0], location[1], location[2]); miget_real_value(vol, location, 3, &value); printf("Test from hyperslab: %f \n", *( buffer + (location[0] - start[0])*count[1]*count[2] + (location[1]- start[1]) * count[2] + (location[2]- start[2]))); printf("Test from voxel scaled: %f\n", value); miget_voxel_value(vol, location, 3, &value); printf("Test voxel value itself: %f\n", value); /* close volume*/ miclose_volume(vol); if (error_cnt != 0) { fprintf(stderr, "%d error%s reported\n", error_cnt, (error_cnt == 1) ? "" : "s"); } else { fprintf(stderr, "\n No errors\n"); } return (error_cnt); }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Mem_Map_Test")); #if !defined (ACE_LACKS_MMAP) // = Initialize the temporary variable names ACE_TCHAR test_file[MAXPATHLEN + 1]; ACE_TCHAR temp_file1[MAXPATHLEN + 1]; ACE_TCHAR temp_file2[MAXPATHLEN + 1]; // Get the temporary directory // - 18 is for the filenames, ace_mem_map_temp_1 is the longest if (ACE::get_temp_dir (test_file, MAXPATHLEN - 18) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Temporary path too long\n")), -1); // Copy the temp directory to the other variables ACE_OS::strcpy (temp_file1, test_file); ACE_OS::strcpy (temp_file2, test_file); // Add the filenames to the end ACE_OS::strcat (test_file, ACE_TEXT ("ace_mem_map_test")); ACE_OS::strcat (temp_file1, ACE_TEXT ("ace_mem_map_temp_1")); ACE_OS::strcat (temp_file2, ACE_TEXT ("ace_mem_map_temp_2")); // First create a test file to work on if (create_test_file (test_file, LINE_LENGTH, NUM_LINES) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Create test file failed\n")), -1); ACE_Mem_Map mmap; // First memory map the test file if (mmap.map (test_file) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); // Now create a temporary file for intermediate processing ACE_HANDLE temp_file_handle = ACE_OS::open (temp_file1, O_RDWR | O_TRUNC | O_CREAT, ACE_DEFAULT_FILE_PERMS); if (temp_file_handle == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Open failed\n")), -1); // Reverse the original file and write the output to the temporary // file. reverse_file (temp_file_handle, (char *) mmap.addr (), mmap.size ()); ACE_OS::close (temp_file_handle); ACE_Mem_Map temp_mmap; // Now memory map the temporary file if (temp_mmap.map (temp_file1) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); if ((temp_file_handle = ACE_OS::open (temp_file2, O_RDWR | O_TRUNC | O_CREAT, ACE_DEFAULT_FILE_PERMS)) == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Open failed\n")), -1); // Now reverse the temporary file and write everything to the second // temporary file. reverse_file (temp_file_handle, (char *) temp_mmap.addr (), temp_mmap.size ()); ACE_OS::close (temp_file_handle); // Memory map the second temporary file ACE_Mem_Map temp_mmap2; if (temp_mmap2.map (temp_file2) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); // Now do a memcmp -- the orig file and the second temporary file // should be identical. ACE_ASSERT (ACE_OS::memcmp (temp_mmap2.addr (), mmap.addr (), mmap.size ()) == 0); // Delete the test file mmap.remove (); // Delete ACE_TEMP_TEST_FILE temp_mmap.remove (); // Delete ACE_TEMP_TEST_FILE_2 temp_mmap2.remove (); #else /* !ACE_LACKS_MMAP */ ACE_ERROR ((LM_INFO, ACE_TEXT ("mmap is not supported on this platform\n"))); #endif /* !ACE_LACKS_MMAP */ ACE_END_TEST; return 0; }
int main(int argc, char ** argv) { int num_errs; char root_file[] = FILE; char test_sim[] = SIM_NAME; char data_name[128]; char **names; int numpe; int i,dim, *size; size_t *nsizes; int ncnt; dsize_t num; double *data,*ref_data; hid_t fid, sid; if ( FILE_EXISTS(root_file) ) { danu_file_delete(root_file); } if ( H5_RETURN_FAIL(create_test_file(root_file) ) ) { DANU_ERROR_MESS("Failed to create the test file"); num_errs++; goto EXIT_NOW; } fid = danu_file_open_append(root_file); if ( H5_RETURN_FAIL(simulation_add(fid,test_sim,&sid) ) ) { DANU_ERROR_MESS("Failed to add simulation"); goto EXIT_NOW; } num_errs = 0; /* Arrays */ size = DANU_MALLOC(int,DIM); /* Write the data */ size[0] = 1; numpe = DUMMY_INT; sprintf(data_name,DATA_INT_NAME); if ( H5_RETURN_FAIL(data_write_int(sid,data_name,1,size,&numpe)) ) { DANU_ERROR_MESS("Failed to write int data"); num_errs++; goto EXIT_NOW; } dim = DIM; num = 1; for(i=0;i<dim;i++) { size[i] = NUMCELLS; num*=NUMCELLS; } data = DANU_MALLOC(double,num); sprintf(data_name,DATA_DBL_NAME); danu_rand_data_double(-5.0,5.0,num,data); if ( H5_RETURN_FAIL(data_write_double(sid,data_name,dim,size,data)) ) { DANU_ERROR_MESS("Failed to write double data"); num_errs++; goto EXIT_NOW; } /* Check data by reading */ ref_data = DANU_MALLOC(double,num); if ( H5_RETURN_FAIL(data_read_double(sid,data_name,dim,size,ref_data) ) ) { num_errs++; goto EXIT_NOW; } for(i=0;i<num;i++) { if ( ref_data[i] != data[i] ) { num_errs++; } } /* Find the number of datasets */ data_count(sid,&ncnt); printf("Found %d datasets\n",ncnt); names = DANU_MALLOC(char *,ncnt); nsizes = convert_int_to_size(ncnt,size); for(i=0;i<ncnt;i++) { size[i] = 128; names[i] = DANU_MALLOC(char,128); } data_list(sid,ncnt,nsizes,names); printf("Found the following datasets\n"); for(i=0;i<ncnt;i++) { printf("\t<%s>\n",names[i]); } /* Free memory */ for(i=0;i<ncnt;i++) { DANU_FREE(names[i]); } DANU_FREE(names); DANU_FREE(ref_data); DANU_FREE(data); DANU_FREE(size); /* Free HDF5 resources */ danu_group_close(sid); danu_file_close(fid); EXIT_NOW: printf("Found %d errors\n",num_errs); return num_errs; }
//----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { std::string path; std::string temp_path, root_path; // names of files and directories std::string test_file = "test.txt"; std::string subdir1_name = "subdir1"; std::string subdir2_name = "subdir2"; std::string subsubdir1_name = "subsubdir1"; std::string subdir_test_file = "subtest.txt"; // get the current working path from the system std::string working_path = get_current_path(); // attempt to create a temporary directory if( !get_temp_directory( temp_path ) ) return 5; // temp path just reported to be successfully created. test existence method if( !path_exists( temp_path ) ) return 1; // temp path is a path to a directory, so test is_directory if( !is_directory( temp_path ) ) return 2; // create a file in the temp path if( !create_test_file( temp_path, test_file ) ) return 8; // already know temp path is not a file, so test is_file for negative case if( is_file( temp_path ) ) return 3; // test whether the is file method reports the test file correctly path = combine_path( temp_path, test_file ); if( !is_file( path ) ) return 3; // attempt to remove the temporary directory if( !remove_directory( temp_path ) ) return 6; //-- // get another temporary directory this time call it the root path if( !get_temp_directory( root_path ) ) return 7; // create a file in the root path if( !create_test_file( root_path, test_file ) ) return 8; // create a directory in the root path std::string subdir1_path = combine_path( root_path, subdir1_name ); if( !get_directory( subdir1_path ) ) return 9; // create another directory in the root path std::string subdir2_path = combine_path( root_path, subdir2_name ); if( !get_directory( subdir2_path ) ) return 9; // create a directory in the first child directory of the root path std::string subsubdir1_path = combine_path( subdir1_path, subsubdir1_name ); if( !get_directory( subsubdir1_path ) ) return 9; // create a file in the child of the child directory if( !create_test_file( subsubdir1_path, subdir_test_file ) ) return 8; /* // get the subdirectories of the root std::vector<std::string> dirs = get_subdirectories( root_path ); for( std::vector<std::string>::iterator it = dirs.begin(); it != dirs.end(); it++ ) { printf( "dir: %s\n", it->c_str() ); } */ // test find file without recursion. search for the test file in the root if( !find_file( path, test_file, root_path ) ) return 1; // validate the path returned from find file temp_path = combine_path( root_path, test_file ); if( temp_path != path ) return 1; // test find file with recursion. search for the subtest file in the dirs if( !find_file( path, subdir_test_file, root_path, true ) ) return 1; temp_path = combine_path( subsubdir1_path, subdir_test_file ); if( temp_path != path ) return 1; // clean up the root path if( !remove_directory( root_path ) ) return 6; if( find_file( path, "gzserver", "/usr/local", true ) ) { printf( "path: %s\n", path.c_str() ); } return 0; }
static void test_mmio_buffer_pointer(void) { char test_file[MAX_PATH]; char buffer[5], data[16]; MMIOINFO mmio; HMMIO hmmio; LONG size, pos; MMRESULT res; if (!create_test_file(test_file)) return; memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_DOS; mmio.pchBuffer = buffer; mmio.cchBuffer = sizeof(buffer); hmmio = mmioOpen(test_file, &mmio, MMIO_READ); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio == NULL) { DeleteFileA(test_file); return; } /* the buffer is empty */ size = mmioRead(hmmio, data, 0); ok(size == 0, "expected 0, got %d\n", size); res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead); /* fill the buffer */ size = mmioAdvance(hmmio, &mmio, MMIO_READ); ok(mmio.pchEndRead-mmio.pchBuffer == sizeof(buffer), "got %d\n", (int)(mmio.pchEndRead-mmio.pchBuffer)); /* seeking to the same buffer chunk, the buffer is kept */ size = sizeof(buffer)/2; pos = mmioSeek(hmmio, size, SEEK_SET); ok(pos == size, "failed to seek, expected %d, got %d\n", size, pos); res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.lBufOffset == 0, "expected 0, got %d\n", mmio.lBufOffset); ok(mmio.pchNext-mmio.pchBuffer == size, "expected %d, got %d\n", size, (int)(mmio.pchNext-mmio.pchBuffer)); ok(mmio.pchEndRead-mmio.pchBuffer == sizeof(buffer), "got %d\n", (int)(mmio.pchEndRead-mmio.pchBuffer)); /* seeking to another buffer chunk, the buffer is empty */ size = sizeof(buffer) * 3 + sizeof(buffer) / 2; pos = mmioSeek(hmmio, size, SEEK_SET); ok(pos == size, "failed to seek, got %d\n", pos); res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.lBufOffset == size, "expected %d, got %d\n", size, mmio.lBufOffset); ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext); ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead); /* reading a lot (as sizeof(data) > mmio.cchBuffer), the buffer is empty */ size = mmioRead(hmmio, data, sizeof(data)); ok(size == sizeof(data), "failed to read, got %d\n", size); res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.lBufOffset == pos+size, "expected %d, got %d\n", pos+size, mmio.lBufOffset); ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext); ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead); mmioClose(hmmio, 0); DeleteFileA(test_file); }
static void test_mmioSeek(void) { HMMIO hmmio; MMIOINFO mmio; LONG end, pos; const LONG size = sizeof(RIFF_buf), offset = 16; char test_file[MAX_PATH]; MMRESULT res; HFILE hfile; OFSTRUCT ofs; /* test memory file */ memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_MEM; mmio.pchBuffer = (char*)&RIFF_buf; mmio.cchBuffer = sizeof(RIFF_buf); hmmio = mmioOpen(NULL, &mmio, MMIO_READ); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio != NULL) { /* seek to the end */ end = mmioSeek(hmmio, 0, SEEK_END); todo_wine ok(end == size, "expected %d, got %d\n", size, end); /* seek backward from the end */ pos = mmioSeek(hmmio, offset, SEEK_END); ok(pos == size-offset, "expected %d, got %d\n", size-offset, pos); mmioClose(hmmio, 0); } if (!create_test_file(test_file)) return; /* test standard file without buffering */ hmmio = NULL; memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_DOS; mmio.pchBuffer = 0; mmio.cchBuffer = 0; hmmio = mmioOpen(test_file, &mmio, MMIO_READ); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio != NULL) { /* seek to the end */ end = mmioSeek(hmmio, 0, SEEK_END); ok(end == size, "expected %d, got %d\n", size, end); /* test MMIOINFO values */ res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext); ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead); ok(mmio.pchEndWrite == mmio.pchBuffer + mmio.cchBuffer, "expected %p + %d, got %p\n", mmio.pchBuffer, mmio.cchBuffer, mmio.pchEndWrite); todo_wine ok(mmio.lBufOffset == size, "expected %d, got %d\n", size, mmio.lBufOffset); ok(mmio.lDiskOffset == size, "expected %d, got %d\n", size, mmio.lDiskOffset); /* seek backward from the end */ pos = mmioSeek(hmmio, offset, SEEK_END); ok(pos == size-offset, "expected %d, got %d\n", size-offset, pos); mmioClose(hmmio, 0); } /* test standard file with buffering */ hmmio = NULL; memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_DOS; mmio.pchBuffer = 0; mmio.cchBuffer = 0; hmmio = mmioOpen(test_file, &mmio, MMIO_READ | MMIO_ALLOCBUF); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio != NULL) { /* seek to the end */ end = mmioSeek(hmmio, 0, SEEK_END); ok(end == size, "expected %d, got %d\n", size, end); /* test MMIOINFO values */ res = mmioGetInfo(hmmio, &mmio, 0); ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res); ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext); ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead); ok(mmio.pchEndWrite == mmio.pchBuffer + mmio.cchBuffer, "expected %p + %d, got %p\n", mmio.pchBuffer, mmio.cchBuffer, mmio.pchEndWrite); ok(mmio.lBufOffset == end, "expected %d, got %d\n", end, mmio.lBufOffset); ok(mmio.lDiskOffset == size, "expected %d, got %d\n", size, mmio.lDiskOffset); /* seek backward from the end */ pos = mmioSeek(hmmio, offset, SEEK_END); ok(pos == size-offset, "expected %d, got %d\n", size-offset, pos); mmioClose(hmmio, 0); } /* test seek position inheritance from standard file handle */ hfile = OpenFile(test_file, &ofs, OF_READ); ok(hfile != HFILE_ERROR, "Failed to open the file, err %d\n", GetLastError()); if (hfile != HFILE_ERROR) { pos = _llseek(hfile, offset, SEEK_SET); ok(pos != HFILE_ERROR, "Failed to seek, err %d\n", GetLastError()); memset(&mmio, 0, sizeof(mmio)); mmio.fccIOProc = FOURCC_DOS; mmio.adwInfo[0] = (DWORD)hfile; hmmio = mmioOpen(NULL, &mmio, MMIO_READ | MMIO_DENYWRITE | MMIO_ALLOCBUF); ok(hmmio != NULL, "mmioOpen error %u\n", mmio.wErrorRet); if (hmmio != NULL) { pos = mmioSeek(hmmio, 0, SEEK_CUR); ok(pos == offset, "expected %d, got %d\n", offset, pos); mmioClose(hmmio, 0); } } DeleteFileA(test_file); }
static void test_GetPrivateProfileString(const char *content, const char *descript) { DWORD ret, len; CHAR buf[MAX_PATH]; CHAR def_val[MAX_PATH]; CHAR path[MAX_PATH]; CHAR windir[MAX_PATH]; /* NT series crashes on r/o empty strings, so pass an r/w empty string and check for modification */ CHAR emptystr[MAX_PATH] = ""; LPSTR tempfile; static const char filename[] = ".\\winetest.ini"; trace("test_GetPrivateProfileStringA: %s\n", descript); if(!lstrcmpA(descript, "CR only")) { SetLastError(0xdeadbeef); ret = GetPrivateProfileStringW(NULL, NULL, NULL, NULL, 0, NULL); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("Win9x and WinME don't handle 'CR only' correctly\n"); return; } } create_test_file(filename, content, lstrlenA(content)); /* Run this test series with caching. Wine won't cache profile files younger than 2.1 seconds. */ Sleep(2500); /* lpAppName is NULL */ memset(buf, 0xc, sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(NULL, "name1", "default", buf, MAX_PATH, filename); ok(ret == 18 || broken(ret == 19), /* Win9x and WinME */ "Expected 18, got %d\n", ret); len = lstrlenA("section1") + sizeof(CHAR) + lstrlenA("section2") + 2 * sizeof(CHAR); ok(!memcmp(buf, "section1\0section2\0\0", len), "Expected \"section1\\0section2\\0\\0\", got \"%s\"\n", buf); /* lpAppName is empty */ memset(buf, 0xc, sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is missing */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("notasection", "name1", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpAppName is empty, lpDefault is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", NULL, buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, lpDefault is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "", buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, lpDefault has trailing blank characters */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "default "); ret = GetPrivateProfileStringA(emptystr, "name1", def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, many blank characters in lpDefault */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "one two "); ret = GetPrivateProfileStringA(emptystr, "name1", def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "one two"), "Expected \"one two\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpAppName is empty, blank character but not trailing in lpDefault */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(emptystr, "name1", "one two", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "one two"), "Expected \"one two\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "AppName modified\n"); /* lpKeyName is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", NULL, "default", buf, MAX_PATH, filename); ok(ret == 18, "Expected 18, got %d\n", ret); ok(!memcmp(buf, "name1\0name2\0name4\0", ret + 1), "Expected \"name1\\0name2\\0name4\\0\", got \"%s\"\n", buf); /* lpKeyName is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is missing */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "notakey", "default", buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpKeyName is empty, lpDefault is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, NULL, buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is empty, lpDefault is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", emptystr, "", buf, MAX_PATH, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); /* lpKeyName is empty, lpDefault has trailing blank characters */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); /* lpDefault must be writable (trailing blanks are removed inplace in win9x) */ lstrcpyA(def_val, "default "); ret = GetPrivateProfileStringA("section1", emptystr, def_val, buf, MAX_PATH, filename); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); ok(emptystr_ok(emptystr), "KeyName modified\n"); if (0) /* crashes */ { /* lpReturnedString is NULL */ ret = GetPrivateProfileStringA("section1", "name1", "default", NULL, MAX_PATH, filename); } /* lpFileName is NULL */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, NULL); ok(ret == 7 || broken(ret == 0), /* Win9x, WinME */ "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default") || broken(!lstrcmpA(buf, "kumquat")), /* Win9x, WinME */ "Expected \"default\", got \"%s\"\n", buf); /* lpFileName is empty */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, ""); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* lpFileName is nonexistent */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, "nonexistent"); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); /* nSize is 0 */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 0, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, "kumquat"), "Expected buf to be unchanged, got \"%s\"\n", buf); /* nSize is exact size of output */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 4, filename); ok(ret == 3, "Expected 3, got %d\n", ret); ok(!lstrcmpA(buf, "val"), "Expected \"val\", got \"%s\"\n", buf); /* nSize has room for NULL terminator */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, 5, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* output is 1 character */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name4", "default", buf, MAX_PATH, filename); ok(ret == 1, "Expected 1, got %d\n", ret); ok(!lstrcmpA(buf, "a"), "Expected \"a\", got \"%s\"\n", buf); /* output is 1 character, no room for NULL terminator */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name4", "default", buf, 1, filename); ok(ret == 0, "Expected 0, got %d\n", ret); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); /* lpAppName is NULL, not enough room for final section name */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA(NULL, "name1", "default", buf, 16, filename); ok(ret == 14, "Expected 14, got %d\n", ret); len = lstrlenA("section1") + 2 * sizeof(CHAR); todo_wine ok(!memcmp(buf, "section1\0secti\0\0", ret + 2) || broken(!memcmp(buf, "section1\0\0", len)), /* Win9x, WinME */ "Expected \"section1\\0secti\\0\\0\", got \"%s\"\n", buf); /* lpKeyName is NULL, not enough room for final key name */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", NULL, "default", buf, 16, filename); ok(ret == 14, "Expected 14, got %d\n", ret); todo_wine ok(!memcmp(buf, "name1\0name2\0na\0\0", ret + 2) || broken(!memcmp(buf, "name1\0name2\0n\0\0", ret + 1)), /* Win9x, WinME */ "Expected \"name1\\0name2\\0na\\0\\0\", got \"%s\"\n", buf); /* key value has quotation marks which are stripped */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name2", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val2"), "Expected \"val2\", got \"%s\"\n", buf); /* case does not match */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* only filename is used */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, "winetest.ini"); ok(ret == 7, "Expected 7, got %d\n", ret); ok(!lstrcmpA(buf, "default"), "Expected \"default\", got \"%s\"\n", buf); GetWindowsDirectoryA(windir, MAX_PATH); SetLastError(0xdeadbeef); ret = GetTempFileNameA(windir, "pre", 0, path); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { skip("Not allowed to create a file in the Windows directory\n"); DeleteFileA(filename); return; } tempfile = strrchr(path, '\\') + 1; create_test_file(path, content, lstrlenA(content)); /* only filename is used, file exists in windows directory */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "NaMe1", "default", buf, MAX_PATH, tempfile); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* successful case */ memset(buf, 0xc,sizeof(buf)); lstrcpyA(buf, "kumquat"); ret = GetPrivateProfileStringA("section1", "name1", "default", buf, MAX_PATH, filename); ok(ret == 4, "Expected 4, got %d\n", ret); ok(!lstrcmpA(buf, "val1"), "Expected \"val1\", got \"%s\"\n", buf); /* Existing section with no keys in an existing file */ memset(buf, 0xc,sizeof(buf)); SetLastError(0xdeadbeef); ret=GetPrivateProfileStringA("section2", "DoesntExist", "", buf, MAX_PATH, filename); ok( ret == 0, "expected return size 0, got %d\n", ret ); ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf); todo_wine ok( GetLastError() == 0xdeadbeef || GetLastError() == ERROR_FILE_NOT_FOUND /* Win 7 */, "expected 0xdeadbeef or ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); DeleteFileA(path); DeleteFileA(filename); }
int main ( void ) { mihandle_t vol; int r = 0; midimhandle_t dim[NDIMS]; misize_t lengths[NDIMS]; midimhandle_t copy_dim[NDIMS]; misize_t coords[NDIMS]; misize_t count[NDIMS]; int i, j; unsigned char * Atmp; midimclass_t dimension_class; int ndims; Atmp = ( unsigned char * ) malloc ( CX * CY * CZ * sizeof ( unsigned char ) ); create_test_file(); printf ( " \n" ); printf ( "Opening vector-dimension file!\n" ); printf ( " \n" ); r = miopen_volume ( "example_vector2.mnc", MI2_OPEN_READ, &vol ); if ( r < 0 ) { TESTRPT ( "failed to open vector_dimension volume", r ); } r = miget_volume_dimension_count ( vol, MI_DIMCLASS_ANY, MI_DIMATTR_REGULARLY_SAMPLED, &ndims ); if ( r < 0 ) { TESTRPT ( "failed to get number of dimensions", r ); } printf ( "Total number of dimensions : %d \n", ndims ); r = miget_volume_dimensions ( vol, MI_DIMCLASS_ANY, MI_DIMATTR_REGULARLY_SAMPLED, MI_DIMORDER_FILE, NDIMS, dim ); if ( r < 0 ) { TESTRPT ( "Could not get dimension handles from volume", r ); } r = miget_dimension_sizes ( dim, NDIMS, lengths ); if ( r < 0 ) { TESTRPT ( " more trouble", r ); } printf ( "Dimension Size in file order : " ); for ( i = 0; i < NDIMS; i++ ) { printf ( " %lld ", lengths[i] ); } printf ( " \n" ); for ( i = 0; i < NDIMS; i++ ) { r = miget_dimension_class ( dim[i], &dimension_class ); if ( r < 0 ) { TESTRPT ( "failed to get dimension class", r ); } if ( dimension_class == MI_DIMCLASS_RECORD ) { printf ( "Dim class RECORD present check dim name for *vector_dimension*\n" ); } } printf ( "Let's get the first 10 data values of each vector component (file order) \n" ); coords[0] = coords[1] = coords[2] = 0; count[0] = CZ; count[1] = CY; count[2] = CX; count[3] = 1; printf ( " FILE ORDER --> zspace, yspace, xspace, vector_dimension \n" ); for ( i = 0; i < 3; i++ ) { printf ( "Vector Componenet %d \n", i + 1 ); coords[3] = i; r = miget_voxel_value_hyperslab ( vol, MI_TYPE_UBYTE, coords, count, Atmp ); if ( r < 0 ) { TESTRPT ( "Failed to operate hyperslab function", r ); } for ( j = 0; j < 10; j++ ) { printf ( " %u ", Atmp[j] ); } printf ( " \n" ); } printf ( "APPARENT ORDER --> vector_dimension, zspace, yspace, xspace\n" ); // Set the apparent dimension order copy_dim[0] = dim[3]; copy_dim[1] = dim[0]; copy_dim[2] = dim[1]; copy_dim[3] = dim[2]; r = miset_apparent_dimension_order ( vol, NDIMS, copy_dim ); if ( r < 0 ) { TESTRPT ( "failed to set apparent order", r ); } coords[1] = coords[2] = coords[3] = 0; count[0] = 1; //must always be one count[1] = CZ; count[2] = CY; count[3] = CZ; printf ( "APPARENT ORDER SET \n" ); for ( i = 0; i < 3; i++ ) { printf ( "Vector Componenet %d \n", i + 1 ); coords[0] = i; r = miget_voxel_value_hyperslab ( vol, MI_TYPE_UBYTE, coords, count, Atmp ); if ( r < 0 ) { TESTRPT ( "Failed to operate hyperslab function", r ); } for ( j = 0; j < 10; j++ ) { printf ( " %u ", Atmp[j] ); } printf ( " \n" ); } if ( error_cnt != 0 ) { fprintf ( stderr, "%d error%s reported\n", error_cnt, ( error_cnt == 1 ) ? "" : "s" ); } else { fprintf ( stderr, "No errors\n" ); } return ( error_cnt ); }