Skip to content

Commit 4bd8fa4

Browse files
committed
removeCache: refactor Source and SourceTests
1 parent e3e7c5d commit 4bd8fa4

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

+nix/Source.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121

2222
function s = create_source(obj, name, type)
2323
s = nix.Source(nix_mx('Source::createSource', obj.nix_handle, name, type));
24-
obj.sourcesCache.lastUpdate = 0;
2524
end;
2625

2726
function hasSource = has_source(obj, id_or_name)
2827
hasSource = nix_mx('Source::hasSource', obj.nix_handle, id_or_name);
2928
end;
3029

3130
function delCheck = delete_source(obj, del)
32-
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
33-
del, 'nix.Source', 'Source::deleteSource', obj.sourcesCache);
31+
delCheck = nix.Utils.delete_entity_(obj, del, ...
32+
'nix.Source', 'Source::deleteSource');
3433
end;
3534

3635
function retObj = open_source(obj, id_or_name)
@@ -39,4 +38,4 @@
3938
end;
4039

4140
end;
42-
end
41+
end

tests/TestSource.m

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@
1515

1616
%% Test: fetch sources
1717
function [] = test_fetch_sources( varargin )
18-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
19-
getBlock = test_file.createBlock('sourcetest', 'nixBlock');
20-
getSource = getBlock.create_source('sourcetest', 'nixSource');
21-
tmp = getSource.create_source('nestedsource1', 'nixSource');
22-
tmp = getSource.create_source('nestedsource2', 'nixSource');
18+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
19+
f = nix.File(fileName, nix.FileMode.Overwrite);
20+
b = f.createBlock('sourcetest', 'nixBlock');
21+
s = b.create_source('sourcetest', 'nixSource');
22+
23+
assert(isempty(s.sources));
24+
assert(isempty(f.blocks{1}.sources{1}.sources));
25+
tmp = s.create_source('nestedsource1', 'nixSource');
26+
assert(size(s.sources, 1) == 1);
27+
assert(size(f.blocks{1}.sources{1}.sources, 1) == 1);
28+
tmp = s.create_source('nestedsource2', 'nixSource');
29+
assert(size(s.sources, 1) == 2);
30+
assert(size(f.blocks{1}.sources{1}.sources, 1) == 2);
2331

24-
assert(size(getSource.sources, 1) == 2);
32+
clear tmp s b f;
33+
f = nix.File(fileName, nix.FileMode.ReadOnly);
34+
assert(size(f.blocks{1}.sources{1}.sources, 1) == 2);
2535
end
2636

2737
%% Test: Open source by ID or name

0 commit comments

Comments
 (0)