Commits

Herbert Breunung committed 78d78f7

fixed and extended focus tests

  • Participants
  • Parent commits a15ad10

Comments (0)

Files changed (4)

File lib/Kephra/App/Focus.pm

 
 package Kephra::App::Focus;
 my @focus_stack = ();
-my $max_size = 50;
+my $max_stack_size = 50;
 
 #Kephra::CommandList::register_cmd({'app-focus-set-back'  =>{sub=>'set_back',label=>'',keys=>''},});
 
 		unless Kephra::App::Util::is_widget($widget);
 	return if $widget eq get();
 	unshift @focus_stack, $widget;
-	pop @focus_stack if @focus_stack > $max_size;
+	pop @focus_stack while stack_size() > $max_stack_size;
 	stay();
 }
 
 sub set_back {                          # undo n times (default 1) a set command
 	my ($times) = shift // 1;
-	for (1 .. $times) { shift @focus_stack if @focus_stack > 1 }
+	for (1 .. $times) { shift @focus_stack if stack_size() > 1 }
 	stay();
 }
 
 		: Kephra::Log::warning( "no widget to stay focussed on", 1 );
 }
 
-sub max_size {                          # get and set maximum number of memorized widgets in focus
-	my $new_size = shift;
-	$max_size = defined $new_size ? $new_size : $max_size;
+sub stack_size { scalar @focus_stack }  # get current size (number  of memorized widgets)
+
+sub max_stack_size {                    # get and set maximum number of memorized widgets in focus
+	my $new_stack_size = shift;
+	$max_stack_size = defined $new_stack_size ? $new_stack_size : $max_stack_size;
 }
 
+
 1;

File lib/Kephra/Internals.pod

 
 keeps track in which App::Part the Focus wanders to make save way back if needed
 
+=over 4
+
 * Kephra::App::Panel
 
 wrapper around Wx::Panel + Wx::BoxSizer, helps not to deal with with sizers

File lib/Kephra/Log.pm

 
 sub init {}
 
-sub note {}
+sub note {
+	return if $test_mode;
+}
 
-sub warning { 
+sub warning {
+	return if $test_mode;
 	my $msg = message( @_ );
 	warn $msg unless $test_mode;
 	Kephra::API::output('warn', $msg) unless $test_mode;
 }
 
 sub error { 
+	return if $test_mode;
 	my $msg = message( @_ );
 	die $msg unless $test_mode;
 	Kephra::API::output('warn', 'ERROR: '.$msg) unless $test_mode;
 
 sub message     { 
 	my $msg = timestamp() . ' ' . calling_sub(3) . ': "'. $_[0].'"';
-	$msg .= ', when called by '. calling_sub(4) if $_[1];
+	$msg .= ', when called by '. calling_sub(3 + $_[1]) if $_[1];
 	$msg;
 }
 sub timestamp   { sprintf("[%02u:%02u:%02u]", (localtime)[2,1,0]) }

File t/605-app-focus.t

 BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
 
 package probe;
-use Test::More tests => 11;
+use Test::More tests => 14;
 use Test::NoWarnings;
 
 use Wx;
 my $frame = Wx::Frame->new( undef, -1, '');
 my $label = Wx::StaticText->new( undef, -1, '');
 
-
-is(Kephra::App::Focus::get(), undef, 'stack starts empty');
+is(Kephra::App::Focus::get(), '', 'stack starts empty');
 
 Kephra::App::Focus::set($frame);
 is(Kephra::App::Focus::get(), $frame, 'first widget was stored with set and retrieved with get');
 Kephra::App::Focus::set($label);
 is(Kephra::App::Focus::get(), $label, 'second widget was stored');
 
+my $size = Kephra::App::Focus::stack_size();
+Kephra::App::Focus::set($label);
+is(Kephra::App::Focus::stack_size(), $size, 'don\'t store widget twice in a row');
+
 Kephra::App::Focus::set(4);
 is(Kephra::App::Focus::get(), $label, 'set doesnt take number');
 
 Kephra::App::Focus::set_back();
 is(Kephra::App::Focus::get(), $frame, 'set_back() works');
 
-Kephra::App::Focus::set($label) for 1..7;
+Kephra::App::Focus::set( Wx::Button->new( undef, -1, '') ) for 1..7;
 Kephra::App::Focus::set_back(7);
 is(Kephra::App::Focus::get(), $frame, 'set_back() works with parameter');
 
 Kephra::App::Focus::stay();
 is(Kephra::App::Focus::get(), $label, 'stay does no harm');
 
+$size = Kephra::App::Focus::stack_size();
+Kephra::App::Focus::max_stack_size($size);
+is(Kephra::App::Focus::max_stack_size(), $size, 'max_stack_size() works');
+
+Kephra::App::Focus::set( Wx::Button->new( undef, -1, '') );
+is(Kephra::App::Focus::max_stack_size(), $size, 'set() keeps intended stack size');
+
+my $btn   = Wx::Button->new( undef, -1, '');
+
 
 exit(0);