Skip to content

Commit c73d158

Browse files
committed
addGroupEntity: add missing group functions
1 parent 3611921 commit c73d158

File tree

4 files changed

+42
-61
lines changed

4 files changed

+42
-61
lines changed

+nix/Block.m

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,17 @@
2323
% Group methods
2424
% -----------------
2525

26-
% TODO -- seems to work remove me later
2726
function g = create_group(obj, name, nixtype)
2827
handle = nix_mx('Block::createGroup', obj.nix_handle, ...
2928
name, nixtype);
3029
g = nix.Group(handle);
3130
obj.groupsCache.lastUpdate = 0;
3231
end;
3332

34-
% TODO - check if this actually works...
35-
% TODO - find better solution to deal with non-entity entries.
36-
function hasGroup = has_group(obj, group)
37-
% TODO not available from the c++ side at the moment
38-
%{
39-
if(strcmp(class(group), 'nix.Group'))
40-
hasGroup = nix_mx('Block::hasGroup', group);
41-
else
42-
error('Please provide a proper group.');
43-
end;
44-
%}
33+
function hasGroup = has_group(obj, id_or_name)
34+
hasGroup = nix_mx('Block::hasGroup', obj.nix_handle, id_or_name);
4535
end;
4636

47-
% TODO -- seems to work remove me later
4837
function delCheck = delete_group(obj, del)
4938
[delCheck, obj.groupsCache] = nix.Utils.delete_entity(obj, ...
5039
del, 'nix.Group', 'Block::deleteGroup');

nix_mx.cc

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void mexFunction(int nlhs,
116116
.reg("groups", &nix::Block::groups)
117117
.reg("hasTag", GETBYSTR(bool, nix::Block, hasTag))
118118
.reg("hasMultiTag", GETBYSTR(bool, nix::Block, hasMultiTag))
119-
// method is only available as get by entity, not as get by id or name on the c++ side
120-
//.reg("hasGroup", GETBYSTR(bool, nix::Block, hasGroup))
119+
.reg("hasGroup", GETBYSTR(bool, nix::Block, hasGroup))
121120
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Block, getDataArray))
122121
.reg("openSource", GETBYSTR(nix::Source, nix::Block, getSource))
123122
.reg("openTag", GETBYSTR(nix::Tag, nix::Block, getTag))
@@ -139,29 +138,17 @@ void mexFunction(int nlhs,
139138

140139
classdef<nix::Group>("Group", methods)
141140
.desc(&nixgroup::describe)
142-
// does not work
143-
//.reg("dataArrays", &nix::Group::dataArrays)
144-
// does not work
145-
//.reg("tags", &nix::Group::tags)
146-
// does not work
147-
//.reg("multiTags", &nix::Group::multiTags)
148-
// compiles, should work
141+
.reg("dataArrays", FILTER(std::vector<nix::DataArray>, nix::Group, , dataArrays))
142+
.reg("tags", FILTER(std::vector<nix::Tag>, nix::Group, , tags))
143+
.reg("multiTags", FILTER(std::vector<nix::MultiTag>, nix::Group, , multiTags))
149144
.reg("hasDataArray", GETBYSTR(bool, nix::Group, hasDataArray))
150-
// compiles, should work
151145
.reg("hasTag", GETBYSTR(bool, nix::Group, hasTag))
152-
// compiles, should work
153146
.reg("hasMultiTag", GETBYSTR(bool, nix::Group, hasMultiTag))
154-
// compiles, should work
155147
.reg("getDataArray", GETBYSTR(nix::DataArray, nix::Group, getDataArray))
156-
// compiles, should work
157148
.reg("getTag", GETBYSTR(nix::Tag, nix::Group, getTag))
158-
// compiles, should work
159149
.reg("getMultiTag", GETBYSTR(nix::MultiTag, nix::Group, getMultiTag))
160-
// compiles, should work
161150
.reg("removeDataArray", REMOVER(nix::DataArray, nix::Group, removeDataArray))
162-
// compiles, should work, deleteTag in Block
163151
.reg("removeTag", REMOVER(nix::Tag, nix::Group, removeTag))
164-
// should work, deleteMultiTag in Block
165152
.reg("removeMultiTag", REMOVER(nix::MultiTag, nix::Group, removeMultiTag))
166153
.reg("set_type", SETTER(const std::string&, nix::Group, type))
167154
.reg("set_definition", SETTER(const std::string&, nix::Group, definition))

tests/TestBlock.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,18 @@
420420
assert(isempty(f.blocks{1}.groups));
421421
end
422422

423-
%% Test: Block has Group by entity
423+
%% Test: Block has Group by name or id
424424
function [] = test_has_group( varargin )
425-
%{
426-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5', nix.FileMode.Overwrite));
425+
groupName = 'testGroup';
426+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
427427
b = f.createBlock('grouptest', 'nixBlock');
428428

429-
g = b.create_group('testGroup', 'nixGroup');
430-
assert(b.has_group(b.groups{1}));
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));
431434

432435
b.delete_group(b.groups{1});
433-
assert(~b.has_group(g));
434-
%}
435-
disp('Test Block.has_group ... TODO (function not working at the moment)');
436-
end
436+
assert(~b.has_group(g.id));
437+
end

tests/TestGroup.m

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@
6262
da = b.create_data_array(daName, daType, 'double', [2 3]);
6363
g = b.create_group('testGroup', 'nixGroup');
6464

65-
disp('Test Group.add_data_array ... TODO dataArrays check is not working');
66-
%assert(isempty(g.dataArrays));
65+
assert(isempty(g.dataArrays));
6766
g.add_data_array(da);
68-
%assert(size(g.dataArrays,1) == 1);
69-
%assert(strcmp(b.groups{1}.dataArrays{1}.name, daName));
67+
assert(size(g.dataArrays, 1) == 1);
68+
assert(strcmp(b.groups{1}.dataArrays{1}.name, daName));
7069

7170
clear g da b f;
7271
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
73-
%assert(strcmp(f.blocks{1}.groups{1}.dataArrays{1}.name, daName));
72+
assert(strcmp(f.blocks{1}.groups{1}.dataArrays{1}.name, daName));
7473
end
7574

7675
%% Test: Get nix.DataArray by id or name
@@ -184,17 +183,16 @@
184183
t2 = b.create_tag(tagName2, 'nixTag', [1.0 1.2 1.3 15.9]);
185184
tID = t2.id;
186185
g = b.create_group('testGroup', 'nixGroup');
187-
disp('test_add_tag: TODO comment in check once method is implemented in c++');
188-
%assert(isempty(g.tags));
186+
assert(isempty(g.tags));
189187
g.add_tag(t1);
190-
%assert(strcmp(g.tags{1}.name, tagName1));
188+
assert(strcmp(g.tags{1}.name, tagName1));
191189
g.add_tag(tID);
192-
%assert(strcmp(g.tags{2}.name, tagName2));
190+
assert(strcmp(g.tags{2}.name, tagName2));
193191

194192
clear t1 t2 g b f;
195193
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
196-
%assert(strcmp(f.blocks{1}.groups{1}.tags{1}.name, tagName1));
197-
%assert(strcmp(f.blocks{1}.groups{1}.tags{2}.name, tagName2));
194+
assert(strcmp(f.blocks{1}.groups{1}.tags{1}.name, tagName1));
195+
assert(strcmp(f.blocks{1}.groups{1}.tags{2}.name, tagName2));
198196
end
199197

200198
%% Test: has nix.Tag by id or name
@@ -253,17 +251,21 @@
253251

254252
assert(~g.remove_tag('I do not exist'));
255253

256-
disp('TODO: comment asserts in when tags function works');
254+
disp('Fix caching issue before commenting in inactive asserts.');
257255
assert(size(f.blocks{1}.tags, 1) == 3);
258-
%assert(size(f.blocks{1}.groups{1}.tags, 1) == 3);
256+
assert(size(g.tags, 1) == 3);
257+
assert(size(f.blocks{1}.groups{1}.tags, 1) == 3);
259258
assert(g.remove_tag(t1.id));
260259
assert(size(f.blocks{1}.tags, 1) == 3);
260+
assert(size(g.tags, 1) == 2);
261261
%assert(size(f.blocks{1}.groups{1}.tags, 1) == 2);
262262
assert(g.remove_tag(t2));
263263
assert(size(f.blocks{1}.tags, 1) == 3);
264+
assert(size(g.tags, 1) == 1);
264265
%assert(size(f.blocks{1}.groups{1}.tags, 1) == 1);
265266
assert(~g.remove_tag(t2));
266267
assert(size(f.blocks{1}.tags, 1) == 3);
268+
assert(size(g.tags, 1) == 1);
267269
%assert(size(f.blocks{1}.groups{1}.tags, 1) == 1);
268270

269271
clear t1 t2 t3 g b f;
@@ -286,18 +288,17 @@
286288
tmp = b.create_multi_tag(tagName2, tagType, b.dataArrays{2});
287289
g = b.create_group('testGroup', 'nixGroup');
288290

289-
disp('test_add_multi_tag: comment in once c++ method works');
290-
%assert(isempty(g.multiTags));
291+
assert(isempty(g.multiTags));
291292
g.add_multi_tag(b.multiTags{1});
292-
%assert(size(g.multiTags, 1) == 1);
293+
assert(size(g.multiTags, 1) == 1);
293294

294295
g.add_multi_tag(b.multiTags{2}.id);
295-
%assert(size(g.multiTags, 1) == 2);
296+
assert(size(g.multiTags, 1) == 2);
296297

297298
clear tmp g b f;
298299
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
299-
%assert(strcmp(f.blocks{1}.groups{1}.tags{1}.name, tagName1));
300-
%assert(strcmp(f.blocks{1}.groups{1}.tags{2}.name, tagName2));
300+
assert(strcmp(f.blocks{1}.groups{1}.multiTags{1}.name, tagName1));
301+
assert(strcmp(f.blocks{1}.groups{1}.multiTags{2}.name, tagName2));
301302
end
302303

303304
%% Test: has nix.MultiTag by id or name
@@ -368,24 +369,27 @@
368369

369370
assert(~g.remove_multi_tag('I do not exist'));
370371

371-
disp('TODO: comment asserts in when multitags function works');
372+
disp('Fix caching issue before commenting in inactive asserts.');
372373
assert(size(f.blocks{1}.multiTags, 1) == 3);
373-
%assert(size(f.blocks{1}.groups{1}.multiTags, 1) == 3);
374+
assert(size(f.blocks{1}.groups{1}.multiTags, 1) == 3);
374375
assert(g.remove_multi_tag(t1.id));
375376
assert(size(f.blocks{1}.multiTags, 1) == 3);
377+
assert(size(g.multiTags, 1) == 2);
376378
%assert(size(f.blocks{1}.groups{1}.multiTags, 1) == 2);
377379
assert(~g.has_multi_tag(tagName1));
378380

379381
assert(g.remove_multi_tag(t2));
380382
assert(size(f.blocks{1}.multiTags, 1) == 3);
383+
assert(size(g.multiTags, 1) == 1);
381384
%assert(size(f.blocks{1}.groups{1}.multiTags, 1) == 1);
382385
assert(~g.has_multi_tag(tagName2));
383386

384387
assert(~g.remove_multi_tag(t2));
385388
assert(size(f.blocks{1}.multiTags, 1) == 3);
389+
assert(size(g.multiTags, 1) == 1);
386390
%assert(size(f.blocks{1}.groups{1}.multiTags, 1) == 1);
387391

388392
clear t1 t2 t3 da g b f;
389393
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
390394
assert(f.blocks{1}.groups{1}.has_multi_tag(tagName3));
391-
end
395+
end

0 commit comments

Comments
 (0)