Skip to content

Commit

Permalink
test return status, clear memory in c example
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 21, 2022
1 parent b914a67 commit 138be0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions example/c/testzmat.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ int main(void) {
/* error handling */
if (ret) {
printf("encoding failed, error code: %d: encoder error code %d\n", ret, status);

if (compressed) {
free(compressed);
}

return ret;
}

Expand All @@ -75,6 +80,11 @@ int main(void) {
/* error handling */
if (ret) {
printf("decoding failed, error code: %d: decoder error code %d\n", ret, status);

if (decoded) {
free(decoded);
}

return ret;
}

Expand Down
Binary file modified private/zipmat.mexa64
Binary file not shown.
4 changes: 2 additions & 2 deletions test/run_zmat_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function run_zmat_test(tests)
fprintf('Test decompression\n');
fprintf(sprintf('%s\n', char(ones(1, 79) * 61)));

test_zmat('zlib (empty)', 'zlib', [1, 2, 3, 4], '', 'level', 0);
test_zmat('zlib (scalar)', 'zlib', uint8([120 156 147 208 117 9 249 173 200 233 0 0 9 224 2 67]), typecast(pi, 'uint8'), 'level', 0);
end
%%
if (ismember('err', tests))
Expand All @@ -87,6 +87,6 @@ function run_zmat_test(tests)
if (exist('string'))
test_zmat('unsupported input (string)', 'zlib', string(sprintf('zmat\ntest')), 'input must be a char, non-complex numeric or logical vector or N-D array');
end
test_zmat('unsupported input (cell)', 'zlib', zeros(1e9,1e9), 'input must be a char, non-complex numeric or logical vector or N-D array');
test_zmat('zlib wrong input format', 'zlib', [1, 2, 3, 4], [], 'level', 0, 'status', -3);
end

17 changes: 14 additions & 3 deletions test/test_zmat.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function test_zmat(testname, method, input, expected, varargin)
opt=struct('level',1);

if(length(varargin)>1 && rem(length(varargin),2)==0 && ischar(varargin{1}))
for i=1:2:length(varargin)
opt.(varargin{i})=varargin{i+1};
end
end

try
[res, info] = zmat(input, opt.level, method);
catch ME
Expand All @@ -15,11 +17,20 @@ function test_zmat(testname, method, input, expected, varargin)
end
return;
end

if(isfield(opt,'info'))
res=info.(opt.info);
end
res
expected

if(isfield(opt,'status'))
if(info.status~=opt.status)
warning('Test %s: failed: expected ''%s'', obtained ''%s''', testname, mat2str(expected), mat2str(res));
else
fprintf(1, 'Testing %s error: ok\n\tstatus:''%d''\n', testname, info.status);
end
return;
end

if (~isequal(res, expected))
warning('Test %s: failed: expected ''%s'', obtained ''%s''', testname, mat2str(expected), mat2str(res));
else
Expand All @@ -28,7 +39,7 @@ function test_zmat(testname, method, input, expected, varargin)
else
fprintf(1, 'Testing %s: ok\n\toutput:''%s''\n', testname, mat2str(res));
end
if(isfield(opt,'info'))
if(isfield(opt,'info') || opt.level == 0)
return;
end
newres = zmat(res, info);
Expand Down

0 comments on commit 138be0b

Please sign in to comment.