1###############################################################################
2#
3# A test for Spreadsheet::WriteExcel::Chart.
4#
5# Tests for the Excel Chart.pm methods.
6#
7# reverse('�'), December 2009, John McNamara, jmcnamara@cpan.org
8#
9
10# prove -I../lib --nocolor -v 60_chart_generic.t
11
12use strict;
13
14use Spreadsheet::WriteExcel::Chart;
15
16use Test::More tests => 41;
17
18
19###############################################################################
20#
21# Tests setup
22#
23my $chart = Spreadsheet::WriteExcel::Chart->new();
24my $got;
25my $expected;
26my $caption;
27my $string;
28my @values;
29
30###############################################################################
31#
32# Test the _store_fbi method.
33#
34$caption = " \tChart: _store_fbi()";
35
36$expected = join ' ', qw(
37  60 10 0A 00 B8 38 A1 22 C8 00 00 00 05 00
38);
39
40$got = unpack_record( $chart->_store_fbi( 5, 10, 0x38B8, 0x22A1, 0x0000 ) );
41
42is( $got, $expected, $caption );
43
44###############################################################################
45#
46# Test the _store_fbi method.
47#
48$expected = join ' ', qw(
49  60 10 0A 00 B8 38 A1 22 C8 00 00 00 06 00
50);
51
52$got = unpack_record( $chart->_store_fbi( 6, 10, 0x38B8, 0x22A1, 0x0000 ) );
53
54is( $got, $expected, $caption );
55
56
57###############################################################################
58#
59# Test the _store_chart method.
60#
61$caption = " \tChart: _store_chart()";
62
63$expected = join ' ', qw(
64  02 10 10 00 00 00 00 00 00 00 00 00 E0 51 DD 02
65  38 B8 C2 01
66);
67
68@values = ( 0x0000, 0x0000, 0x02DD51E0, 0x01C2B838 );
69
70$got = unpack_record( $chart->_store_chart( @values ) );
71
72is( $got, $expected, $caption );
73
74
75###############################################################################
76#
77# Test the _store_series() method.
78#
79$caption = " \tChart: _store_series()";
80
81$expected = join ' ', qw(
82  03 10 0C 00 01 00 01 00 08 00 08 00 01 00 00 00
83);
84
85$got = unpack_record( $chart->_store_series( 8, 8 ) );
86
87is( $got, $expected, $caption );
88
89
90###############################################################################
91#
92# Test the _store_begin() method.
93#
94$caption = " \tChart: _store_begin()";
95
96$expected = join ' ', qw(
97  33 10 00 00
98);
99
100$got = unpack_record( $chart->_store_begin() );
101
102is( $got, $expected, $caption );
103
104
105###############################################################################
106#
107# Test the _store_end() method.
108#
109$caption = " \tChart: _store_end()";
110
111$expected = join ' ', qw(
112  34 10 00 00
113);
114
115$got = unpack_record( $chart->_store_end() );
116
117is( $got, $expected, $caption );
118
119
120###############################################################################
121#
122# Test the _store_ai() method.
123#
124$caption = " \tChart: _store_ai()";
125
126@values = ( 0, 1, '' );
127
128$expected = join ' ', qw(
129  51 10 08 00 00 01 00 00 00 00 00 00
130);
131
132$got = unpack_record( $chart->_store_ai( @values ) );
133
134is( $got, $expected, $caption );
135
136
137###############################################################################
138#
139# Test the _store_ai() method.
140#
141$caption = " \tChart: _store_ai()";
142
143@values = ( 1, 2, pack 'H*', '3B00000000070000000000' );
144
145$expected = join ' ', qw(
146  51 10 13 00 01 02 00 00 00 00 0B 00 3B 00 00 00
147  00 07 00 00 00 00 00
148);
149
150$got = unpack_record( $chart->_store_ai( @values ) );
151
152is( $got, $expected, $caption );
153
154
155###############################################################################
156#
157# Test the _store_dataformat() method.
158#
159$caption = " \tChart: _store_dataformat()";
160
161$expected = join ' ', qw(
162  06 10 08 00 FF FF 00 00 00 00 00 00
163);
164
165$got = unpack_record( $chart->_store_dataformat( 0, 0, 0xFFFF ) );
166
167is( $got, $expected, $caption );
168
169
170###############################################################################
171#
172# Test the _store_dataformat() method.
173#
174$caption = " \tChart: _store_dataformat()";
175
176$expected = join ' ', qw(
177  06 10 08 00 00 00 00 00 FD FF 00 00
178);
179
180$got = unpack_record( $chart->_store_dataformat( 0, 0xFFFD, 0 ) );
181
182is( $got, $expected, $caption );
183
184
185###############################################################################
186#
187# Test the _store_3dbarshape() method.
188#
189$caption = " \tChart: _store_3dbarshape()";
190
191$expected = join ' ', qw(
192  5F 10 02 00 00 00
193);
194
195$got = unpack_record( $chart->_store_3dbarshape() );
196
197is( $got, $expected, $caption );
198
199
200###############################################################################
201#
202# Test the _store_sertocrt() method.
203#
204$caption = " \tChart: _store_sertocrt()";
205
206$expected = join ' ', qw(
207  45 10 02 00 00 00
208);
209
210$got = unpack_record( $chart->_store_sertocrt() );
211
212is( $got, $expected, $caption );
213
214
215###############################################################################
216#
217# Test the _store_shtprops() method.
218#
219$caption = " \tChart: _store_shtprops()";
220
221$expected = join ' ', qw(
222  44 10 04 00 0E 00 00 00
223);
224
225$got = unpack_record( $chart->_store_shtprops() );
226
227is( $got, $expected, $caption );
228
229
230###############################################################################
231#
232# Test the _store_defaulttext() method.
233#
234$caption = " \tChart: _store_defaulttext()";
235
236$expected = join ' ', qw(
237  24 10 02 00 02 00
238);
239
240$got = unpack_record( $chart->_store_defaulttext() );
241
242is( $got, $expected, $caption );
243
244
245###############################################################################
246#
247# Test the _store_charttext() method.
248#
249$caption = " \tChart: _store_charttext()";
250
251$expected = join ' ', qw(
252  25 10 20 00 02 02 01 00 00 00 00 00 46 FF FF FF
253  06 FF FF FF 00 00 00 00 00 00 00 00 B1 00 4D 00
254  00 00 00 00
255);
256
257$got = unpack_record( $chart->_store_charttext() );
258
259is( $got, $expected, $caption );
260
261
262###############################################################################
263#
264# Test the _store_fontx() method.
265#
266$caption = " \tChart: _store_fontx()";
267
268$expected = join ' ', qw(
269  26 10 02 00 05 00
270);
271
272$got = unpack_record( $chart->_store_fontx( 5 ) );
273
274is( $got, $expected, $caption );
275
276
277###############################################################################
278#
279# Test the _store_axesused() method.
280#
281$caption = " \tChart: _store_axesused()";
282
283$expected = join ' ', qw(
284  46 10 02 00 01 00
285);
286
287$got = unpack_record( $chart->_store_axesused( 1 ) );
288
289is( $got, $expected, $caption );
290
291
292###############################################################################
293#
294# Test the _store_axisparent() method.
295#
296$caption = " \tChart: _store_axisparent()";
297
298$expected = join ' ', qw(
299  41 10 12 00 00 00 F8 00 00 00 F5 01 00 00 7F 0E
300  00 00 36 0B 00 00
301);
302
303@values = ( 0, 0x00F8, 0x01F5, 0x0E7F, 0x0B36 );
304
305$got = unpack_record( $chart->_store_axisparent( @values ) );
306
307is( $got, $expected, $caption );
308
309
310###############################################################################
311#
312# Test the _store_axis() method.
313#
314$caption = " \tChart: _store_axis()";
315
316$expected = join ' ', qw(
317  1D 10 12 00 00 00 00 00 00 00 00 00 00 00 00 00
318  00 00 00 00 00 00
319);
320
321$got = unpack_record( $chart->_store_axis( 0 ) );
322
323is( $got, $expected, $caption );
324
325###############################################################################
326#
327# Test the _store_catserrange() method.
328#
329$caption = " \tChart: _store_catserrange()";
330
331$expected = join ' ', qw(
332  20 10 08 00 01 00 01 00 01 00 01 00
333);
334
335$got = unpack_record( $chart->_store_catserrange() );
336
337is( $got, $expected, $caption );
338
339
340###############################################################################
341#
342# Test the _store_axcext() method.
343#
344$caption = " \tChart: _store_axcext()";
345
346$expected = join ' ', qw(
347  62 10 12 00 00 00 00 00 01 00 00 00 01 00 00 00
348  00 00 00 00 EF 00
349);
350
351$got = unpack_record( $chart->_store_axcext() );
352
353is( $got, $expected, $caption );
354
355
356###############################################################################
357#
358# Test the _store_tick() method.
359#
360$caption = " \tChart: _store_tick()";
361
362$expected = join ' ', qw(
363  1E 10 1E 00 02 00 03 01 00 00 00 00 00 00 00 00
364  00 00 00 00 00 00 00 00 00 00 00 00 23 00 4D 00
365  00 00
366);
367
368$got = unpack_record( $chart->_store_tick() );
369
370is( $got, $expected, $caption );
371
372
373###############################################################################
374#
375# Test the _store_valuerange() method.
376#
377$caption = " \tChart: _store_valuerange()";
378
379$expected = join ' ', qw(
380  1F 10 2A 00 00 00 00 00 00 00 00 00 00 00 00 00
381  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
382  00 00 00 00 00 00 00 00 00 00 00 00 1F 01
383);
384
385$got = unpack_record( $chart->_store_valuerange() );
386
387is( $got, $expected, $caption );
388
389
390###############################################################################
391#
392# Test the _store_axislineformat() method.
393#
394$caption = " \tChart: _store_axislineformat()";
395
396$expected = join ' ', qw(
397  21 10 02 00 01 00
398);
399
400$got = unpack_record( $chart->_store_axislineformat() );
401
402is( $got, $expected, $caption );
403
404
405###############################################################################
406#
407# Test the _store_lineformat() method.
408#
409$caption = " \tChart: _store_lineformat()";
410
411$expected = join ' ', qw(
412  07 10 0C 00 00 00 00 00 00 00 FF FF 09 00 4D 00
413);
414
415@values = ( 0x00000000, 0x0000, 0xFFFF, 0x0009, 0x004D );
416
417$got = unpack_record( $chart->_store_lineformat( @values ) );
418
419is( $got, $expected, $caption );
420
421
422###############################################################################
423#
424# Test the _store_frame() method.
425#
426$caption = " \tChart: _store_frame()";
427
428$expected = join ' ', qw(
429  32 10 04 00 00 00 03 00
430);
431
432$got = unpack_record( $chart->_store_frame( 0x00, 0x03 ) );
433
434is( $got, $expected, $caption );
435
436
437###############################################################################
438#
439# Test the _store_areaformat() method.
440#
441$caption = " \tChart: _store_areaformat()";
442
443$expected = join ' ', qw(
444  0A 10 10 00 C0 C0 C0 00 00 00 00 00 01 00 00 00
445  16 00 4F 00
446);
447
448@values = ( 0x00C0C0C0, 0x00, 0x01, 0x00, 0x16, 0x4F );
449$got = unpack_record( $chart->_store_areaformat( @values ) );
450
451is( $got, $expected, $caption );
452
453
454###############################################################################
455#
456# Test the _store_chartformat() method.
457#
458$caption = " \tChart: _store_chartformat()";
459
460$expected = join ' ', qw(
461  14 10 14 00 00 00 00 00 00 00 00 00 00 00 00 00
462  00 00 00 00 00 00 00 00
463);
464
465$got = unpack_record( $chart->_store_chartformat() );
466
467is( $got, $expected, $caption );
468
469
470###############################################################################
471#
472# Test the _store_legend() method.
473#
474$caption = " \tChart: _store_legend()";
475
476$expected = join ' ', qw(
477  15 10 14 00 F9 05 00 00 E9 0E 00 00 7D 04 00 00
478  9C 00 00 00 00 01 0F 00
479);
480
481@values = ( 0x05F9, 0x0EE9, 0x047D, 0x009C, 0x00, 0x01, 0x000F );
482
483$got = unpack_record( $chart->_store_legend( @values ) );
484
485is( $got, $expected, $caption );
486
487
488###############################################################################
489#
490# Test the _store_pos() method.
491#
492$caption = " \tChart: _store_pos()";
493
494$expected = join ' ', qw(
495  4F 10 14 00 05 00 02 00 83 0E 00 00 F9 06 00 00
496  00 00 00 00 00 00 00 00
497);
498
499@values = ( 5, 2, 0x0E83, 0x06F9, 0, 0 );
500
501$got = unpack_record( $chart->_store_pos( @values ) );
502
503is( $got, $expected, $caption );
504
505
506###############################################################################
507#
508# Test the _store_text() method.
509#
510$caption = " \tChart: _store_text()";
511
512$expected = join ' ', qw(
513
514  25 10 20 00 02 02 01 00 00 00 00 00 46 FF FF FF
515  06 FF FF FF 00 00 00 00 00 00 00 00 B1 00 4D 00
516  20 10 00 00
517);
518
519@values = ( 0xFFFFFF46, 0xFFFFFF06, 0, 0, 0x00B1, 0x1020 );
520
521$got = unpack_record( $chart->_store_text( @values ) );
522
523is( $got, $expected, $caption );
524
525
526###############################################################################
527#
528# Test the _store_plotgrowth() method.
529#
530$caption = " \tChart: _store_plotgrowth()";
531
532$expected = join ' ', qw(
533  64 10 08 00 00 00 01 00 00 00 01 00
534);
535
536$got = unpack_record( $chart->_store_plotgrowth() );
537
538is( $got, $expected, $caption );
539
540
541###############################################################################
542#
543# Test the _store_seriestext() method.
544#
545$caption = " \tChart: _store_seriestext()";
546
547$expected = join ' ', qw(
548  0D 10 14 00 00 00 10 00 4E 61 6D 65
549  20 66 6F 72 20 53 65 72
550  69 65 73 31
551);
552
553$string = 'Name for Series1';
554
555$got = unpack_record( $chart->_store_seriestext( $string, 0 ) );
556
557is( $got, $expected, $caption );
558
559
560###############################################################################
561#
562# Test the _store_seriestext() method. UTF-16 string.
563#
564$caption = " \tChart: _store_seriestext()";
565
566$expected = join ' ', qw(
567  0D 10 24 00 00 00 10 01 4E 00 61 00 6D 00 65 00
568  20 00 66 00 6F 00 72 00 20 00 53 00 65 00 72 00
569  69 00 65 00 73 00 31 00
570);
571
572$string = pack 'n*', unpack 'C*', 'Name for Series1';
573
574$got = unpack_record( $chart->_store_seriestext( $string, 1 ) );
575
576is( $got, $expected, $caption );
577
578
579###############################################################################
580#
581# Test the _store_objectlink() method.
582#
583$caption = " \tChart: _store_objectlink()";
584
585$expected = join ' ', qw(
586  27 10 06 00 01 00 00 00 00 00
587);
588
589$got = unpack_record( $chart->_store_objectlink( 1 ) );
590
591is( $got, $expected, $caption );
592
593
594###############################################################################
595#
596# Test the _store_pieformat() method.
597#
598$caption = " \tChart: _store_pieformat()";
599
600$expected = join ' ', qw(
601  0B 10 02 00 00 00
602);
603
604$got = unpack_record( $chart->_store_pieformat() );
605
606is( $got, $expected, $caption );
607
608
609###############################################################################
610#
611# Test the _store_markerformat() method.
612#
613$caption = " \tChart: _store_markerformat()";
614
615$expected = join ' ', qw(
616  09 10 14 00 00 00 00 00 00 00 00 00 02 00 01 00
617  4D 00 4D 00 3C 00 00 00
618);
619
620@values = ( 0x00, 0x00, 0x02, 0x01, 0x4D, 0x4D, 0x3C );
621
622
623$got = unpack_record( $chart->_store_markerformat( @values ) );
624
625is( $got, $expected, $caption );
626
627
628###############################################################################
629#
630# Test the _store_dropbar() method.
631#
632$caption = " \tChart: _store_dropbar()";
633
634$expected = join ' ', qw(
635  3D 10 02 00 96 00
636);
637
638$got = unpack_record( $chart->_store_dropbar() );
639
640is( $got, $expected, $caption );
641
642
643###############################################################################
644#
645# Test the _store_chartline() method.
646#
647$caption = " \tChart: _store_chartline()";
648
649$expected = join ' ', qw(
650  1C 10 02 00 01 00
651);
652
653$got = unpack_record( $chart->_store_chartline() );
654
655is( $got, $expected, $caption );
656
657
658###############################################################################
659#
660# Test the _store_serparent() method.
661#
662$caption = " \tChart: _store_serparent()";
663
664$expected = join ' ', qw(
665  4A 10 02 00 01 00
666);
667
668$got = unpack_record( $chart->_store_serparent( 1 ) );
669
670is( $got, $expected, $caption );
671
672
673###############################################################################
674#
675# Test the _store_serauxtrend() method
676#
677$caption = " \tChart: _store_serauxtrend()";
678
679$expected = join ' ', qw(
680  4B 10 1C 00 00 01 FF FF FF FF 00 01 FF FF 00 00
681  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
682);
683
684@values = ( 0x00, 0x01, 0x00, 0x00 );
685
686$got = unpack_record( $chart->_store_serauxtrend( @values ) );
687
688is( $got, $expected, $caption );
689
690
691###############################################################################
692#
693# Utility function used by the test suite.
694#
695# Unpack the binary data into a format suitable for printing in tests.
696#
697sub unpack_record {
698    return join ' ', map { sprintf '%02X', $_ } unpack 'C*', shift;
699}
700
701
702__END__
703