blib/lib/Script/mytest.pl untested

filter: Statementstmt 0.0% 0 / 97 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 112 SCAR 30.0
CC
4
Cov
0%
test1
20.0
testCheckBox
2.0
main
2.0
CRAP 20.0
1 #!/usr/bin/perl -w
2 #
3 # Jan 2016 M.Eckardt, imunixx GmbH <Matthias.Eckardt@imunixx.de>
4 # SDG
5 ############################################################################
6 # make testdb TEST_FILE=mytest.pl
7 ############################################################################
8 use strict;
9 use Script::Toolbox qw(:all);
10 use Script::Toolbox::TableO;
11 ############################################################################
12 my $O = {
13 'file' => { 'mod' => '=s', 'desc' => 'Get a file name.', 'mand' => 1, 'default' => '/bin/cat', },
14 };
15 ############################################################################
16 ############ generate prototypes with the following line ###################
17 # :r! echo $(grep '^sub' queue_blocking.pl | sed -e 's/$/;/') | fold -s -80
18 ############################################################################
19 ############################################################################
20 #$SIG{'INT'} = 'sigExit';
21 #$SIG{'HUP'} = 'sigExit';
22 #$SIG{'QUIT'}= 'sigExit';
23 #$SIG{'TERM'}= 'sigExit';
24 ############################################################################
25 #------------------------------------------------------------------------------
26 # Signal handler.
27 #------------------------------------------------------------------------------
28 #sub sigExit($)
29 #{
30 # my ($sig) = @_;
31 # Exit( 1, "program aborted by signal SIG$sig." );
32 #}
33  
34  
35 #------------------------------------------------------------------------------
36 #------------------------------------------------------------------------------
37 sub testCheckBox(){
38  
39 my $x;
40 $x = CheckBox('CheckBox ccc-selected.',',AAA,BBB,ccc','ccc' );
41 $x = CheckBox('CheckBox ccc-AAA-selected.',',AAA,BBB,ccc','ccc|AAA' );
42 $x = CheckBox('CheckBox nothing selected.',',AAA,BBB,ccc' );
43 $x = RadioButton('RadioButtonCheckBox no preselect (one option must be selected).',',AAA,BBB,ccc',undef,1 );
44 $x = RadioButton('RadioButtonCheckBox with 1 preselect.',',AAA,BBB,ccc','ccc', 1 );
45  
46 my $m = Script::Toolbox::Util::Menus->new();
47 $x = CheckBox('CheckBox ccc-selected preselect and menu container.',',AAA,BBB,ccc','ccc', ,$m);
48 $x = CheckBox('CheckBox ccc-AAA-selected and menu container usage.',',AAA,BBB,ccc','ccc|AAA',,$m);
49 $x = CheckBox('CheckBox nothing selected and menu container usage.',',AAA,BBB,ccc',undef, ,$m);
50 $x = RadioButton('RadioButtonCheckBox ccc-selected (use only first preselect pattern).',',AAA,BBB,ccc','ccc|AAA',$m);
51 $x = RadioButton('RadioButtonCheckBox nothing selected (unmatching preselect pattern).',',AAA,BBB,ccc','ssc|67A',$m);
52  
53 $x = CheckBox('Initialize testmenu.',',AAA,BBB,ccc','ccc', $m,'testmenu');
54 $x = CheckBox('Same select state.',',AAA,BBB,ccc','ccc|AAA', $m,'testmenu');
55 $x = CheckBox('Same select state.',',AAA,BBB,ccc',undef, $m,'testmenu');
56 $x = RadioButton('Change into RadioButton CB.',',AAA,BBB,ccc','ccc', $m,'testmenu');
57 return;
58 }
59  
60  
61 #------------------------------------------------------------------------------
62 #------------------------------------------------------------------------------
63 sub test1()
64 {
65 my $M =[
66 {'label'=>'rwValue', 'value'=>1 },
67 {'label'=>'roValue', 'value'=>'readOnly','readOnly'=>1},
68 {'label'=>'rwValDef','value'=>30, 'default'=>50},
69 {'label'=>'roValDef','value'=>30, 'default'=>50, 'readOnly'=>1},
70 {'label'=>'roNoValNoDef', 'readOnly'=>1},
71 {'label'=>'roNoValDef', 'default'=>50, 'readOnly'=>1},
72 {'label'=>'roValNoDef','value'=>30, 'readOnly'=>1},
73 {'label'=>'test8',},
74 {'label'=>'test9',},
75 {'label'=>'test10', 'value'=>30, },
76 {'label'=>'Untermenue 1', 'jump'=>'SubMenu1'},
77 {'label'=>'Untermenue 2', 'jump'=>'SubMenu2'},
78 {'label'=>'InvalidSubMenu', 'jump'=>'SubMenuX'}
79 ];
80 my ($self) = @_;
81 my $o = Script::Toolbox->new( $O );
82  
83 my $m = Script::Toolbox::Util::Menus->new({'SubMenu2'=>[{'label'=>'test','value'=>10}]});
84 $m->addMenu({'MainMenu'=>$M});
85 $m->addMenu({'SubMenu1'=>[{'label'=>'SubMenu1 Test','value'=>40}]});
86 $m->addOption('MainMenu', {'label'=>'Untermenue 2 via addOption()', 'jump'=>'SubMenu2'});
87  
88 $m->setAutoHeader();
89 $m->setFooter('MainMenu', 'Test:Autoheader, infinite run');
90 my $r = $m->run('MainMenu',-1);
91  
92 printf "\n%s\n", '-' x 20;
93 my $v = $m->getMatching('MainMenu','test','label','value');
94 printf "Values of Labels /test/ : %s\n", join ' ', @{$v};
95 $v = $m->getMatching('MainMenu','(1|3)','number','value');
96 printf "Values of Numbers /(1|3)/: %s\n", join ' ', @{$v};
97 $v = $m->getMatching('MainMenu','\d+','value','label');
98 printf "Labels of Values /%s/ : %s\n", '\d+', join ' ', @{$v};
99 printf "\n%s\n", '-' x 20;
100  
101 $m->setFooter('MainMenu', 'Test:Autoheader, single run with reaction code');
102 while( $m->run('MainMenu')) {
103 if( $m->currNumber('MainMenu') == 2 ) {
104 my $v = $m->currValue('MainMenu');
105 my $nv= $v == 0 ? 1 : 0;
106 my $lb= $nv == 0 ? 'test1-off' : 'test1-on';
107 $m->setCurrValue('MainMenu',$nv);
108 $m->setCurrLabel('MainMenu',$lb);
109  
110 }
111 }
112  
113 $m->addMenu({'MultiSel'=>$M});
114 $m->run('MultiSel',0);
115 $m->run('MultiSel',0);
116 $m->setCurrDefault('bla','blu'); # err-test
117 $m->setCurrDefault('MultiSel','ok'); # ok-test
118 $m->setCurrReadOnly('bla','blu'); # err-test
119 $m->setCurrReadOnly('MultiSel','ok'); # ok-test
120 print;
121  
122  
123 # my $t = Table([ 'Util-Table',
124 # [ '--H1--', '--H2--', '--H3--'],
125 # [ '11:11:11', 33.456, 'cc ' ],
126 # [ '12:23:00', 2222222, 3 ],
127 # [ '11:11', 222, 3333333333333333 ]]);
128 # print join "\n", @{$t};
129 #
130 # $t = $o->Table([ 'Util-Table as Script::Toolbox Object',
131 # [ '--H1--', '--H2--', '--H3--'],
132 # [ '11:11:11', 33.456, 'cc ' ],
133 # [ '12:23:00', 2222222, 3 ],
134 # [ '11:11', 222, 3333333333333333 ]]);
135 # print join "\n", @{$t};
136 #
137 # my $T = Script::Toolbox::TableO->new([ 'TableO',
138 # [ '--H1--', '--H2--', '--H3--'],
139 # [ '11:11:11', 33.456, 'cc ' ],
140 # [ '12:23:00', 2222222, 3 ],
141 # [ '11:11', 222, 3333333333333333 ]]);
142 # print $T->asString("\n\n");
143 # return;
144 }
145  
146 #------------------------------------------------------------------------------
147 #------------------------------------------------------------------------------
148 sub main(){
149 #test1();
150 testCheckBox();
151 return;
152 }
153  
154 main();
155  
156  
157 ############################################################################
158 1;
159 __END__