#!/usr/bin/perl

use strict;
use warnings;

use Test::More qw(no_plan);

use Wx;
use Wx::Event qw(
  EVT_IDLE
  );

# TODO: juggle STDfoo and make sure it is quiet

my $package = eval { require("./client/app.pl") };
ok((not $@), "require ok") or
  BAIL_OUT("error: " . join('\n', split(/\n+/, $@)));
ok($package, $package || 'got a package') or
  BAIL_OUT("app.pl failed to load...STOP");

# NOTE: crash will typically happen here.  If it does, we're dead in
# the water (probably a syntax error.)
my $app = eval {$package->new(); };
ok((not $@), "$package constructor") or
  BAIL_OUT("error: " . join('\n', split(/\n+/, $@)));
ok($app, 'application');

# setup the event
my $idle_ok = 0;
EVT_IDLE($app, sub {
  0 and warn "\n  idle ", time(), "\n";
  if(0) { # hacking around on the mac
    0 and warn "Are we active ? ", $app->IsActive;
    (0 == $idle_ok) and $app->_main_frame->RequestUserAttention;
    $app->IsActive or $app->_main_frame->Maximize(1);
  }
  $idle_ok++;
  # I thought this could be two, but that only occurs if your mouse
  # happens to be over the window at start.
  ($idle_ok >= 1) and $app->ExitMainLoop;
  1;
  });

# MainLoop only reacts to events, but we'll wrap it anyway.
eval { $app->MainLoop(); };
ok((not $@), "MainLoop done") or
  BAIL_OUT("error: " . join('\n', split(/\n+/, $@)));

# MeinLeap does not have a useful return value?
ok(1, 'MainLoop');
ok($idle_ok, 'exit');

# vim:ts=2:sw=2:et:sta
