#!/usr/bin/perl

use strict;
use warnings;

use inc::testplan(1, 7);
use test_inc::loginit;

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";
  $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');

done;

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