close all, clear all, clc
fprintf('\nOctave gui functionality tests...\n\n')

test0 = 1

%------------------------------------------------------------------------------%
if( test0 )

fprintf('Test 0: No crash after pause.\n ')

hf  = figure;
% hp  = uipanel( 'parent', hf, 'units', 'normalized', 'position', [0 0 1 1], 'backgroundcolor', 'r' );
% cbf = @(obj,foo) set( obj, 'units', 'pixels', 'position', [0,0,100,100], 'backgroundcolor', 'b' );
% set( hp, 'resizefcn', cbf )

% fprintf('Paused, press any key to continue...\n\n')
% pause
% delete(hp)
delete(hf)
close all

end

%------------------------------------------------------------------------------%
fprintf('Test 1: Resizing should make the panel small and blue color.\n ')

hf  = figure;
hp  = uipanel( 'parent', hf, 'units', 'normalized', 'position', [0 0 1 1], 'backgroundcolor', 'r' );
cbf = @(obj,foo) set( obj, 'units', 'pixels', 'position', [0,0,100,100], 'backgroundcolor', 'b' );
% new_pos = @() [ones(1,4)*100*rand + [0 0 300*rand 300*rand]];
% cbf = @(obj,foo) set( obj, 'units', 'pixels', 'position', new_pos(), 'backgroundcolor', 'b' );
set( hp, 'resizefcn', cbf )

fprintf('Paused, press any key to continue...\n')
pause
delete(hp)
clf

%------------------------------------------------------------------------------%
fprintf('\nTest 2: Uicontrol background should be red.\n ')

% hf  = figure;
hc  = uicontrol( 'parent', hf, 'style', 'push', 'string', 'button', 'backgroundcolor', 'r' );

fprintf('Paused, press any key to continue...\n')
pause
delete(hc)
clf

%------------------------------------------------------------------------------%
fprintf('\nTest 3: Random image should be displayed on uicontrol.\n ')

% hf  = figure;
% cdata = zeros(160,160,3);
% cdata(:,:,1) = 1;
cdata = rand(100,100,3);
hc  = uicontrol( 'parent', hf, 'style', 'push', 'string', 'button', 'cdata', cdata );

fprintf('Paused, press any key to continue...\n')
pause

%------------------------------------------------------------------------------%
fprintf('\nTest 4: Not crash while deleting figure.\n ')
fprintf('Paused, press any key to continue...\n')
pause

delete(hc)
delete(hf)
