Skip to content

Commit b8f2a56

Browse files
committed
Merge pull request #102 from mpsonntag/fixUnitsBug
Fix Tag/MultiTag units bug LGTM
2 parents ad54241 + cd93280 commit b8f2a56

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

+nix/Dynamic.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ function set_method(obj, val)
2222
prop, class(obj)));
2323
throwAsCaller(ME);
2424
end
25-
25+
2626
if (isempty(val))
2727
nix_mx(strcat(obj.alias, '::set_none_', prop), obj.nix_handle, 0);
28+
elseif(strcmp(prop, 'units') && (~iscell(val)))
29+
%-- BUGFIX: Matlab crashes, if units in Tags and MultiTags
30+
%-- are set using anything else than a cell.
31+
ME = MException('MATLAB:class:SetProhibited', sprintf(...
32+
'Units can be only set by using cells.'));
33+
throwAsCaller(ME);
2834
else
2935
nix_mx(strcat(obj.alias, '::set_', prop), obj.nix_handle, val);
3036
end
3137
obj.info = nix_mx(strcat(obj.alias, '::describe'), obj.nix_handle);
3238
end
33-
39+
3440
function val = get_method(obj)
3541
val = obj.info.(prop);
3642
end

tests/TestMultiTag.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@
416416
t = b.create_multi_tag('unitsTest', 'nixMultiTag', da);
417417

418418
assert(isempty(t.units));
419+
try
420+
t.units = 'mV';
421+
catch ME
422+
assert(strcmp(ME.identifier, 'MATLAB:class:SetProhibited'));
423+
end;
424+
try
425+
t.units = ['mV', 'uA'];
426+
catch ME
427+
assert(strcmp(ME.identifier, 'MATLAB:class:SetProhibited'));
428+
end;
429+
419430
units = {'mV'};
420431
t.units = {'mV'};
421432
assert(isequal(t.units,units));

tests/TestTag.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@
316316
assert(isempty(t1.definition));
317317

318318
assert(isempty(t1.units));
319+
try
320+
t1.units = 'mV';
321+
catch ME
322+
assert(strcmp(ME.identifier, 'MATLAB:class:SetProhibited'));
323+
end;
324+
try
325+
t1.units = ['mV', 'uA'];
326+
catch ME
327+
assert(strcmp(ME.identifier, 'MATLAB:class:SetProhibited'));
328+
end;
329+
319330
t1.units = {'ms', 'mV'};
320331
assert(isequal(t1.units, {'ms', 'mV'}));
321332

0 commit comments

Comments
 (0)