|
40 | 40 | funcs{end+1} = @test_referring_blocks;
|
41 | 41 | funcs{end+1} = @test_compare;
|
42 | 42 | funcs{end+1} = @test_filter_section;
|
| 43 | + funcs{end+1} = @test_filter_property; |
43 | 44 | end
|
44 | 45 |
|
45 | 46 | %% Test: Create Section
|
|
677 | 678 | assert(strcmp(ME.message, err));
|
678 | 679 | end
|
679 | 680 | end
|
| 681 | + |
| 682 | +%% Test: filter properties |
| 683 | +function [] = test_filter_property( varargin ) |
| 684 | + filterName = 'filterMe'; |
| 685 | + f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite); |
| 686 | + ms = f.create_section('testSection', 'nixSection'); |
| 687 | + p = ms.create_property(filterName, nix.DataType.Double); |
| 688 | + filterID = p.id; |
| 689 | + s = ms.create_property('testProperty', nix.DataType.Bool); |
| 690 | + filterIDs = {filterID, s.id}; |
| 691 | + |
| 692 | + % test empty id filter |
| 693 | + assert(isempty(f.sections{1}.filter_properties(nix.Filter.id, 'IdoNotExist'))); |
| 694 | + |
| 695 | + % test nix.Filter.accept_all |
| 696 | + filtered = f.sections{1}.filter_properties(nix.Filter.accept_all, ''); |
| 697 | + assert(size(filtered, 1) == 2); |
| 698 | + |
| 699 | + % test nix.Filter.id |
| 700 | + filtered = f.sections{1}.filter_properties(nix.Filter.id, filterID); |
| 701 | + assert(size(filtered, 1) == 1); |
| 702 | + assert(strcmp(filtered{1}.id, filterID)); |
| 703 | + |
| 704 | + % test nix.Filter.ids |
| 705 | + filtered = f.sections{1}.filter_properties(nix.Filter.ids, filterIDs); |
| 706 | + assert(size(filtered, 1) == 2); |
| 707 | + assert(strcmp(filtered{1}.id, filterIDs{1}) || strcmp(filtered{1}.id, filterIDs{2})); |
| 708 | + |
| 709 | + % test nix.Filter.name |
| 710 | + filtered = f.sections{1}.filter_properties(nix.Filter.name, filterName); |
| 711 | + assert(size(filtered, 1) == 1); |
| 712 | + assert(strcmp(filtered{1}.name, filterName)); |
| 713 | + |
| 714 | + % test fail on nix.Filter.type |
| 715 | + err = 'unknown or unsupported filter'; |
| 716 | + try |
| 717 | + f.sections{1}.filter_properties(nix.Filter.type, 'someType'); |
| 718 | + catch ME |
| 719 | + assert(strcmp(ME.message, err)); |
| 720 | + end |
| 721 | + |
| 722 | + % test fail on nix.Filter.metadata |
| 723 | + err = 'unknown or unsupported filter'; |
| 724 | + try |
| 725 | + f.sections{1}.filter_properties(nix.Filter.metadata, 'someMetadata'); |
| 726 | + catch ME |
| 727 | + assert(strcmp(ME.message, err)); |
| 728 | + end |
| 729 | + |
| 730 | + % test fail on nix.Filter.source |
| 731 | + try |
| 732 | + f.sections{1}.filter_properties(nix.Filter.source, 'someSource'); |
| 733 | + catch ME |
| 734 | + assert(strcmp(ME.message, err)); |
| 735 | + end |
| 736 | +end |
0 commit comments