1 /*
2  * Tests for the libxlsxwriter 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/utility.h"
12 
13 // Test lxw_rowcol_to_range().
CTEST(utility,lxw_rowcol_to_range)14 CTEST(utility, lxw_rowcol_to_range) {
15 
16     char got[LXW_MAX_CELL_RANGE_LENGTH];
17 
18     TEST_ROWCOL_TO_RANGE(0, 0, 0, 1, "A1:B1");
19     TEST_ROWCOL_TO_RANGE(0, 2, 0, 9, "C1:J1");
20     TEST_ROWCOL_TO_RANGE(1, 0, 2, 0, "A2:A3");
21     TEST_ROWCOL_TO_RANGE(9, 0, 1, 24, "A10:Y2");
22     TEST_ROWCOL_TO_RANGE(7, 25, 9, 26, "Z8:AA10");
23     TEST_ROWCOL_TO_RANGE(1, 254, 1, 255, "IU2:IV2");
24     TEST_ROWCOL_TO_RANGE(1, 256, 0, 16383, "IW2:XFD1");
25     TEST_ROWCOL_TO_RANGE(0, 0, 1048576, 16384, "A1:XFE1048577");
26     TEST_ROWCOL_TO_RANGE(1048575, 16383, 1048576, 16384, "XFD1048576:XFE1048577");
27 
28     // Test ranges that resolve to single cells.
29     TEST_ROWCOL_TO_RANGE(0, 0, 0, 0, "A1");
30     TEST_ROWCOL_TO_RANGE(1048576, 16384, 1048576, 16384, "XFE1048577");
31 
32 }
33 
34 // Test lxw_rowcol_to_range_abs().
CTEST(utility,lxw_rowcol_to_range_abs)35 CTEST(utility, lxw_rowcol_to_range_abs) {
36 
37     char got[LXW_MAX_CELL_RANGE_LENGTH];
38 
39     TEST_ROWCOL_TO_RANGE_ABS(0, 0, 0, 1, "$A$1:$B$1");
40     TEST_ROWCOL_TO_RANGE_ABS(0, 2, 0, 9, "$C$1:$J$1");
41     TEST_ROWCOL_TO_RANGE_ABS(1, 0, 2, 0, "$A$2:$A$3");
42     TEST_ROWCOL_TO_RANGE_ABS(9, 0, 1, 24, "$A$10:$Y$2");
43     TEST_ROWCOL_TO_RANGE_ABS(7, 25, 9, 26, "$Z$8:$AA$10");
44     TEST_ROWCOL_TO_RANGE_ABS(1, 254, 1, 255, "$IU$2:$IV$2");
45     TEST_ROWCOL_TO_RANGE_ABS(1, 256, 0, 16383, "$IW$2:$XFD$1");
46     TEST_ROWCOL_TO_RANGE_ABS(0, 0, 1048576, 16384, "$A$1:$XFE$1048577");
47     TEST_ROWCOL_TO_RANGE_ABS(1048575, 16383, 1048576, 16384, "$XFD$1048576:$XFE$1048577");
48 
49     // Test ranges that resolve to single cells.
50     TEST_ROWCOL_TO_RANGE_ABS(0, 0, 0, 0, "$A$1");
51     TEST_ROWCOL_TO_RANGE_ABS(1048576, 16384, 1048576, 16384, "$XFE$1048577");
52 
53 }
54