25#if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) < 500
26#define _XOPEN_SOURCE 500
38#include "hdrl_utils.h"
39#include "hdrl_download.h"
41#define INVALID_HOSTNAME "notthere.invalid"
43#define ESO_FTP_IP_ADDR "https://ftp.eso.org"
59static cpl_error_code hdrl_download_test(
void)
64 char * raw_text = NULL;
67 int test_failed_before = cpl_test_get_failed();
70 ESO_FTP_IP_ADDR
"/pub/dfs/pipelines/gravity/finals2000A.data", &data_length);
73 cpl_test_error(CPL_ERROR_NONE);
76 cpl_test(data_length > 0);
79 cpl_test_nonnull(raw_text);
87 cpl_test_error(CPL_ERROR_NONE);
90 FILE *file = fopen(
"finals2000A.data",
"r");
93 cpl_test_nonnull(file);
97 if(cpl_test_get_failed() == test_failed_before)
102 fseek(file, 0, SEEK_END);
103 long length = ftell(file);
104 fseek(file, 0, SEEK_SET);
107 cpl_test_eq(length, data_length);
110 char *buffer = malloc(
sizeof(
char) * (length + 1));
111 buffer[length] =
'\0';
113 size_t read = fread(buffer,
sizeof(
char), length, file);
117 cpl_test_eq(read, data_length);
119 int comp = memcmp(buffer, raw_text, data_length);
121 cpl_test_eq(comp, 0);
127 int num = strtol(raw_text, &endptr, 10);
131 cpl_table * eop_table =
135 cpl_test(cpl_table_get_nrow(eop_table) > 0);
138 cpl_test(cpl_table_get_column_max(eop_table,
"PMX") < 10);
139 cpl_test(cpl_table_get_column_min(eop_table,
"PMX") > -10);
140 cpl_test(cpl_table_get_column_max(eop_table,
"PMY") < 10);
141 cpl_test(cpl_table_get_column_min(eop_table,
"PMY") > -10);
142 cpl_test(cpl_table_get_column_max(eop_table,
"DUT") < 10);
143 cpl_test(cpl_table_get_column_min(eop_table,
"DUT") > -10);
146 for(cpl_size i_row = 1; i_row < cpl_table_get_nrow(eop_table); i_row++)
149 cpl_test(cpl_table_get_double(eop_table,
"MJD", i_row, &null) >
150 cpl_table_get_double(eop_table,
"MJD", i_row - 1, &null));
152 cpl_table_delete(eop_table);
156 cpl_test_error(CPL_ERROR_NULL_INPUT);
157 cpl_test_null(eop_table);
161 cpl_test_error(CPL_ERROR_NULL_INPUT);
162 cpl_test_null(eop_table);
166 cpl_test_error(CPL_ERROR_NULL_INPUT);
167 cpl_test_null(eop_table);
177 INVALID_HOSTNAME
"/products/eop/rapid/standard/finals2000A.data", &data_length);
178 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
183 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
187 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
191 ESO_FTP_IP_ADDR
"/products/eop/rapid/standard/finals2000A.data", NULL);
192 cpl_test_error(CPL_ERROR_NULL_INPUT);
194 cpl_test_error(CPL_ERROR_NULL_INPUT);
199 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
203 ESO_FTP_IP_ADDR
"/products/eop/rapid/standard/finals2000A.data", NULL);
204 cpl_test_error(CPL_ERROR_NULL_INPUT);
206 cpl_test_error(CPL_ERROR_NULL_INPUT);
210 "/dev/null/finals2000A.data");
211 cpl_test_error(CPL_ERROR_FILE_NOT_CREATED);
215 cpl_msg_set_level(CPL_MSG_DEBUG);
217 ESO_FTP_IP_ADDR
"/pub/dfs/pipelines/gravity/finals2000A.data",
224 cpl_test_error(CPL_ERROR_NONE);
228 return cpl_error_get_code();
243 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
245 hdrl_download_test();
247 return cpl_test_end(0);
cpl_error_code hdrl_download_url_to_file(const char *url, const char *filename)
Downloads a url into a file on disc.
char * hdrl_download_url_to_buffer(const char *url, size_t *data_length)
Downloads a url into a c data buffer.
cpl_table * hdrl_eop_data_totable(const char *eop_data, cpl_size data_length)
Export a raw string buffer containing EOP data to a CPL table.