1#!perl
2use strict;
3use warnings;
4use Test::More tests => 39;
5# use Test::More 'no_plan';
6
7BEGIN
8{
9   eval "use Test::Deep";
10   $main::Test_Deep_loaded = $@ ? 0 : 1;
11
12   $| = 1;
13};
14
15
16# use lib '../../../lib';
17use Text::Report;
18
19# ----------------------------- #
20# --- Create new report obj --- #
21# ----------------------------- #
22my $rpt = Text::Report->new(debug => 'off', debugv => 1,);
23
24main
25{
26   _test_defaults();
27
28   my @data = _getdata();
29
30   _build_report1(@data);
31}
32
33exit(1);
34
35
36sub _build_report1
37{
38   my @data = @_;
39   my @stuff;
40
41   $stuff[0] = 'Simple Report';
42   $stuff[1] = 'One 3-Dimensional Array';
43   $stuff[2] = 'Pretty Average Weather Stuff';
44   $stuff[3] = ' ';
45   $stuff[4] = '==========';
46   $stuff[5] = ' ';
47   $stuff[6] = ' ';
48   $stuff[7] = ' ';
49   $stuff[8] = 'Solaris Host Intf Activity';
50   $stuff[9] = '-------------';
51   $stuff[10] = ' ';
52   $stuff[11] = 'Server';
53   $stuff[12] = '_______';
54   $stuff[13] = 'lnc0';
55   $stuff[14] = 'lnc1';
56   $stuff[15] = 'lnc2';
57   $stuff[16] = 'lnc3';
58   $stuff[17] = 'lnc4';
59   $stuff[18] = 'lnc5';
60   $stuff[19] = 'lnc6';
61   $stuff[20] = ' ';
62   $stuff[21] = ' ';
63
64
65   # --------------------------- #
66   # --- Create Report Title --- #
67   # --------------------------- #
68   is(
69      $rpt->defblock(name => 'title_lines', noHeaders => 1),
70      $rpt,
71      "Defining block \'title_lines\' with \'noHeaders\' set should return report obj");
72   # Use the default report width (80 char)
73
74   # --- Separate our header from the --- #
75   # --- report body w/a double line  --- #
76   is($rpt->insert('dbl_line'), $rpt, "Build 1st dbl_line separator should return report obj");
77
78   $rpt->defblock(name => 'sd2',
79         title => $stuff[8],
80         useColHeaders => 1,
81         sortby => 1,
82         sorttype => 'alpha',
83         orderby => 'ascending',
84         columnWidth => 12,
85         columnAlign => 'right',
86         pad => {top => 2, bottom => 2},);
87
88   my $header = shift(@data);
89
90   my $i = 0;
91
92   # --- Place col headers from 1st line of data --- #
93   for(@{$header}){$rpt->setcol('sd2', ++$i, head => $_);}
94
95   $rpt->setcol('sd2', 1, align => 'left', width => 7);
96
97   $rpt->fill_block('title_lines', [$stuff[0]], [$stuff[1]], [$stuff[2]],);
98
99   is($rpt->fill_block('sd2', @data), $rpt, "Valid blockname should return report obj");
100   is($rpt->fill_block('bla', @data), undef, "Invalid blockname should return undef");
101
102   # --- Get csv data for block name 'sd2' --- #
103   my @csv = $rpt->get_csv('sd2');
104
105   my $x = 0;
106
107   # --- Remove Title & Header --- #
108   shift(@{$csv[0]}); shift(@{$csv[0]});
109
110   # --- Check CSV data matches original data set --- #
111   for(@csv)
112   {
113      for(@{$_})
114      {
115         like( $_, "/$data[$x++][0]/", "Line $x CSV data should match line $x of original data" );
116      }
117
118   }
119
120   # --- Check that report gives us what we expect --- #
121   my @report = $rpt->report('get');
122
123   $x = 0;
124
125   for(@report)
126   {
127      like( $_, "/$stuff[$x++]/i", "Line $x report data should match line $x of original data" );
128   }
129}
130
131
132sub _test_defaults
133{
134   SKIP: {
135      skip "Test::Deep not installed", 6 unless $main::Test_Deep_loaded;
136
137      # --- Check default report width = 80 --- #
138      cmp_deeply($rpt->{_page}{_profile}{report}{width}, 80,
139         "Confirming default report width = 80");
140
141      # --- Check default block column width = 80 --- #
142      cmp_deeply($rpt->{_block}{_profile}{_block}{column}, {1 => {width => 80, align => 'center'},},
143         "Confirming default block column settings =  {1 => {width => 80, align => \'center\'}}");
144
145      cmp_deeply($rpt->{_block}{_profile}{_block}{pad}, {top => 0, bottom => 1},
146         "Confirming default blockPad is {top => 0, bottom => 1}");
147
148      cmp_deeply($rpt->{_block}{_profile}{_block}{column}, {1 => {width => 80, align => 'center'},},
149         "Confirming default column is 1 => {width => 80, align => \'center\'}");
150
151      # --- Cols should default to using NO headers --- #
152      cmp_deeply($rpt->{_block}{_profile}{_block}{useColHeaders}, 0,
153         "Confirming default useColHeaders is \"OFF\"");
154
155      # --- Test column sorting properties --- #
156      cmp_deeply($rpt->{_block}{_profile}{_block}{sortby}, 0,
157         "Confirming default column sort key is \"OFF\"");
158   }
159}
160
161sub _getdata
162{
163   return(
164   ['Server','Pkts Out','Bytes Out','Pkts In','Bytes In'],
165   [qw(lnc0 6700730 3163758138 105780764 2526211316)],
166   [qw(lnc1 332616 20424792 273036 16382160)],
167   [qw(lnc2 13594464 2362497118 105780764 2526211316)],
168   [qw(lnc3 312207 115266948 215356 66329648)],
169   [qw(lnc4 4100 262400 4101 246060)],
170   [qw(lnc5 2469926 1507952738 105780764 2526211316)],
171   [qw(lnc6 503645 30218700 1811 108660)],
172   );
173}
174