32#if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) < 500
33#define _XOPEN_SOURCE 500
45#include "hdrl_utils.h"
46#include "hdrl_download.h"
48#define INVALID_HOSTNAME "notthere.invalid"
50#define ESO_FTP_IP_ADDR "https://ftp.eso.org"
66static cpl_error_code hdrl_download_test(
void)
71 char * raw_text = NULL;
74 int test_failed_before = cpl_test_get_failed();
77 ESO_FTP_IP_ADDR
"/pub/dfs/pipelines/gravity/finals2000A.data", &data_length);
80 cpl_test_error(CPL_ERROR_NONE);
83 cpl_test(data_length > 0);
86 cpl_test_nonnull(raw_text);
94 cpl_test_error(CPL_ERROR_NONE);
97 FILE *file = fopen(
"finals2000A.data",
"r");
100 cpl_test_nonnull(file);
104 if(cpl_test_get_failed() == test_failed_before)
109 fseek(file, 0, SEEK_END);
110 long length = ftell(file);
111 fseek(file, 0, SEEK_SET);
114 cpl_test_eq(length, data_length);
117 char *buffer = malloc(
sizeof(
char) * (length + 1));
118 buffer[length] =
'\0';
120 size_t read = fread(buffer,
sizeof(
char), length, file);
124 cpl_test_eq(read, data_length);
126 int comp = memcmp(buffer, raw_text, data_length);
128 cpl_test_eq(comp, 0);
134 int num = strtol(raw_text, &endptr, 10);
138 cpl_table * eop_table =
142 cpl_test(cpl_table_get_nrow(eop_table) > 0);
145 cpl_test(cpl_table_get_column_max(eop_table,
"PMX") < 10);
146 cpl_test(cpl_table_get_column_min(eop_table,
"PMX") > -10);
147 cpl_test(cpl_table_get_column_max(eop_table,
"PMY") < 10);
148 cpl_test(cpl_table_get_column_min(eop_table,
"PMY") > -10);
149 cpl_test(cpl_table_get_column_max(eop_table,
"DUT") < 10);
150 cpl_test(cpl_table_get_column_min(eop_table,
"DUT") > -10);
153 for(cpl_size i_row = 1; i_row < cpl_table_get_nrow(eop_table); i_row++)
156 cpl_test(cpl_table_get_double(eop_table,
"MJD", i_row, &null) >
157 cpl_table_get_double(eop_table,
"MJD", i_row - 1, &null));
159 cpl_table_delete(eop_table);
163 cpl_test_error(CPL_ERROR_NULL_INPUT);
164 cpl_test_null(eop_table);
168 cpl_test_error(CPL_ERROR_NULL_INPUT);
169 cpl_test_null(eop_table);
173 cpl_test_error(CPL_ERROR_NULL_INPUT);
174 cpl_test_null(eop_table);
184 INVALID_HOSTNAME
"/products/eop/rapid/standard/finals2000A.data", &data_length);
185 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
190 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
194 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
198 ESO_FTP_IP_ADDR
"/products/eop/rapid/standard/finals2000A.data", NULL);
199 cpl_test_error(CPL_ERROR_NULL_INPUT);
201 cpl_test_error(CPL_ERROR_NULL_INPUT);
206 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
210 ESO_FTP_IP_ADDR
"/products/eop/rapid/standard/finals2000A.data", NULL);
211 cpl_test_error(CPL_ERROR_NULL_INPUT);
213 cpl_test_error(CPL_ERROR_NULL_INPUT);
217 "/dev/null/finals2000A.data");
218 cpl_test_error(CPL_ERROR_FILE_NOT_CREATED);
222 cpl_msg_set_level(CPL_MSG_DEBUG);
224 ESO_FTP_IP_ADDR
"/pub/dfs/pipelines/gravity/finals2000A.data",
231 cpl_test_error(CPL_ERROR_NONE);
235 return cpl_error_get_code();
250 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
252 hdrl_download_test();
254 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.