Skip to content

Commit 4de23c2

Browse files
committed
removeCache: refactor Block and BlockTests
1 parent 5d61e09 commit 4de23c2

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

+nix/Block.m

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
handle = nix_mx('Block::createGroup', obj.nix_handle, ...
2828
name, nixtype);
2929
g = nix.Group(handle);
30-
obj.groupsCache.lastUpdate = 0;
3130
end;
3231

3332
function hasGroup = has_group(obj, id_or_name)
@@ -40,7 +39,7 @@
4039
end;
4140

4241
function delCheck = delete_group(obj, del)
43-
[delCheck, obj.groupsCache] = nix.Utils.delete_entity(obj, ...
42+
delCheck = nix.Utils.delete_entity_(obj, ...
4443
del, 'nix.Group', 'Block::deleteGroup');
4544
end;
4645

@@ -59,7 +58,6 @@
5958
handle = nix_mx('Block::createDataArray', obj.nix_handle, ...
6059
name, nixtype, datatype, shape);
6160
da = nix.DataArray(handle);
62-
obj.dataArraysCache.lastUpdate = 0;
6361
end
6462

6563
function da = create_data_array_from_data(obj, name, nixtype, data)
@@ -75,26 +73,26 @@
7573
end;
7674

7775
function delCheck = delete_data_array(obj, del)
78-
[delCheck, obj.dataArraysCache] = nix.Utils.delete_entity(obj, ...
79-
del, 'nix.DataArray', 'Block::deleteDataArray', obj.dataArraysCache);
76+
delCheck = nix.Utils.delete_entity_(obj, ...
77+
del, 'nix.DataArray', 'Block::deleteDataArray');
8078
end;
8179

8280
% -----------------
8381
% Sources methods
8482
% -----------------
8583

8684
function s = create_source(obj, name, type)
87-
s = nix.Source(nix_mx('Block::createSource', obj.nix_handle, name, type));
88-
obj.sourcesCache.lastUpdate = 0;
85+
s = nix.Source(nix_mx('Block::createSource', ...
86+
obj.nix_handle, name, type));
8987
end;
9088

9189
function hasSource = has_source(obj, id_or_name)
9290
hasSource = nix_mx('Block::hasSource', obj.nix_handle, id_or_name);
9391
end;
9492

9593
function delCheck = delete_source(obj, del)
96-
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
97-
del, 'nix.Source', 'Block::deleteSource', obj.sourcesCache);
94+
delCheck = nix.Utils.delete_entity_(obj, ...
95+
del, 'nix.Source', 'Block::deleteSource');
9896
end;
9997

10098
function retObj = open_source(obj, id_or_name)
@@ -119,12 +117,11 @@
119117
th = nix_mx('Block::createTag', obj.nix_handle, ...
120118
name, type, position);
121119
tag = nix.Tag(th);
122-
obj.tagsCache.lastUpdate = 0;
123120
end;
124121

125122
function delCheck = delete_tag(obj, del)
126-
[delCheck, obj.tagsCache] = nix.Utils.delete_entity(obj, ...
127-
del, 'nix.Tag', 'Block::deleteTag', obj.tagsCache);
123+
delCheck = nix.Utils.delete_entity_(obj, ...
124+
del, 'nix.Tag', 'Block::deleteTag');
128125
end;
129126

130127
% -----------------
@@ -150,12 +147,12 @@
150147

151148
multitag = nix.MultiTag(nix_mx('Block::createMultiTag', ...
152149
obj.nix_handle, name, type, addID));
153-
obj.multiTagsCache.lastUpdate = 0;
154150
end;
155151

156152
function delCheck = delete_multi_tag(obj, del)
157-
[delCheck, obj.multiTagsCache] = nix.Utils.delete_entity(obj, ...
158-
del, 'nix.MultiTag', 'Block::deleteMultiTag', obj.multiTagsCache);
153+
delCheck = nix.Utils.delete_entity_(obj, ...
154+
del, 'nix.MultiTag', 'Block::deleteMultiTag');
159155
end;
156+
160157
end;
161-
end
158+
end

tests/TestBlock.m

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,51 +204,82 @@
204204
assert(~getBlock.delete_source('I do not exist'));
205205
end
206206

207+
%% Test: Fetch nix.DataArrays
207208
function [] = test_list_arrays( varargin )
208-
%% Test: fetch data arrays
209-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
209+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
210+
f = nix.File(fileName, nix.FileMode.Overwrite);
210211
b = f.createBlock('arraytest', 'nixBlock');
211212

212213
assert(isempty(b.dataArrays));
213214
tmp = b.create_data_array('arrayTest1', 'nixDataArray', 'double', [1 2]);
215+
assert(size(b.dataArrays, 1) == 1);
216+
assert(size(f.blocks{1}.dataArrays, 1) == 1);
214217
tmp = b.create_data_array('arrayTest2', 'nixDataArray', 'double', [3 4]);
215218
assert(size(b.dataArrays, 1) == 2);
219+
assert(size(f.blocks{1}.dataArrays, 1) == 2);
216220

221+
clear tmp b f;
222+
f = nix.File(fileName, nix.FileMode.ReadOnly);
223+
assert(size(f.blocks{1}.dataArrays, 1) == 2);
217224
end
218225

226+
%% Test: Fetch nix.Sources
219227
function [] = test_list_sources( varargin )
220-
%% Test: fetch sources
221-
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
222-
getBlock = test_file.createBlock('sourcetest', 'nixBlock');
228+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
229+
f = nix.File(fileName, nix.FileMode.Overwrite);
230+
b = f.createBlock('sourcetest', 'nixBlock');
223231

224-
assert(isempty(getBlock.sources));
225-
tmp = getBlock.create_source('sourcetest1','nixSource');
226-
tmp = getBlock.create_source('sourcetest2','nixSource');
227-
assert(size(getBlock.sources, 1) == 2);
232+
assert(isempty(b.sources));
233+
tmp = b.create_source('sourcetest1','nixSource');
234+
assert(size(b.sources, 1) == 1);
235+
assert(size(f.blocks{1}.sources, 1) == 1);
236+
tmp = b.create_source('sourcetest2','nixSource');
237+
assert(size(b.sources, 1) == 2);
238+
assert(size(f.blocks{1}.sources, 1) == 2);
239+
240+
clear tmp b f;
241+
f = nix.File(fileName, nix.FileMode.ReadOnly);
242+
assert(size(f.blocks{1}.sources, 1) == 2);
228243
end
229244

245+
%% Test: Fetch nix.Tags
230246
function [] = test_list_tags( varargin )
231-
%% Test: fetch tags
232-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
247+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
248+
f = nix.File(fileName, nix.FileMode.Overwrite);
233249
b = f.createBlock('tagtest', 'nixBlock');
234250
position = [1.0 1.2 1.3 15.9];
235251

236252
assert(isempty(b.tags));
237253
tmp = b.create_tag('tagtest1', 'nixTag', position);
254+
assert(size(b.tags, 1) == 1);
255+
assert(size(f.blocks{1}.tags, 1) == 1);
238256
tmp = b.create_tag('tagtest2', 'nixTag', position);
239257
assert(size(b.tags, 1) == 2);
258+
assert(size(f.blocks{1}.tags, 1) == 2);
259+
260+
clear tmp b f;
261+
f = nix.File(fileName, nix.FileMode.ReadOnly);
262+
assert(size(f.blocks{1}.tags, 1) == 2);
240263
end
241264

242-
function [] = test_list_multitags( varargin )
243265
%% Test: fetch multitags
244-
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
266+
function [] = test_list_multitags( varargin )
267+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
268+
f = nix.File(fileName, nix.FileMode.Overwrite);
245269
b = f.createBlock('mTagTestBlock', 'nixBlock');
246270
tmp = b.create_data_array('mTagTestDataArray', 'nixDataArray', 'double', [1 2]);
247271

248272
assert(isempty(b.multiTags));
249273
tmp = b.create_multi_tag('mTagTest1', 'nixMultiTag', b.dataArrays{1});
274+
assert(size(b.multiTags, 1) == 1);
275+
assert(size(f.blocks{1}.multiTags, 1) == 1);
250276
tmp = b.create_multi_tag('mTagTest2', 'nixMultiTag', b.dataArrays{1});
251277
assert(size(b.multiTags, 1) == 2);
278+
assert(size(f.blocks{1}.multiTags, 1) == 2);
279+
280+
clear tmp b f;
281+
f = nix.File(fileName, nix.FileMode.ReadOnly);
282+
assert(size(f.blocks{1}.multiTags, 1) == 2);
252283
end
253284

254285
function [] = test_open_array( varargin )

0 commit comments

Comments
 (0)