diff --git a/matlab/test/test_fiff_finish_writing_raw.m b/matlab/test/test_fiff_finish_writing_raw.m new file mode 100644 index 0000000..0d5b5c9 --- /dev/null +++ b/matlab/test/test_fiff_finish_writing_raw.m @@ -0,0 +1,45 @@ +function test_suite=test_fiff_finish_writing_raw + try test_functions=localfunctions(); catch + end + initTestSuite; + +function test_fiff_readwrite_raw_() +% Test a round trip of reading and writing raw data +% this function calls the following relevant m-files: +% - fiff_read_meas_info +% - fiff_setup_read_raw +% - fiff_read_raw_segment +% - fiff_start_writing_raw +% - fiff_write_int +% - fiff_write_raw_buffer +% - fiff_finish_writing_raw + +FIFF = fiff_define_constants; + +% read +pathstr = fileparts(mfilename('fullpath')); +fname = fullfile(pathstr, 'data', 'test_raw.fif'); +info = fiff_read_meas_info(fname); +raw = fiff_setup_read_raw(fname); +[data, times] = fiff_read_raw_segment(raw); + +% write -> note that the original data was in 24 chunks of 600 samples, the +% data is saved out as a single chunk of 14400 samples +fnamenew = strrep(fname, 'test_', 'testout_'); +[outfid, cals] = fiff_start_writing_raw(fnamenew, info); +fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, raw.first_samp); +fiff_write_int(outfid, FIFF.FIFF_DATA_SKIP, 0); +fiff_write_raw_buffer(outfid, data, cals); +fiff_finish_writing_raw(outfid); + +% read the new file +rawnew = fiff_setup_read_raw(fnamenew); +[datanew, timesnew] = fiff_read_raw_segment(rawnew); + +% compare +assertEqual(data, datanew); +assertEqual(times, timesnew); + +% clean up +delete(fnamenew); + diff --git a/matlab/test/test_fiff_read_meas_info.m b/matlab/test/test_fiff_read_meas_info.m new file mode 100644 index 0000000..e0a1a67 --- /dev/null +++ b/matlab/test/test_fiff_read_meas_info.m @@ -0,0 +1,45 @@ +function test_suite=test_fiff_read_meas_info + try test_functions=localfunctions(); catch + end + initTestSuite; + +function test_fiff_readwrite_raw_() +% Test a round trip of reading and writing raw data +% this function calls the following relevant m-files: +% - fiff_read_meas_info +% - fiff_setup_read_raw +% - fiff_read_raw_segment +% - fiff_start_writing_raw +% - fiff_write_int +% - fiff_write_raw_buffer +% - fiff_finish_writing_raw + +FIFF = fiff_define_constants; + +% read +pathstr = fileparts(mfilename('fullpath')); +fname = fullfile(pathstr, 'data', 'test_raw.fif'); +info = fiff_read_meas_info(fname); +raw = fiff_setup_read_raw(fname); +[data, times] = fiff_read_raw_segment(raw); + +% write -> note that the original data was in 24 chunks of 600 samples, the +% data is saved out as a single chunk of 14400 samples +fnamenew = strrep(fname, 'test_', 'testout_'); +[outfid, cals] = fiff_start_writing_raw(fnamenew, info); +fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, raw.first_samp); +fiff_write_int(outfid, FIFF.FIFF_DATA_SKIP, 0); +fiff_write_raw_buffer(outfid, data, cals); +fiff_finish_writing_raw(outfid); + +% read the new file +rawnew = fiff_setup_read_raw(fnamenew); +[datanew, timesnew] = fiff_read_raw_segment(rawnew); + +% compare +assertEqual(data, datanew); +assertEqual(times, timesnew); + +% clean up +delete(fnamenew); + diff --git a/matlab/test/test_fiff_read_tag.m b/matlab/test/test_fiff_read_tag.m index 7a31f66..12b07a2 100644 --- a/matlab/test/test_fiff_read_tag.m +++ b/matlab/test/test_fiff_read_tag.m @@ -4,8 +4,46 @@ initTestSuite; function test_fiff_read_tag_() -% Test fiff_read_tag.m -% -% This is a placeholder function, referencing the below test function, -% which should fail if fiff_read_tag does not work properly -test_fiff_open +% Test fiff_open.m + +if ispc + % I don't know what happens with the unit testing actually, if the + % function returns without actually testing anything + return; +end + +f = which('test_fiff_define_constants.m'); +[p,f,e] = fileparts(f); + +% load the reference trees +load(fullfile(p, 'data', 'test_fiftrees_ref.mat')); + +fname = fullfile(p, 'data', 'test_raw.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.raw)); + +fname = fullfile(p, 'data', 'test_long_raw.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.longraw)); + +fname = fullfile(p, 'data', 'test_raw-eve.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.raweve)); + +fname = fullfile(p, 'data', 'test-eve.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.eve)); + +fname = fullfile(p, 'data', 'test-ave.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.ave)); + +fname = fullfile(p, 'data', 'test-cov.fif'); +[fid, tree, dir] = fiff_open(fname); +fclose(fid); +assert(isequal(tree, trees.cov)); diff --git a/matlab/test/test_fiff_start_writing_raw.m b/matlab/test/test_fiff_start_writing_raw.m new file mode 100644 index 0000000..a8a7073 --- /dev/null +++ b/matlab/test/test_fiff_start_writing_raw.m @@ -0,0 +1,45 @@ +function test_suite=test_fiff_start_writing_raw + try test_functions=localfunctions(); catch + end + initTestSuite; + +function test_fiff_readwrite_raw_() +% Test a round trip of reading and writing raw data +% this function calls the following relevant m-files: +% - fiff_read_meas_info +% - fiff_setup_read_raw +% - fiff_read_raw_segment +% - fiff_start_writing_raw +% - fiff_write_int +% - fiff_write_raw_buffer +% - fiff_finish_writing_raw + +FIFF = fiff_define_constants; + +% read +pathstr = fileparts(mfilename('fullpath')); +fname = fullfile(pathstr, 'data', 'test_raw.fif'); +info = fiff_read_meas_info(fname); +raw = fiff_setup_read_raw(fname); +[data, times] = fiff_read_raw_segment(raw); + +% write -> note that the original data was in 24 chunks of 600 samples, the +% data is saved out as a single chunk of 14400 samples +fnamenew = strrep(fname, 'test_', 'testout_'); +[outfid, cals] = fiff_start_writing_raw(fnamenew, info); +fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, raw.first_samp); +fiff_write_int(outfid, FIFF.FIFF_DATA_SKIP, 0); +fiff_write_raw_buffer(outfid, data, cals); +fiff_finish_writing_raw(outfid); + +% read the new file +rawnew = fiff_setup_read_raw(fnamenew); +[datanew, timesnew] = fiff_read_raw_segment(rawnew); + +% compare +assertEqual(data, datanew); +assertEqual(times, timesnew); + +% clean up +delete(fnamenew); + diff --git a/matlab/test/test_fiff_write_int.m b/matlab/test/test_fiff_write_int.m new file mode 100644 index 0000000..43b8016 --- /dev/null +++ b/matlab/test/test_fiff_write_int.m @@ -0,0 +1,45 @@ +function test_suite=test_fiff_write_int + try test_functions=localfunctions(); catch + end + initTestSuite; + +function test_fiff_readwrite_raw_() +% Test a round trip of reading and writing raw data +% this function calls the following relevant m-files: +% - fiff_read_meas_info +% - fiff_setup_read_raw +% - fiff_read_raw_segment +% - fiff_start_writing_raw +% - fiff_write_int +% - fiff_write_raw_buffer +% - fiff_finish_writing_raw + +FIFF = fiff_define_constants; + +% read +pathstr = fileparts(mfilename('fullpath')); +fname = fullfile(pathstr, 'data', 'test_raw.fif'); +info = fiff_read_meas_info(fname); +raw = fiff_setup_read_raw(fname); +[data, times] = fiff_read_raw_segment(raw); + +% write -> note that the original data was in 24 chunks of 600 samples, the +% data is saved out as a single chunk of 14400 samples +fnamenew = strrep(fname, 'test_', 'testout_'); +[outfid, cals] = fiff_start_writing_raw(fnamenew, info); +fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, raw.first_samp); +fiff_write_int(outfid, FIFF.FIFF_DATA_SKIP, 0); +fiff_write_raw_buffer(outfid, data, cals); +fiff_finish_writing_raw(outfid); + +% read the new file +rawnew = fiff_setup_read_raw(fnamenew); +[datanew, timesnew] = fiff_read_raw_segment(rawnew); + +% compare +assertEqual(data, datanew); +assertEqual(times, timesnew); + +% clean up +delete(fnamenew); + diff --git a/matlab/test/test_fiff_write_raw_buffer.m b/matlab/test/test_fiff_write_raw_buffer.m new file mode 100644 index 0000000..5150a9f --- /dev/null +++ b/matlab/test/test_fiff_write_raw_buffer.m @@ -0,0 +1,45 @@ +function test_suite=test_fiff_write_raw_buffer + try test_functions=localfunctions(); catch + end + initTestSuite; + +function test_fiff_readwrite_raw_() +% Test a round trip of reading and writing raw data +% this function calls the following relevant m-files: +% - fiff_read_meas_info +% - fiff_setup_read_raw +% - fiff_read_raw_segment +% - fiff_start_writing_raw +% - fiff_write_int +% - fiff_write_raw_buffer +% - fiff_finish_writing_raw + +FIFF = fiff_define_constants; + +% read +pathstr = fileparts(mfilename('fullpath')); +fname = fullfile(pathstr, 'data', 'test_raw.fif'); +info = fiff_read_meas_info(fname); +raw = fiff_setup_read_raw(fname); +[data, times] = fiff_read_raw_segment(raw); + +% write -> note that the original data was in 24 chunks of 600 samples, the +% data is saved out as a single chunk of 14400 samples +fnamenew = strrep(fname, 'test_', 'testout_'); +[outfid, cals] = fiff_start_writing_raw(fnamenew, info); +fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, raw.first_samp); +fiff_write_int(outfid, FIFF.FIFF_DATA_SKIP, 0); +fiff_write_raw_buffer(outfid, data, cals); +fiff_finish_writing_raw(outfid); + +% read the new file +rawnew = fiff_setup_read_raw(fnamenew); +[datanew, timesnew] = fiff_read_raw_segment(rawnew); + +% compare +assertEqual(data, datanew); +assertEqual(times, timesnew); + +% clean up +delete(fnamenew); +