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