|
4 | 4 |
|
5 | 5 | funcs = {};
|
6 | 6 | funcs{end+1} = @test_open_data;
|
| 7 | + funcs{end+1} = @test_get_set_link_type; |
| 8 | + funcs{end+1} = @test_set_data; |
7 | 9 | end
|
8 | 10 |
|
9 | 11 | %% Test: Open data from feature
|
|
17 | 19 | getFeature = getTag.features{1};
|
18 | 20 | assert(~isempty(getFeature.open_data));
|
19 | 21 | end
|
| 22 | + |
| 23 | +%% Test: Get and set nix.LinkType |
| 24 | +function [] = test_get_set_link_type ( varargin ) |
| 25 | + fileName = 'testRW.h5'; |
| 26 | + f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite); |
| 27 | + b = f.createBlock('featureTest', 'nixBlock'); |
| 28 | + da = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]); |
| 29 | + t = b.create_tag('featureTest', 'nixTag', [1, 2]); |
| 30 | + feat = t.add_feature(b.dataArrays{1}, nix.LinkType.Tagged); |
| 31 | + |
| 32 | + try |
| 33 | + feat.linkType = ''; |
| 34 | + catch ME |
| 35 | + assert(strcmp(ME.identifier, 'nix:arg:inval')); |
| 36 | + end; |
| 37 | + try |
| 38 | + feat.linkType = {}; |
| 39 | + catch ME |
| 40 | + assert(strcmp(ME.identifier, 'nix:arg:inval')); |
| 41 | + end; |
| 42 | + try |
| 43 | + feat.linkType = 1; |
| 44 | + catch ME |
| 45 | + assert(strcmp(ME.identifier, 'nix:arg:inval')); |
| 46 | + end; |
| 47 | + assert(f.blocks{1}.tags{1}.features{1}.linkType == 0); |
| 48 | + |
| 49 | + feat.linkType = nix.LinkType.Untagged; |
| 50 | + assert(f.blocks{1}.tags{1}.features{1}.linkType == 1); |
| 51 | + |
| 52 | + feat.linkType = nix.LinkType.Indexed; |
| 53 | + |
| 54 | + clear feat t da b f; |
| 55 | + f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly); |
| 56 | + assert(f.blocks{1}.tags{1}.features{1}.linkType == 2); |
| 57 | +end |
| 58 | + |
| 59 | +%% Test: Set data by entity, ID and name |
| 60 | +function [] = test_set_data ( varargin ) |
| 61 | + fileName = 'testRW.h5'; |
| 62 | + daName1 = 'featTestDA1'; |
| 63 | + daName2 = 'featTestDA2'; |
| 64 | + daName3 = 'featTestDA3'; |
| 65 | + daName4 = 'featTestDA4'; |
| 66 | + daType = 'nixDataArray'; |
| 67 | + daData = [1 2 3 4 5 6]; |
| 68 | + f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite); |
| 69 | + b = f.createBlock('featureTest', 'nixBlock'); |
| 70 | + da1 = b.create_data_array(daName1, daType, 'double', daData); |
| 71 | + da2 = b.create_data_array(daName2, daType, 'double', daData); |
| 72 | + da3 = b.create_data_array(daName3, daType, 'double', daData); |
| 73 | + da4 = b.create_data_array(daName4, daType, 'double', daData); |
| 74 | + t = b.create_tag('featureTest', 'nixTag', [1, 2]); |
| 75 | + feat = t.add_feature(b.dataArrays{1}, nix.LinkType.Tagged); |
| 76 | + |
| 77 | + assert(strcmp(feat.open_data.name, daName1)); |
| 78 | + feat.set_data(da2); |
| 79 | + assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName2)); |
| 80 | + feat.set_data(da3.id); |
| 81 | + assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName3)); |
| 82 | + feat.set_data(da4.name); |
| 83 | + |
| 84 | + clear feat t da4 da3 da2 da1 b f; |
| 85 | + f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly); |
| 86 | + assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName4)); |
| 87 | +end |
0 commit comments