Skip to content

Commit cc90ae9

Browse files
committed
addGroupEntity: Block - add missing Group functions
1 parent c73d158 commit cc90ae9

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

+nix/Block.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
function hasGroup = has_group(obj, id_or_name)
3434
hasGroup = nix_mx('Block::hasGroup', obj.nix_handle, id_or_name);
3535
end;
36-
36+
37+
function retObj = get_group(obj, id_or_name)
38+
retObj = nix.Utils.open_entity(obj, ...
39+
'Block::getGroup', id_or_name, @nix.Group);
40+
end;
41+
3742
function delCheck = delete_group(obj, del)
3843
[delCheck, obj.groupsCache] = nix.Utils.delete_entity(obj, ...
3944
del, 'nix.Group', 'Block::deleteGroup');

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void mexFunction(int nlhs,
117117
.reg("hasTag", GETBYSTR(bool, nix::Block, hasTag))
118118
.reg("hasMultiTag", GETBYSTR(bool, nix::Block, hasMultiTag))
119119
.reg("hasGroup", GETBYSTR(bool, nix::Block, hasGroup))
120+
.reg("getGroup", GETBYSTR(nix::Group, nix::Block, getGroup))
120121
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Block, getDataArray))
121122
.reg("openSource", GETBYSTR(nix::Source, nix::Block, getSource))
122123
.reg("openTag", GETBYSTR(nix::Tag, nix::Block, getTag))

tests/TestBlock.m

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
funcs{end+1} = @test_set_metadata;
2727
funcs{end+1} = @test_open_metadata;
2828
funcs{end+1} = @test_create_group;
29-
funcs{end+1} = @test_delete_group;
3029
funcs{end+1} = @test_has_group;
30+
funcs{end+1} = @test_get_group;
31+
funcs{end+1} = @test_delete_group;
3132
end
3233

3334
function [] = test_attrs( varargin )
@@ -375,7 +376,7 @@
375376
assert(strcmp(b.open_metadata.name, 'testSection'));
376377
end
377378

378-
%% Test: Create Group
379+
%% Test: Create nix.Group
379380
function [] = test_create_group( varargin )
380381
fileName = 'testRW.h5';
381382
groupName = 'testGroup';
@@ -397,7 +398,37 @@
397398
assert(strcmp(f.blocks{1}.groups{1}.name, groupName));
398399
end
399400

400-
%% Test: delete group by entity and id
401+
%% Test: nix.Block has nix.Group by name or id
402+
function [] = test_has_group( varargin )
403+
groupName = 'testGroup';
404+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
405+
b = f.createBlock('grouptest', 'nixBlock');
406+
407+
assert(~b.has_group('I do not exist'));
408+
409+
g = b.create_group(groupName, 'nixGroup');
410+
assert(b.has_group(b.groups{1}.id));
411+
assert(b.has_group(groupName));
412+
413+
b.delete_group(b.groups{1});
414+
assert(~b.has_group(g.id));
415+
end
416+
417+
%% Test: Get nix.Group by name or id
418+
function [] = test_get_group( varargin )
419+
groupName = 'testGroup';
420+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
421+
b = f.createBlock('grouptest', 'nixBlock');
422+
g = b.create_group(groupName, 'nixGroup');
423+
gID = g.id;
424+
425+
clear g b f;
426+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.ReadOnly);
427+
assert(strcmp(f.blocks{1}.get_group(gID).name, groupName));
428+
assert(strcmp(f.blocks{1}.get_group(groupName).name, groupName));
429+
end
430+
431+
%% Test: Delete nix.Group by entity and id
401432
function [] = test_delete_group( varargin )
402433
fileName = 'testRW.h5';
403434
groupType = 'nixGroup';
@@ -419,19 +450,3 @@
419450
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
420451
assert(isempty(f.blocks{1}.groups));
421452
end
422-
423-
%% Test: Block has Group by name or id
424-
function [] = test_has_group( varargin )
425-
groupName = 'testGroup';
426-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
427-
b = f.createBlock('grouptest', 'nixBlock');
428-
429-
assert(~b.has_group('I do not exist'));
430-
431-
g = b.create_group(groupName, 'nixGroup');
432-
assert(b.has_group(b.groups{1}.id));
433-
assert(b.has_group(groupName));
434-
435-
b.delete_group(b.groups{1});
436-
assert(~b.has_group(g.id));
437-
end

0 commit comments

Comments
 (0)