Skip to content

Commit 7fab066

Browse files
committed
completify: add missing Block functions and tests
1 parent ba731a6 commit 7fab066

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

+nix/Block.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
da.write_all(data);
4545
end
4646

47+
function hasDA = has_data_array(obj, id_or_name)
48+
hasDA = nix_mx('Block::hasDataArray', obj.nix_handle, id_or_name);
49+
end;
50+
4751
function delCheck = delete_data_array(obj, del)
4852
[delCheck, obj.dataArraysCache] = nix.Utils.delete_entity(obj, ...
4953
del, 'nix.DataArray', 'Block::deleteDataArray', obj.dataArraysCache);
@@ -58,6 +62,10 @@
5862
obj.sourcesCache.lastUpdate = 0;
5963
end;
6064

65+
function hasSource = has_source(obj, id_or_name)
66+
hasSource = nix_mx('Block::hasSource', obj.nix_handle, id_or_name);
67+
end;
68+
6169
function delCheck = delete_source(obj, del)
6270
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
6371
del, 'nix.Source', 'Block::deleteSource', obj.sourcesCache);

nix_mx.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ void mexFunction(int nlhs,
114114
.reg("sources", &nix::Block::sources)
115115
.reg("tags", &nix::Block::tags)
116116
.reg("multiTags", &nix::Block::multiTags)
117+
.reg("hasDataArray", GETBYSTR(bool, nix::Block, hasDataArray))
118+
.reg("hasSource", GETBYSTR(bool, nix::Block, hasSource))
117119
.reg("hasTag", GETBYSTR(bool, nix::Block, hasTag))
118120
.reg("hasMultiTag", GETBYSTR(bool, nix::Block, hasMultiTag))
119121
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Block, getDataArray))

tests/TestBlock.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
funcs{end+1} = @test_open_tag;
2222
funcs{end+1} = @test_open_multitag;
2323
funcs{end+1} = @test_open_source;
24+
funcs{end+1} = @test_has_data_array;
25+
funcs{end+1} = @test_has_source;
2426
funcs{end+1} = @test_has_multitag;
2527
funcs{end+1} = @test_has_tag;
2628
funcs{end+1} = @test_set_metadata;
@@ -371,3 +373,37 @@
371373

372374
assert(strcmp(b.open_metadata.name, 'testSection'));
373375
end
376+
377+
%% Test: nix.Block has nix.DataArray by ID or name
378+
function [] = test_has_data_array( varargin )
379+
fileName = 'testRW.h5';
380+
daName = 'hasDataArrayTest';
381+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
382+
b = f.createBlock('testblock', 'nixBlock');
383+
da = b.create_data_array(daName, 'nixDataArray', 'double', [1 2]);
384+
daID = da.id;
385+
386+
assert(~b.has_data_array('I do not exist'));
387+
assert(b.has_data_array(daName));
388+
389+
clear da b f;
390+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
391+
assert(f.blocks{1}.has_data_array(daID));
392+
end
393+
394+
%% Test: nix.Block has nix.Source by ID or name
395+
function [] = test_has_source( varargin )
396+
fileName = 'testRW.h5';
397+
sName = 'sourcetest1';
398+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
399+
b = f.createBlock('testblock', 'nixBlock');
400+
s = b.create_source(sName, 'nixSource');
401+
sID = s.id;
402+
403+
assert(~b.has_source('I do not exist'));
404+
assert(b.has_source(sName));
405+
406+
clear s b f;
407+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
408+
assert(f.blocks{1}.has_source(sID));
409+
end

0 commit comments

Comments
 (0)