Skip to content

Commit b62e8b4

Browse files
committed
completify: add missing Source functions and tests
1 parent 7fab066 commit b62e8b4

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

+nix/Source.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
obj.sourcesCache.lastUpdate = 0;
2525
end;
2626

27+
function hasSource = has_source(obj, id_or_name)
28+
hasSource = nix_mx('Source::hasSource', obj.nix_handle, id_or_name);
29+
end;
30+
2731
function delCheck = delete_source(obj, del)
2832
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
2933
del, 'nix.Source', 'Source::deleteSource', obj.sourcesCache);

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void mexFunction(int nlhs,
167167
.reg("createSource", &nix::Source::createSource)
168168
.reg("deleteSource", REMOVER(nix::Source, nix::Source, deleteSource))
169169
.reg("sources", &nix::Source::sources)
170+
.reg("hasSource", GETBYSTR(bool, nix::Source, hasSource))
170171
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
171172
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata))
172173
.reg("set_metadata", SETTER(const std::string&, nix::Source, metadata))

tests/TestSource.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
funcs{end+1} = @test_delete_source;
88
funcs{end+1} = @test_attrs;
99
funcs{end+1} = @test_fetch_sources;
10+
funcs{end+1} = @test_has_source;
1011
funcs{end+1} = @test_open_source;
1112
funcs{end+1} = @test_set_metadata;
1213
funcs{end+1} = @test_open_metadata;
@@ -120,3 +121,21 @@
120121
s.definition = '';
121122
assert(isempty(s.definition));
122123
end
124+
125+
%% Test: nix.Source has nix.Source by ID or name
126+
function [] = test_has_source( varargin )
127+
fileName = 'testRW.h5';
128+
sName = 'nestedsource';
129+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
130+
b = f.createBlock('testblock', 'nixBlock');
131+
s = b.create_source('sourcetest', 'nixSource');
132+
nested = s.create_source(sName, 'nixSource');
133+
nestedID = nested.id;
134+
135+
assert(~s.has_source('I do not exist'));
136+
assert(s.has_source(sName));
137+
138+
clear nested s b f;
139+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
140+
assert(f.blocks{1}.sources{1}.has_source(nestedID));
141+
end

0 commit comments

Comments
 (0)