1 #include <stdio.h> 2 #include <stdlib.h> 3 #include "../../include/xlsxwriter/utility.h" 4 5 /* Compare expected results with the XML data written to the output 6 * test file. 7 */ 8 #define RUN_XLSX_STREQ(exp, got) \ 9 fflush(testfile); \ 10 int file_size = ftell(testfile); \ 11 \ 12 got = (char*)calloc(file_size + 1, 1); \ 13 \ 14 rewind(testfile); \ 15 (void)fread(got, file_size, 1, testfile); \ 16 \ 17 ASSERT_STR((exp), (got)); \ 18 \ 19 if (got) \ 20 free(got); \ 21 \ 22 fclose(testfile) 23 24 /* Compare expected results with the XML data written to the output 25 * test file. Same as the previous macro but only shows the difference 26 * from where it starts. Suitable for long strings of XML data. 27 */ 28 #define RUN_XLSX_STREQ_SHORT(exp, got) \ 29 fflush(testfile); \ 30 int file_size = ftell(testfile); \ 31 \ 32 got = (char*)calloc(file_size + 1, 1); \ 33 \ 34 rewind(testfile); \ 35 (void)fread(got, file_size, 1, testfile); \ 36 \ 37 /* Start comparison from first difference. */ \ 38 char *got_short = got; \ 39 char *exp_short = exp; \ 40 while (*exp_short && *exp_short == *got_short) { \ 41 exp_short++; \ 42 got_short++; \ 43 } \ 44 \ 45 ASSERT_STR(exp_short, got_short); \ 46 \ 47 if (got) \ 48 free(got); \ 49 \ 50 fclose(testfile) 51 52 53 #define TEST_COL_TO_NAME(num, abs, exp) \ 54 lxw_col_to_name(got, num, abs); \ 55 ASSERT_STR(exp, got); 56 57 58 #define TEST_ROWCOL_TO_CELL(row, col, exp) \ 59 lxw_rowcol_to_cell(got, row, col); \ 60 ASSERT_STR(exp, got); 61 62 63 #define TEST_ROWCOL_TO_CELL_ABS(row, col, row_abs, col_abs, exp) \ 64 lxw_rowcol_to_cell_abs(got, row, col, row_abs, col_abs); \ 65 ASSERT_STR(exp, got); 66 67 68 #define TEST_ROWCOL_TO_RANGE(row1, col1, row2, col2, exp) \ 69 lxw_rowcol_to_range(got, row1, col1, row2, col2); \ 70 ASSERT_STR(exp, got); 71 72 73 #define TEST_ROWCOL_TO_RANGE_ABS(row1, col1, row2, col2, exp) \ 74 lxw_rowcol_to_range_abs(got, row1, col1, row2, col2); \ 75 ASSERT_STR(exp, got); 76 77 78 #define TEST_ROWCOL_TO_FORMULA_ABS(sheet, row1, col1, row2, col2, exp) \ 79 lxw_rowcol_to_formula_abs(got, sheet, row1, col1, row2, col2); \ 80 ASSERT_STR(exp, got); 81 82 83 #define TEST_DATETIME_TIME(_hour, _min, _sec, exp) \ 84 datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \ 85 datetime->hour = _hour; \ 86 datetime->min = _min; \ 87 datetime->sec = _sec; \ 88 \ 89 got = lxw_datetime_to_excel_datetime(datetime); \ 90 \ 91 ASSERT_DOUBLE(exp, got); \ 92 free(datetime); 93 94 #define TEST_DATETIME_DATE(_year, _month, _day, exp) \ 95 datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \ 96 datetime->year = _year; \ 97 datetime->month = _month; \ 98 datetime->day = _day; \ 99 \ 100 got = lxw_datetime_to_excel_datetime(datetime); \ 101 \ 102 ASSERT_DOUBLE(exp, got); \ 103 free(datetime); 104 105 #define TEST_DATETIME_DATE_1904(_year, _month, _day, exp) \ 106 datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \ 107 datetime->year = _year; \ 108 datetime->month = _month; \ 109 datetime->day = _day; \ 110 \ 111 got = lxw_datetime_to_excel_date_epoch(datetime, 1); \ 112 \ 113 ASSERT_DOUBLE(exp, got); \ 114 free(datetime); 115 116 #define TEST_DATETIME(_year, _month, _day, _hour, _min, _sec, exp) \ 117 datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \ 118 datetime->year = _year; \ 119 datetime->month = _month; \ 120 datetime->day = _day; \ 121 datetime->hour = _hour; \ 122 datetime->min = _min; \ 123 datetime->sec = _sec; \ 124 \ 125 got = lxw_datetime_to_excel_datetime(datetime); \ 126 \ 127 ASSERT_DOUBLE(exp, got); \ 128 free(datetime); 129 130 #define TEST_UNIXTIME(_unixtime, exp) \ 131 got = lxw_unixtime_to_excel_date(_unixtime); \ 132 ASSERT_DOUBLE(exp, got); 133 134 #define TEST_UNIXTIME_1904(_unixtime, exp) \ 135 got = lxw_unixtime_to_excel_date_epoch(_unixtime, 1); \ 136 ASSERT_DOUBLE(exp, got); 137 138