1 /*
2  * Tests for the lib_xlsx_writer library.
3  *
4  * Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
5  *
6  */
7 
8 #include "../ctest.h"
9 #include "../helper.h"
10 
11 #include "../../../include/xlsxwriter/styles.h"
12 #include "../../../include/xlsxwriter/format.h"
13 
14 // Test the _write_xf() method. Default properties.
CTEST(styles,write_xf01)15 CTEST(styles, write_xf01) {
16 
17     char* got;
18     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>";
19     FILE* testfile = lxw_tmpfile(NULL);
20 
21     lxw_styles *styles = lxw_styles_new();
22     lxw_format *format = lxw_format_new();
23 
24     styles->file = testfile;
25 
26     _write_xf(styles, format);
27 
28     RUN_XLSX_STREQ(exp, got);
29 
30     lxw_styles_free(styles);
31     lxw_format_free(format);
32 }
33 
34 
35 // Test the _write_xf() method. Has font but is first XF.
CTEST(styles,write_xf02)36 CTEST(styles, write_xf02) {
37 
38     char* got;
39     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>";
40     FILE* testfile = lxw_tmpfile(NULL);
41 
42     lxw_styles *styles = lxw_styles_new();
43     lxw_format *format = lxw_format_new();
44 
45     format->has_font = 1;
46 
47     styles->file = testfile;
48 
49     _write_xf(styles, format);
50 
51     RUN_XLSX_STREQ(exp, got);
52 
53     lxw_styles_free(styles);
54     lxw_format_free(format);
55 }
56 
57 
58 // Test the _write_xf() method. Has font but isn't first XF.
CTEST(styles,write_xf03)59 CTEST(styles, write_xf03) {
60 
61     char* got;
62     char exp[] = "<xf numFmtId=\"0\" fontId=\"1\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyFont=\"1\"/>";
63     FILE* testfile = lxw_tmpfile(NULL);
64 
65     lxw_styles *styles = lxw_styles_new();
66     lxw_format *format = lxw_format_new();
67 
68     format->has_font = 1;
69     format->font_index = 1;
70 
71     styles->file = testfile;
72 
73     _write_xf(styles, format);
74 
75     RUN_XLSX_STREQ(exp, got);
76 
77     lxw_styles_free(styles);
78     lxw_format_free(format);
79 }
80 
81 
82 // Test the _write_xf() method. Uses built-in number format.
CTEST(styles,write_xf04)83 CTEST(styles, write_xf04) {
84 
85     char* got;
86     char exp[] = "<xf numFmtId=\"2\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\"/>";
87     FILE* testfile = lxw_tmpfile(NULL);
88 
89     lxw_styles *styles = lxw_styles_new();
90     lxw_format *format = lxw_format_new();
91 
92     format_set_num_format_index(format, 2);
93 
94     styles->file = testfile;
95 
96     _write_xf(styles, format);
97 
98     RUN_XLSX_STREQ(exp, got);
99 
100     lxw_styles_free(styles);
101     lxw_format_free(format);
102 }
103 
104 
105 // Test the _write_xf() method. Uses built-in number format + font.
CTEST(styles,write_xf05)106 CTEST(styles, write_xf05) {
107 
108     char* got;
109     char exp[] = "<xf numFmtId=\"2\" fontId=\"1\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\" applyFont=\"1\"/>";
110     FILE* testfile = lxw_tmpfile(NULL);
111 
112     lxw_styles *styles = lxw_styles_new();
113     lxw_format *format = lxw_format_new();
114 
115     format_set_num_format_index(format, 2);
116     format->has_font = 1;
117     format->font_index = 1;
118 
119     styles->file = testfile;
120 
121     _write_xf(styles, format);
122 
123     RUN_XLSX_STREQ(exp, got);
124 
125     lxw_styles_free(styles);
126     lxw_format_free(format);
127 }
128 
129 
130 // Test the _write_xf() method. Vertical alignment = top.
CTEST(styles,write_xf06)131 CTEST(styles, write_xf06) {
132 
133     char* got;
134     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"top\"/></xf>";
135     FILE* testfile = lxw_tmpfile(NULL);
136 
137     lxw_styles *styles = lxw_styles_new();
138     lxw_format *format = lxw_format_new();
139 
140     format_set_align(format, LXW_ALIGN_VERTICAL_TOP);
141 
142     styles->file = testfile;
143 
144     _write_xf(styles, format);
145 
146     RUN_XLSX_STREQ(exp, got);
147 
148     lxw_styles_free(styles);
149     lxw_format_free(format);
150 }
151 
152 
153 // Test the _write_xf() method. Vertical alignment = centre.
CTEST(styles,write_xf07)154 CTEST(styles, write_xf07) {
155 
156     char* got;
157     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"center\"/></xf>";
158     FILE* testfile = lxw_tmpfile(NULL);
159 
160     lxw_styles *styles = lxw_styles_new();
161     lxw_format *format = lxw_format_new();
162 
163     format_set_align(format, LXW_ALIGN_VERTICAL_CENTER);
164 
165     styles->file = testfile;
166 
167     _write_xf(styles, format);
168 
169     RUN_XLSX_STREQ(exp, got);
170 
171     lxw_styles_free(styles);
172     lxw_format_free(format);
173 }
174 
175 
176 // Test the _write_xf() method. Vertical alignment = bottom.
CTEST(styles,write_xf08)177 CTEST(styles, write_xf08) {
178 
179     char* got;
180     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"/>";
181     FILE* testfile = lxw_tmpfile(NULL);
182 
183     lxw_styles *styles = lxw_styles_new();
184     lxw_format *format = lxw_format_new();
185 
186     format_set_align(format, LXW_ALIGN_VERTICAL_BOTTOM);
187 
188     styles->file = testfile;
189 
190     _write_xf(styles, format);
191 
192     RUN_XLSX_STREQ(exp, got);
193 
194     lxw_styles_free(styles);
195     lxw_format_free(format);
196 }
197 
198 
199 // Test the _write_xf() method. Vertical alignment = justify.
CTEST(styles,write_xf09)200 CTEST(styles, write_xf09) {
201 
202     char* got;
203     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"justify\"/></xf>";
204     FILE* testfile = lxw_tmpfile(NULL);
205 
206     lxw_styles *styles = lxw_styles_new();
207     lxw_format *format = lxw_format_new();
208 
209     format_set_align(format, LXW_ALIGN_VERTICAL_JUSTIFY);
210 
211     styles->file = testfile;
212 
213     _write_xf(styles, format);
214 
215     RUN_XLSX_STREQ(exp, got);
216 
217     lxw_styles_free(styles);
218     lxw_format_free(format);
219 }
220 
221 
222 // Test the _write_xf() method. Vertical alignment = distributed.
CTEST(styles,write_xf10)223 CTEST(styles, write_xf10) {
224 
225     char* got;
226     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"distributed\"/></xf>";
227     FILE* testfile = lxw_tmpfile(NULL);
228 
229     lxw_styles *styles = lxw_styles_new();
230     lxw_format *format = lxw_format_new();
231 
232     format_set_align(format, LXW_ALIGN_VERTICAL_DISTRIBUTED);
233 
234     styles->file = testfile;
235 
236     _write_xf(styles, format);
237 
238     RUN_XLSX_STREQ(exp, got);
239 
240     lxw_styles_free(styles);
241     lxw_format_free(format);
242 }
243 
244 
245 // Test the _write_xf() method. Horizontal alignment = left.
CTEST(styles,write_xf11)246 CTEST(styles, write_xf11) {
247 
248     char* got;
249     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\"/></xf>";
250     FILE* testfile = lxw_tmpfile(NULL);
251 
252     lxw_styles *styles = lxw_styles_new();
253     lxw_format *format = lxw_format_new();
254 
255     format_set_align(format, LXW_ALIGN_LEFT);
256 
257     styles->file = testfile;
258 
259     _write_xf(styles, format);
260 
261     RUN_XLSX_STREQ(exp, got);
262 
263     lxw_styles_free(styles);
264     lxw_format_free(format);
265 }
266 
267 
268 // Test the _write_xf() method. Horizontal alignment = center.
CTEST(styles,write_xf12)269 CTEST(styles, write_xf12) {
270 
271     char* got;
272     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"center\"/></xf>";
273     FILE* testfile = lxw_tmpfile(NULL);
274 
275     lxw_styles *styles = lxw_styles_new();
276     lxw_format *format = lxw_format_new();
277 
278     format_set_align(format, LXW_ALIGN_CENTER);
279 
280     styles->file = testfile;
281 
282     _write_xf(styles, format);
283 
284     RUN_XLSX_STREQ(exp, got);
285 
286     lxw_styles_free(styles);
287     lxw_format_free(format);
288 }
289 
290 
291 // Test the _write_xf() method. Horizontal alignment = right.
CTEST(styles,write_xf13)292 CTEST(styles, write_xf13) {
293 
294     char* got;
295     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"right\"/></xf>";
296     FILE* testfile = lxw_tmpfile(NULL);
297 
298     lxw_styles *styles = lxw_styles_new();
299     lxw_format *format = lxw_format_new();
300 
301     format_set_align(format, LXW_ALIGN_RIGHT);
302 
303     styles->file = testfile;
304 
305     _write_xf(styles, format);
306 
307     RUN_XLSX_STREQ(exp, got);
308 
309     lxw_styles_free(styles);
310     lxw_format_free(format);
311 }
312 
313 
314 // Test the _write_xf() method. Horizontal alignment = left + indent.
CTEST(styles,write_xf14)315 CTEST(styles, write_xf14) {
316 
317     char* got;
318     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\" indent=\"1\"/></xf>";
319     FILE* testfile = lxw_tmpfile(NULL);
320 
321     lxw_styles *styles = lxw_styles_new();
322     lxw_format *format = lxw_format_new();
323 
324     format_set_align(format, LXW_ALIGN_LEFT);
325     format->indent = 1;
326 
327     styles->file = testfile;
328 
329     _write_xf(styles, format);
330 
331     RUN_XLSX_STREQ(exp, got);
332 
333     lxw_styles_free(styles);
334     lxw_format_free(format);
335 }
336 
337 
338 // Test the _write_xf() method. Horizontal alignment = right + indent.
CTEST(styles,write_xf15)339 CTEST(styles, write_xf15) {
340 
341     char* got;
342     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"right\" indent=\"1\"/></xf>";
343     FILE* testfile = lxw_tmpfile(NULL);
344 
345     lxw_styles *styles = lxw_styles_new();
346     lxw_format *format = lxw_format_new();
347 
348     format_set_align(format, LXW_ALIGN_RIGHT);
349     format_set_indent(format, 1);
350 
351     styles->file = testfile;
352 
353     _write_xf(styles, format);
354 
355     RUN_XLSX_STREQ(exp, got);
356 
357     lxw_styles_free(styles);
358     lxw_format_free(format);
359 }
360 
361 
362 // Test the _write_xf() method. Horizontal alignment = fill.
CTEST(styles,write_xf16)363 CTEST(styles, write_xf16) {
364 
365     char* got;
366     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"fill\"/></xf>";
367     FILE* testfile = lxw_tmpfile(NULL);
368 
369     lxw_styles *styles = lxw_styles_new();
370     lxw_format *format = lxw_format_new();
371 
372     format_set_align(format, LXW_ALIGN_FILL);
373 
374     styles->file = testfile;
375 
376     _write_xf(styles, format);
377 
378     RUN_XLSX_STREQ(exp, got);
379 
380     lxw_styles_free(styles);
381     lxw_format_free(format);
382 }
383 
384 
385 // Test the _write_xf() method. Horizontal alignment = justify.
CTEST(styles,write_xf17)386 CTEST(styles, write_xf17) {
387 
388     char* got;
389     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"justify\"/></xf>";
390     FILE* testfile = lxw_tmpfile(NULL);
391 
392     lxw_styles *styles = lxw_styles_new();
393     lxw_format *format = lxw_format_new();
394 
395     format_set_align(format, LXW_ALIGN_JUSTIFY);
396 
397     styles->file = testfile;
398 
399     _write_xf(styles, format);
400 
401     RUN_XLSX_STREQ(exp, got);
402 
403     lxw_styles_free(styles);
404     lxw_format_free(format);
405 }
406 
407 
408 // Test the _write_xf() method. Horizontal alignment = center across.
CTEST(styles,write_xf18)409 CTEST(styles, write_xf18) {
410 
411     char* got;
412     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"centerContinuous\"/></xf>";
413     FILE* testfile = lxw_tmpfile(NULL);
414 
415     lxw_styles *styles = lxw_styles_new();
416     lxw_format *format = lxw_format_new();
417 
418     format_set_align(format, LXW_ALIGN_CENTER_ACROSS);
419 
420     styles->file = testfile;
421 
422     _write_xf(styles, format);
423 
424     RUN_XLSX_STREQ(exp, got);
425 
426     lxw_styles_free(styles);
427     lxw_format_free(format);
428 }
429 
430 
431 // Test the _write_xf() method. Horizontal alignment = distributed.
CTEST(styles,write_xf19)432 CTEST(styles, write_xf19) {
433 
434     char* got;
435     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\"/></xf>";
436     FILE* testfile = lxw_tmpfile(NULL);
437 
438     lxw_styles *styles = lxw_styles_new();
439     lxw_format *format = lxw_format_new();
440 
441     format_set_align(format, LXW_ALIGN_DISTRIBUTED);
442 
443     styles->file = testfile;
444 
445     _write_xf(styles, format);
446 
447     RUN_XLSX_STREQ(exp, got);
448 
449     lxw_styles_free(styles);
450     lxw_format_free(format);
451 }
452 
453 
454 // Test the _write_xf() method. Horizontal alignment = distributed + indent.
CTEST(styles,write_xf20)455 CTEST(styles, write_xf20) {
456 
457     char* got;
458     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" indent=\"1\"/></xf>";
459     FILE* testfile = lxw_tmpfile(NULL);
460 
461     lxw_styles *styles = lxw_styles_new();
462     lxw_format *format = lxw_format_new();
463 
464     format_set_align(format, LXW_ALIGN_DISTRIBUTED);
465     format_set_indent(format, 1);
466 
467     styles->file = testfile;
468 
469     _write_xf(styles, format);
470 
471     RUN_XLSX_STREQ(exp, got);
472 
473     lxw_styles_free(styles);
474     lxw_format_free(format);
475 }
476 
477 
478 // Test the _write_xf() method. Horizontal alignment = justify distributed.
CTEST(styles,write_xf21)479 CTEST(styles, write_xf21) {
480 
481     char* got;
482     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" justifyLastLine=\"1\"/></xf>";
483     FILE* testfile = lxw_tmpfile(NULL);
484 
485     lxw_styles *styles = lxw_styles_new();
486     lxw_format *format = lxw_format_new();
487 
488     format_set_align(format, LXW_ALIGN_DISTRIBUTED);
489     format->just_distrib = 1;
490 
491     styles->file = testfile;
492 
493     _write_xf(styles, format);
494 
495     RUN_XLSX_STREQ(exp, got);
496 
497     lxw_styles_free(styles);
498     lxw_format_free(format);
499 }
500 
501 
502 // Test the _write_xf() method. Horizontal alignment = indent only.
503 // This should default to left alignment.
CTEST(styles,write_xf22)504 CTEST(styles, write_xf22) {
505 
506     char* got;
507     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\" indent=\"1\"/></xf>";
508     FILE* testfile = lxw_tmpfile(NULL);
509 
510     lxw_styles *styles = lxw_styles_new();
511     lxw_format *format = lxw_format_new();
512 
513     format_set_indent(format, 1);
514 
515     styles->file = testfile;
516 
517     _write_xf(styles, format);
518 
519     RUN_XLSX_STREQ(exp, got);
520 
521     lxw_styles_free(styles);
522     lxw_format_free(format);
523 }
524 
525 
526 // Test the _write_xf() method. Horizontal alignment = distributed + indent.
527 // The justify_distributed should drop back to plain distributed if there
528 // is an indent.
CTEST(styles,write_xf23)529 CTEST(styles, write_xf23) {
530 
531     char* got;
532     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" indent=\"1\"/></xf>";
533     FILE* testfile = lxw_tmpfile(NULL);
534 
535     lxw_styles *styles = lxw_styles_new();
536     lxw_format *format = lxw_format_new();
537 
538     format_set_align(format, LXW_ALIGN_DISTRIBUTED);
539     format_set_indent(format, 1);
540 
541     styles->file = testfile;
542 
543     _write_xf(styles, format);
544 
545     RUN_XLSX_STREQ(exp, got);
546 
547     lxw_styles_free(styles);
548     lxw_format_free(format);
549 }
550 
551 
552 // Test the _write_xf() method. Alignment = text wrap
CTEST(styles,write_xf24)553 CTEST(styles, write_xf24) {
554 
555     char* got;
556     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment wrapText=\"1\"/></xf>";
557     FILE* testfile = lxw_tmpfile(NULL);
558 
559     lxw_styles *styles = lxw_styles_new();
560     lxw_format *format = lxw_format_new();
561 
562     format_set_text_wrap(format);
563 
564     styles->file = testfile;
565 
566     _write_xf(styles, format);
567 
568     RUN_XLSX_STREQ(exp, got);
569 
570     lxw_styles_free(styles);
571     lxw_format_free(format);
572 }
573 
574 
575 // Test the _write_xf() method. Alignment = shrink to fit
CTEST(styles,write_xf25)576 CTEST(styles, write_xf25) {
577 
578     char* got;
579     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment shrinkToFit=\"1\"/></xf>";
580     FILE* testfile = lxw_tmpfile(NULL);
581 
582     lxw_styles *styles = lxw_styles_new();
583     lxw_format *format = lxw_format_new();
584 
585     format_set_shrink(format);
586 
587     styles->file = testfile;
588 
589     _write_xf(styles, format);
590 
591     RUN_XLSX_STREQ(exp, got);
592 
593     lxw_styles_free(styles);
594     lxw_format_free(format);
595 }
596 
597 
598 // Test the _write_xf() method. Alignment = reading order
CTEST(styles,write_xf26)599 CTEST(styles, write_xf26) {
600 
601     char* got;
602     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment readingOrder=\"1\"/></xf>";
603     FILE* testfile = lxw_tmpfile(NULL);
604 
605     lxw_styles *styles = lxw_styles_new();
606     lxw_format *format = lxw_format_new();
607 
608     format_set_reading_order(format, 1);
609 
610     styles->file = testfile;
611 
612     _write_xf(styles, format);
613 
614     RUN_XLSX_STREQ(exp, got);
615 
616     lxw_styles_free(styles);
617     lxw_format_free(format);
618 }
619 
620 
621 // Test the _write_xf() method. Alignment = reading order
CTEST(styles,write_xf27)622 CTEST(styles, write_xf27) {
623 
624     char* got;
625     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment readingOrder=\"2\"/></xf>";
626     FILE* testfile = lxw_tmpfile(NULL);
627 
628     lxw_styles *styles = lxw_styles_new();
629     lxw_format *format = lxw_format_new();
630 
631     format_set_reading_order(format, 2);
632 
633     styles->file = testfile;
634 
635     _write_xf(styles, format);
636 
637     RUN_XLSX_STREQ(exp, got);
638 
639     lxw_styles_free(styles);
640     lxw_format_free(format);
641 }
642 
643 
644 // Test the _write_xf() method. Alignment = rotation
CTEST(styles,write_xf28)645 CTEST(styles, write_xf28) {
646 
647     char* got;
648     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"45\"/></xf>";
649     FILE* testfile = lxw_tmpfile(NULL);
650 
651     lxw_styles *styles = lxw_styles_new();
652     lxw_format *format = lxw_format_new();
653 
654     format_set_rotation(format, 45);
655 
656     styles->file = testfile;
657 
658     _write_xf(styles, format);
659 
660     RUN_XLSX_STREQ(exp, got);
661 
662     lxw_styles_free(styles);
663     lxw_format_free(format);
664 }
665 
666 
667 // Test the _write_xf() method. Alignment = rotation
CTEST(styles,write_xf29)668 CTEST(styles, write_xf29) {
669 
670     char* got;
671     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"135\"/></xf>";
672     FILE* testfile = lxw_tmpfile(NULL);
673 
674     lxw_styles *styles = lxw_styles_new();
675     lxw_format *format = lxw_format_new();
676 
677     format_set_rotation(format, -45);
678 
679     styles->file = testfile;
680 
681     _write_xf(styles, format);
682 
683     RUN_XLSX_STREQ(exp, got);
684 
685     lxw_styles_free(styles);
686     lxw_format_free(format);
687 }
688 
689 
690 // Test the _write_xf() method. Alignment = rotation
CTEST(styles,write_xf30)691 CTEST(styles, write_xf30) {
692 
693     char* got;
694     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"255\"/></xf>";
695     FILE* testfile = lxw_tmpfile(NULL);
696 
697     lxw_styles *styles = lxw_styles_new();
698     lxw_format *format = lxw_format_new();
699 
700     format_set_rotation(format, 270);
701 
702     styles->file = testfile;
703 
704     _write_xf(styles, format);
705 
706     RUN_XLSX_STREQ(exp, got);
707 
708     lxw_styles_free(styles);
709     lxw_format_free(format);
710 }
711 
712 
713 // Test the _write_xf() method. Alignment = rotation
CTEST(styles,write_xf31)714 CTEST(styles, write_xf31) {
715 
716     char* got;
717     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"90\"/></xf>";
718     FILE* testfile = lxw_tmpfile(NULL);
719 
720     lxw_styles *styles = lxw_styles_new();
721     lxw_format *format = lxw_format_new();
722 
723     format_set_rotation(format, 90);
724 
725     styles->file = testfile;
726 
727     _write_xf(styles, format);
728 
729     RUN_XLSX_STREQ(exp, got);
730 
731     lxw_styles_free(styles);
732     lxw_format_free(format);
733 }
734 
735 
736 // Test the _write_xf() method. Alignment = rotation
CTEST(styles,write_xf32)737 CTEST(styles, write_xf32) {
738 
739     char* got;
740     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"180\"/></xf>";
741     FILE* testfile = lxw_tmpfile(NULL);
742 
743     lxw_styles *styles = lxw_styles_new();
744     lxw_format *format = lxw_format_new();
745 
746     format_set_rotation(format, -90);
747 
748     styles->file = testfile;
749 
750     _write_xf(styles, format);
751 
752     RUN_XLSX_STREQ(exp, got);
753 
754     lxw_styles_free(styles);
755     lxw_format_free(format);
756 }
757 
758 
759 // Test the _write_xf() method. With cell protection.
CTEST(styles,write_xf33)760 CTEST(styles, write_xf33) {
761 
762     char* got;
763     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection locked=\"0\"/></xf>";
764     FILE* testfile = lxw_tmpfile(NULL);
765 
766     lxw_styles *styles = lxw_styles_new();
767     lxw_format *format = lxw_format_new();
768 
769     format_set_unlocked(format);
770 
771     styles->file = testfile;
772 
773     _write_xf(styles, format);
774 
775     RUN_XLSX_STREQ(exp, got);
776 
777     lxw_styles_free(styles);
778     lxw_format_free(format);
779 }
780 
781 
782 // Test the _write_xf() method. With cell protection.
CTEST(styles,write_xf34)783 CTEST(styles, write_xf34) {
784 
785     char* got;
786     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection hidden=\"1\"/></xf>";
787     FILE* testfile = lxw_tmpfile(NULL);
788 
789     lxw_styles *styles = lxw_styles_new();
790     lxw_format *format = lxw_format_new();
791 
792     format_set_hidden(format);
793 
794     styles->file = testfile;
795 
796     _write_xf(styles, format);
797 
798     RUN_XLSX_STREQ(exp, got);
799 
800     lxw_styles_free(styles);
801     lxw_format_free(format);
802 }
803 
804 
805 // Test the _write_xf() method. With cell protection.
CTEST(styles,write_xf35)806 CTEST(styles, write_xf35) {
807 
808     char* got;
809     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection locked=\"0\" hidden=\"1\"/></xf>";
810     FILE* testfile = lxw_tmpfile(NULL);
811 
812     lxw_styles *styles = lxw_styles_new();
813     lxw_format *format = lxw_format_new();
814 
815     format_set_unlocked(format);
816     format_set_hidden(format);
817 
818     styles->file = testfile;
819 
820     _write_xf(styles, format);
821 
822     RUN_XLSX_STREQ(exp, got);
823 
824     lxw_styles_free(styles);
825     lxw_format_free(format);
826 }
827 
828 
829 // Test the _write_xf() method. With cell protection + align.
CTEST(styles,write_xf36)830 CTEST(styles, write_xf36) {
831 
832     char* got;
833     char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\" applyProtection=\"1\"><alignment horizontal=\"right\"/><protection locked=\"0\" hidden=\"1\"/></xf>";
834     FILE* testfile = lxw_tmpfile(NULL);
835 
836     lxw_styles *styles = lxw_styles_new();
837     lxw_format *format = lxw_format_new();
838 
839     format_set_align(format, LXW_ALIGN_RIGHT);
840     format_set_unlocked(format);
841     format_set_hidden(format);
842 
843     styles->file = testfile;
844 
845     _write_xf(styles, format);
846 
847     RUN_XLSX_STREQ(exp, got);
848 
849     lxw_styles_free(styles);
850     lxw_format_free(format);
851 }
852