1+ classdef ScalarCompoundTest < tests .abstract .NwbTestCase
2+ % ScalarCompoundTest - Test that a scalar compound dataset is imported correctly
3+
4+ methods (TestMethodSetup )
5+ function setupMethod(testCase )
6+ % Use a fixture to create a temporary working directory
7+ testCase .applyFixture(matlab .unittest .fixtures .WorkingFolderFixture );
8+ end
9+ end
10+
11+ methods (Test )
12+ function testScalarCompoundIO(testCase )
13+
14+ % Generate the compound test schema using fixture
15+ testCase .applyTestSchemaFixture(' rrs' );
16+ testCase .applyTestSchemaFixture(' cs' );
17+
18+ % Set up file with scalar compound dataset
19+ nwb = tests .factory .NWBFile();
20+
21+ ts = tests .factory .TimeSeriesWithTimestamps();
22+ nwb .acquisition .set(' timeseries' , ts );
23+
24+ % Create a structure matching the compound type definition.
25+ data = struct(...
26+ ' integer' , int32(0 ), ...
27+ ' float' , 0 , ...
28+ ' text' , ' test' , ...
29+ ' boolean' , false , ...
30+ ' reference' , types .untyped .ObjectView(ts ));
31+
32+ % Create data type and add to nwb object
33+ scalarCompound = types .cs .ScalarCompoundMixedData(' data' , data );
34+ nwb .analysis .set(' ScalarCompound' , scalarCompound );
35+
36+ % Export
37+ fileName = testCase .getRandomFilename();
38+ nwbExport(nwb , fileName );
39+
40+ % Read
41+ nwbIn = nwbRead(fileName , ' ignorecache' );
42+ scalarCompoundIn = nwbIn .analysis .get(' ScalarCompound' );
43+
44+ % Verify that dataset was stored as scalar/singleton dataset
45+ info = h5info(fileName , ' /analysis/ScalarCompound/data' );
46+ testCase .verifyEqual(info .Dataspace .Type , ' scalar' , ...
47+ ' Expected compound dataset to be saved as scalar/singleton dataset (H5S_SCALAR)' )
48+
49+ % Verify that subtypes were properly postprocessed on read
50+ testCase .verifyClass(scalarCompoundIn .data .float , ' double' )
51+ testCase .verifyClass(scalarCompoundIn .data .text , ' char' )
52+ testCase .verifyClass(scalarCompoundIn .data .boolean , ' logical' )
53+ testCase .verifyClass(scalarCompoundIn .data .reference , ' types.untyped.ObjectView' )
54+ testCase .verifyEqual(scalarCompoundIn .data .text , ' test' )
55+ end
56+ end
57+ end
0 commit comments