1use Test::More;
2BEGIN { use_ok( 'UI::Dialog::Backend::Zenity' ); }
3require_ok( 'UI::Dialog::Backend::Zenity' );
4
5#########################
6
7eval { new UI::Dialog::Backend::Zenity(test_mode=>1); };
8if ( $@ ) {
9  if ($@ =~ m!binary could not be found!) {
10    diag("Tests skipped, backend binary not found.");
11  }
12  else {
13    diag("An unknown error occurred while trying to use backend: ".$@);
14  }
15  done_testing();
16}
17else {
18
19  my $obj = new UI::Dialog::Backend::Zenity
20    ( test_mode => 1 );
21  isa_ok( $obj, 'UI::Dialog::Backend::Zenity' );
22
23  my $bin = $obj->get_bin();
24
25  my @methods = qw( new state ra rs rv nautilus xosd beep clear
26                    yesno msgbox inputbox password textbox menu
27                    checklist radiolist fselect dselect );
28  can_ok( 'UI::Dialog::Backend::Zenity', @methods );
29
30  $obj->yesno( title=>"TITLE", text => "TEXT",
31               width => 64, height => 16 );
32  is( $obj->get_unit_test_result(),
33      $bin.q| --title TITLE --width 64 --height 16 --question --text TEXT|
34    );
35
36  $obj->msgbox( title=>"TITLE", text => "TEXT",
37                width => 64, height => 16 );
38  is( $obj->get_unit_test_result(),
39      $bin.q| --title TITLE --width 64 --height 16 --info --text TEXT|
40    );
41
42  $obj->infobox( title=>"TITLE", text => "TEXT",
43                 width => 64, height => 16 );
44  is( $obj->get_unit_test_result(),
45      $bin.q| --title TITLE --width 64 --height 16 --info --text TEXT|
46    );
47
48  $obj->inputbox( title=>"TITLE", text => "TEXT",
49                  width => 64, height => 16, entry => "ENTRY" );
50  is( $obj->get_unit_test_result(),
51      $bin.q| --title TITLE --width 64 --height 16 --entry --entry-text ENTRY --text TEXT|
52    );
53
54  $obj->password( title=>"TITLE", text => "TEXT",
55                  width => 64, height => 16, entry => "ENTRY" );
56  is( $obj->get_unit_test_result(),
57      $bin.q| --title TITLE --width 64 --height 16 --entry --hide-text --entry-text ENTRY --text TEXT|
58    );
59
60  $obj->textbox( title=>"TITLE", path => "$0",
61                 width => 64, height => 16 );
62  is( $obj->get_unit_test_result(),
63      $bin.q| --title TITLE --width 64 --height 16 --text-info --filename t/UI-Dialog-Backend-Zenity.t|
64    );
65
66  $obj->menu( title=>"TITLE", text => "TEXT",
67              width => 64, height => 16,
68              list => [ "tag0", "item0", "tag1", "item1" ] );
69  is( $obj->get_unit_test_result(),
70      $bin.q| --title TITLE --width 64 --height 16 --list --separator '\n' --column " " --column " " "tag0" "item0" "tag1" "item1"|
71    );
72
73  $obj->checklist( title=>"TITLE", text => "TEXT",
74                   width => 64, height => 16,
75                   list => [ "tag0", [ "item0", 0 ], "tag1", [ "item1", 1 ] ] );
76  is( $obj->get_unit_test_result(),
77      $bin.q| --title TITLE --width 64 --height 16 --list --checklist --separator '\n' --column " " --column " " --column " " "FALSE" "tag0" "item0" "TRUE" "tag1" "item1"|
78    );
79
80  $obj->radiolist( title=>"TITLE", text => "TEXT",
81                   width => 64, height => 16,
82                   list => [ "tag0", [ "item0", 0 ], "tag1", [ "item1", 1 ] ] );
83  is( $obj->get_unit_test_result(),
84      $bin.q| --title TITLE --width 64 --height 16 --list --radiolist --separator '\n' --column " " --column " " --column " " "FALSE" "tag0" "item0" "TRUE" "tag1" "item1"|
85    );
86
87  done_testing();
88}
89