39
39
funcs{end + 1 } = @test_referring_block_sources ;
40
40
funcs{end + 1 } = @test_referring_blocks ;
41
41
funcs{end + 1 } = @test_compare ;
42
+ funcs{end + 1 } = @test_filter_section ;
42
43
end
43
44
44
45
%% Test: Create Section
619
620
assert(s1 .compare(s2 ) < 0 );
620
621
assert(s1 .compare(s1 ) == 0 );
621
622
assert(s2 .compare(s1 ) > 0 );
622
- end
623
+ end
624
+
625
+ %% Test: filter Sections
626
+ function [] = test_filter_section( varargin )
627
+ filterName = ' filterMe' ;
628
+ filterType = ' filterType' ;
629
+ f = nix .File(fullfile(pwd , ' tests' , ' testRW.h5' ), nix .FileMode .Overwrite );
630
+ ms = f .create_section(' testSection' , ' nixSection' );
631
+ s = ms .create_section(filterName , ' nixSection' );
632
+ filterID = s .id ;
633
+ s = ms .create_section(' testSection1' , filterType );
634
+ filterIDs = {filterID , s .id };
635
+ s = ms .create_section(' testSection2' , filterType );
636
+
637
+ % ToDO add basic filter crash tests
638
+
639
+ % test empty id filter
640
+ assert(isempty(f.sections{1 }.filter_sections(nix .Filter .id , ' IdoNotExist' )));
641
+
642
+ % test nix.Filter.accept_all
643
+ filtered = f.sections{1 }.filter_sections(nix .Filter .accept_all , ' ' );
644
+ assert(size(filtered , 1 ) == 3 );
645
+
646
+ % test nix.Filter.id
647
+ filtered = f.sections{1 }.filter_sections(nix .Filter .id , filterID );
648
+ assert(size(filtered , 1 ) == 1 );
649
+ assert(strcmp(filtered{1 }.id, filterID ));
650
+
651
+ % test nix.Filter.ids
652
+ filtered = f.sections{1 }.filter_sections(nix .Filter .ids , filterIDs );
653
+ assert(size(filtered , 1 ) == 2 );
654
+ assert(strcmp(filtered{1 }.id, filterIDs{1 }) || strcmp(filtered{1 }.id, filterIDs{2 }));
655
+
656
+ % test nix.Filter.name
657
+ filtered = f.sections{1 }.filter_sections(nix .Filter .name , filterName );
658
+ assert(size(filtered , 1 ) == 1 );
659
+ assert(strcmp(filtered{1 }.name, filterName ));
660
+
661
+ % test nix.Filter.type
662
+ filtered = f.sections{1 }.filter_sections(nix .Filter .type , filterType );
663
+ assert(size(filtered , 1 ) == 2 );
664
+
665
+ % test fail on nix.Filter.metadata
666
+ err = ' unknown or unsupported filter' ;
667
+ try
668
+ f.sections{1 }.filter_sections(nix .Filter .metadata , ' someMetadata' );
669
+ catch ME
670
+ assert(strcmp(ME .message , err ));
671
+ end
672
+
673
+ % test fail on nix.Filter.source
674
+ try
675
+ f.sections{1 }.filter_sections(nix .Filter .source , ' someSource' );
676
+ catch ME
677
+ assert(strcmp(ME .message , err ));
678
+ end
679
+ end
0 commit comments