% Testcases for EEGLab
% Copyright (C) 2006 Andreas Romeyke & Ronny Lindner
% Max-Planck-Institute for Human Cognitive and Brain Sciences Leipzig, Germany
% romeyke@cbs.mpg.de, art1@it-netservice.de
%
% based on EEGLab-toolbox
% http://www.sccn.ucsd.edu/eeglab/
% Copyright (C) 1996 Scott Makeig et al, SCCN/INC/UCSD, scott@sccn.ucsd.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function pass_general()
        % 5.03:
        % typo in 'getallmenus.m'
        % output should be as in ctree2
        % but is not inverted ( line 56: 'allemnu = allmenu(end:-1:1);' )

        ctree1 = [ ['a' 0 0 0 0 0 0 0]; ...
                   ['      aa']; ...
                   ['      ab']; ...
                   ['      ac']; ...
                   ['      ad']; ...
                   ['b' 0 0 0 0 0 0 0]; ...
                   ['c' 0 0 0 0 0 0 0]; ...
                   ['d' 0 0 0 0 0 0 0]; ...
                   ['      da']; ...
                   ['e' 0 0 0 0 0 0 0]; ...
                   ['f' 0 0 0 0 0 0 0]; ...
                   ['g' 0 0 0 0 0 0 0]; ...
                   [  0 0 0 0 0 0 0 0] ];

        ctree2 = [ ['g' 0 0 0 0 0 0 0]; ...
                   ['f' 0 0 0 0 0 0 0]; ...
                   ['e' 0 0 0 0 0 0 0]; ...
                   ['d' 0 0 0 0 0 0 0]; ...
                   ['      da']; ...
                   ['c' 0 0 0 0 0 0 0]; ...
                   ['b' 0 0 0 0 0 0 0]; ...
                   ['a' 0 0 0 0 0 0 0]; ...
                   ['      ad']; ...
                   ['      ac']; ...
                   ['      ab']; ...
                   ['      aa']; ...
                   [  0 0 0 0 0 0 0 0] ];


        % windows
        W_MAIN = figure('Units','points', ...
            'PaperPosition',[18 180 576 432], ...
            'PaperUnits','points', ...
            'name', [ 'EEGLAB_TEST' ], ... 
            'numbertitle', 'off', ...
            'resize', 'off', ...
            'Position',[100 100 100 100 ], ...
            'color', [0 1 0], ...
            'Tag','EEGLAB_TEST', ...
            'visible', 'off', ...   
            'Userdata', {[], []});

        % frame in window
        H_MAIN(1) = uicontrol('Parent',W_MAIN, ...
            'Units','points', ...
            'BackgroundColor',[1 0 0], ...
            'ListboxTop',0, ...
            'HorizontalAlignment', 'left',...
            'Position',[100 200 300 400], ...
            'Style','frame', ...
            'Tag','Frame1');

        % menu (12 elements)
        set(W_MAIN, 'MenuBar', 'none');
        m_a  = uimenu( W_MAIN, 'Label', 'a');
            m_aa = uimenu( m_a, 'Label', 'aa'); 
            m_ab = uimenu( m_a, 'Label', 'ab'); 
            m_ac = uimenu( m_a, 'Label', 'ac'); 
            m_ad = uimenu( m_a, 'Label', 'ad'); 
        m_b  = uimenu( W_MAIN, 'Label', 'b');
        m_c = uimenu( W_MAIN, 'Label', 'c');
        m_d  = uimenu( W_MAIN, 'Label', 'd');
            m_da   = uimenu( m_d, 'Label', 'da');
        m_e   = uimenu( W_MAIN, 'Label', 'e');
        m_f   = uimenu( W_MAIN, 'Label', 'f');
        m_g  = uimenu( W_MAIN, 'Label', 'g');

    
        rtree = getallmenus(W_MAIN);

        % get handle of all window elements
        windowelements = findobj(0);
        % close window
        close(W_MAIN);

        if ~near(ctree2, rtree) ...
        || length(windowelements) < 15 % 12 menu items + 1 windows + 1 frame + root
            error('EEGLAB:unittesting', 'Error in getallmenus().');
        end;


