summaryrefslogtreecommitdiffstats
path: root/test/s3comms.c
diff options
context:
space:
mode:
authorJacob Smith <jake.smith@hdfgroup.org>2019-08-14 20:36:45 (GMT)
committerJacob Smith <jake.smith@hdfgroup.org>2019-08-14 20:36:45 (GMT)
commit2e5cd3d2b2d953420252c80ab5e32ac95ac0c5b3 (patch)
treea79af758bc878d55a958bedae77d919e03a9516f /test/s3comms.c
parent2b72832d97496290f74ccaffcda41c3e596f8f49 (diff)
downloadhdf5-2e5cd3d2b2d953420252c80ab5e32ac95ac0c5b3.zip
hdf5-2e5cd3d2b2d953420252c80ab5e32ac95ac0c5b3.tar.gz
hdf5-2e5cd3d2b2d953420252c80ab5e32ac95ac0c5b3.tar.bz2
Fix compiler warnings with diabled ROS3 and HDFS VFDs.
Fix misuse of [HD]strncpy and [HD]snprintf. Minor formatting changes. Fix test cleanup issue with java groups example.
Diffstat (limited to 'test/s3comms.c')
-rw-r--r--test/s3comms.c215
1 files changed, 90 insertions, 125 deletions
diff --git a/test/s3comms.c b/test/s3comms.c
index a797e04..d636550 100644
--- a/test/s3comms.c
+++ b/test/s3comms.c
@@ -11,7 +11,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * Read-Only S3 Virtual File Driver (VFD)
+ * Read-Only S3 Virtual File Driver (VFD)
*
* Purpose: Unit tests for the S3 Communications (s3comms) module.
*
@@ -386,7 +386,7 @@ static hbool_t s3_test_bucket_defined = FALSE;
#endif /* H5_HAVE_ROS3_VFD */
-
+
/*---------------------------------------------------------------------------
*
* Function: test_macro_format_credential()
@@ -408,7 +408,6 @@ test_macro_format_credential(void)
* test-local variables *
************************/
-#ifdef H5_HAVE_ROS3_VFD
char dest[256];
const char access[] = "AKIAIOSFODNN7EXAMPLE";
const char date[] = "20130524";
@@ -416,16 +415,9 @@ test_macro_format_credential(void)
const char service[] = "s3";
const char expected[] =
"AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request";
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("test_macro_format_credential");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
FAIL_IF( S3COMMS_MAX_CREDENTIAL_SIZE <
S3COMMS_FORMAT_CREDENTIAL(dest, access, date, region, service) )
@@ -433,14 +425,13 @@ test_macro_format_credential(void)
PASSED();
return 0;
-#endif /* H5_HAVE_ROS3_VFD */
error:
return -1;
-} /* test_macro_format_credential */
-
+} /* end test_macro_format_credential() */
+
/*---------------------------------------------------------------------------
*
* Function: test_aws_canonical_request()
@@ -465,7 +456,6 @@ test_aws_canonical_request(void)
* test-local structures *
*************************/
-#ifdef H5_HAVE_ROS3_VFD
struct header {
const char *name;
const char *value;
@@ -520,16 +510,9 @@ test_aws_canonical_request(void)
hrb_node_t *node = NULL; /* http headers list pointer */
unsigned int n_cases = 3;
char sh_dest[64]; /* signed headers */
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("test_aws_canonical_request");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
for (i = 0; i < n_cases; i++) {
/* pre-test bookkeeping
*/
@@ -559,16 +542,22 @@ test_aws_canonical_request(void)
/* test
*/
JSVERIFY( SUCCEED,
- H5FD_s3comms_aws_canonical_request(cr_dest, sh_dest, hrb),
+ H5FD_s3comms_aws_canonical_request(
+ cr_dest,
+ 512,
+ sh_dest,
+ 64,
+ hrb),
" unable to compose canonical request" )
JSVERIFY_STR( C->exp_headers, sh_dest, NULL )
JSVERIFY_STR( C->exp_request, cr_dest, NULL )
/* tear-down
*/
- while (node != NULL)
+ while (node != NULL) {
FAIL_IF( FAIL ==
H5FD_s3comms_hrb_node_set(&node, node->name, NULL));
+ }
HDassert(NULL == node);
FAIL_IF( FAIL == H5FD_s3comms_hrb_destroy(&hrb));
HDassert(NULL == hrb);
@@ -581,14 +570,29 @@ test_aws_canonical_request(void)
/* malformed hrb and/or node-list
*/
- JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(cr_dest, sh_dest, NULL),
+ JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(
+ cr_dest,
+ 20,
+ sh_dest,
+ 20,
+ NULL),
"http request object cannot be null" )
hrb = H5FD_s3comms_hrb_init_request("GET", "/", "HTTP/1.1");
- JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(NULL, sh_dest, hrb),
+ JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(
+ NULL,
+ 20,
+ sh_dest,
+ 20,
+ hrb),
"canonical request destination cannot be NULL" )
- JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(cr_dest, NULL, hrb),
+ JSVERIFY( FAIL, H5FD_s3comms_aws_canonical_request(
+ cr_dest,
+ 20,
+ NULL,
+ 20,
+ hrb),
"signed headers destination cannot be null" )
FAIL_IF( FAIL == H5FD_s3comms_hrb_destroy(&hrb) )
@@ -604,15 +608,15 @@ error:
(void)H5FD_s3comms_hrb_node_set(&node, node->name, NULL);
HDassert( node == NULL );
}
- if (hrb != NULL)
+ if (hrb != NULL) {
(void)H5FD_s3comms_hrb_destroy(&hrb);
+ }
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-
-} /* test_aws_canonical_request */
+} /* end test_aws_canonical_request() */
+
/*---------------------------------------------------------------------------
*
* Function: test_bytes_to_hex
@@ -706,9 +710,9 @@ test_bytes_to_hex(void)
error:
return -1;
-} /* test_bytes_to_hex */
-
+} /* end test_bytes_to_hex() */
+
/*---------------------------------------------------------------------------
*
* Function: test_hrb_init_request()
@@ -725,7 +729,6 @@ error:
static herr_t
test_hrb_init_request(void)
{
-#ifdef H5_HAVE_ROS3_VFD
/*********************
* test-local macros *
*********************/
@@ -769,7 +772,7 @@ test_hrb_init_request(void)
"HTTP/1.1",
FALSE,
},
- { "slash prepented to resource path, if necessary",
+ { "slash prepended to resource path, if necessary",
NULL,
"MYPATH/MYFILE.tiff",
"/MYPATH/MYFILE.tiff",
@@ -788,29 +791,25 @@ test_hrb_init_request(void)
unsigned int i = 0;
unsigned int ncases = 5;
hrb_t *req = NULL;
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("hrb_init_request");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
for (i = 0; i < ncases; i++) {
C = &cases[i];
- req = H5FD_s3comms_hrb_init_request(C->verb,
- C->resource,
- C->version);
+ req = H5FD_s3comms_hrb_init_request(
+ C->verb,
+ C->resource,
+ C->version);
if (cases[i].ret_null == TRUE) {
FAIL_IF( req != NULL );
- } else {
+ }
+ else {
FAIL_IF( req == NULL );
JSVERIFY( S3COMMS_HRB_MAGIC, req->magic, NULL )
if (C->verb == NULL) {
JSVERIFY_STR( "GET", req->verb, NULL )
- } else {
+ }
+ else {
JSVERIFY_STR( req->verb, C->verb, NULL )
}
JSVERIFY_STR( "HTTP/1.1", req->version, NULL )
@@ -823,7 +822,7 @@ test_hrb_init_request(void)
FAIL_IF( NULL != req ); /* should annull pointer as well as free */
}
- } /* for each testcase */
+ } /* end for each testcase */
PASSED();
return 0;
@@ -832,11 +831,10 @@ error:
(void)H5FD_s3comms_hrb_destroy(&req);
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-
-} /* test_hrb_init_request */
+} /* end test_hrb_init_request() */
+
/*---------------------------------------------------------------------------
*
* Function: test_hrb_node_set()
@@ -853,7 +851,6 @@ error:
static herr_t
test_hrb_node_set(void)
{
-#ifdef H5_HAVE_ROS3_VFD
/*************************
* test-local structures *
*************************/
@@ -1071,18 +1068,10 @@ test_hrb_node_set(void)
};
unsigned testcases_count = 16;
unsigned test_i = 0;
-
hrb_node_t *list = NULL;
-#endif /* H5_HAVE_ROS3_VFD */
- TESTING("test_hrb_node_t");
+ TESTING("hrb_node_t (test_hrb_node_set)");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
for (test_i = 0; test_i < testcases_count; test_i++) {
const hrb_node_t *node = NULL;
const testcase *test = &(cases[test_i]);
@@ -1137,21 +1126,22 @@ test_hrb_node_set(void)
FAIL_IF( SUCCEED !=
H5FD_s3comms_hrb_node_set(&list, list->name, NULL) )
}
- }
+ } /* end for each testcase */
PASSED();
return 0;
error:
- while (list != NULL)
+ while (list != NULL) {
(void)H5FD_s3comms_hrb_node_set(&list, list->name, NULL);
+ }
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-} /* test_hrb_node_t */
+} /* end test_hrb_node_t() */
+
/*---------------------------------------------------------------------------
*
* Function: test_HMAC_SHA256()
@@ -1265,13 +1255,13 @@ test_HMAC_SHA256(void)
dest);
TEST_ERROR;
}
-#else
+#else /* VERBOSE not defined */
/* simple pass/fail test
*/
JSVERIFY( 0,
strncmp(cases[i].exp, dest, HDstrlen(cases[i].exp)),
NULL);
-#endif
+#endif /* VERBOSE */
}
free(dest);
}
@@ -1284,9 +1274,9 @@ error:
return -1;
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_HMAC_SHA256 */
-
+} /* end test_HMAC_SHA256() */
+
/*----------------------------------------------------------------------------
*
* Function: test_nlowercase()
@@ -1307,7 +1297,6 @@ test_nlowercase(void)
* test-local structures *
*************************/
-#ifdef H5_HAVE_ROS3_VFD
struct testcase {
const char *in;
size_t len;
@@ -1338,16 +1327,9 @@ test_nlowercase(void)
char *dest = NULL;
int i = 0;
int n_cases = 3;
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("nlowercase");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
for (i = 0; i < n_cases; i++) {
dest = (char *)HDmalloc(sizeof(char) * 16);
@@ -1360,7 +1342,7 @@ test_nlowercase(void)
JSVERIFY( 0, strncmp(dest, cases[i].exp, cases[i].len), NULL )
}
free(dest);
- }
+ } /* end for each testcase */
JSVERIFY( FAIL,
H5FD_s3comms_nlowercase(NULL,
@@ -1374,11 +1356,10 @@ test_nlowercase(void)
error:
free(dest);
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-
-} /* test_nlowercase */
+} /* end test_nlowercase() */
+
/*---------------------------------------------------------------------------
*
* Function: test_parse_url()
@@ -1399,7 +1380,6 @@ test_parse_url(void)
* test-local structures *
*************************/
-#ifdef H5_HAVE_ROS3_VFD
typedef struct {
const char *scheme;
const char *host;
@@ -1540,16 +1520,9 @@ test_parse_url(void)
"non-decimal PORT (01a3)",
},
};
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("url-parsing functionality");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
/*********
* TESTS *
*********/
@@ -1564,7 +1537,8 @@ test_parse_url(void)
if (cases[i].exp_ret == FAIL) {
/* on FAIL, `purl` should be untouched--remains NULL */
FAIL_UNLESS( purl == NULL )
- } else {
+ }
+ else {
/* on SUCCEED, `purl` should be set */
FAIL_IF( purl == NULL )
@@ -1612,7 +1586,7 @@ test_parse_url(void)
} else {
FAIL_UNLESS( NULL == purl->query )
}
- } /* if parse-url return SUCCEED/FAIL */
+ } /* end if parse-url return SUCCEED/FAIL */
/* per-test cleanup
* well-behaved, even if `purl` is NULL
@@ -1620,7 +1594,7 @@ test_parse_url(void)
FAIL_IF( FAIL == H5FD_s3comms_free_purl(purl) )
purl = NULL;
- } /* for each testcase */
+ } /* end for each testcase */
PASSED();
return 0;
@@ -1632,11 +1606,10 @@ error:
(void)H5FD_s3comms_free_purl(purl);
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-
-} /* test_parse_url */
+} /* end test_parse_url() */
+
/*---------------------------------------------------------------------------
*
* Function: test_percent_encode_char()
@@ -1662,7 +1635,6 @@ test_percent_encode_char(void)
* test-local structures *
*************************/
-#ifdef H5_HAVE_ROS3_VFD
struct testcase {
const char c;
const char *exp;
@@ -1692,16 +1664,9 @@ test_percent_encode_char(void)
size_t dest_len = 0;
int i = 0;
int n_cases = 5;
-#endif /* H5_HAVE_ROS3_VFD */
TESTING("percent encode characters");
-#ifndef H5_HAVE_ROS3_VFD
- SKIPPED();
- puts(" ROS3 VFD is not enabled");
- fflush(stdout);
- return 0;
-#else
for (i = 0; i < n_cases; i++) {
JSVERIFY( SUCCEED,
H5FD_s3comms_percent_encode_char(
@@ -1726,11 +1691,9 @@ test_percent_encode_char(void)
error:
return -1;
-#endif /* H5_HAVE_ROS3_VFD */
-
-} /* test_percent_encode_char */
-
+} /* end test_percent_encode_char() */
+
/*---------------------------------------------------------------------------
* Function: test_s3r_open()
*
@@ -1798,9 +1761,9 @@ error:
return -1;
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_s3r_get_filesize */
-
+} /* end test_s3r_get_filesize() */
+
/*---------------------------------------------------------------------------
* Function: test_s3r_open()
*
@@ -2039,9 +2002,9 @@ error:
return -1;
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_s3r_open */
-
+} /* end test_s3r_open() */
+
/*---------------------------------------------------------------------------
*
* Function: test_s3r_read()
@@ -2265,7 +2228,7 @@ error:
#undef S3COMMS_TEST_BUFFER_SIZE
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_s3r_read */
+} /* end test_s3r_read() */
/*---------------------------------------------------------------------------
@@ -2404,9 +2367,9 @@ error:
return -1;
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_signing_key */
-
+} /* end test_signing_key() */
+
/*---------------------------------------------------------------------------
*
* Function: test_tostringtosign()
@@ -2476,9 +2439,9 @@ error :
return -1;
#endif /* H5_HAVE_ROS3_VFD */
-} /* test_tostringtosign */
-
+} /* end test_tostringtosign() */
+
/*----------------------------------------------------------------------------
*
* Function: test_trim()
@@ -2563,7 +2526,7 @@ test_trim(void)
}
free(str);
str = NULL;
- }
+ } /* end for each testcase */
JSVERIFY( SUCCEED, H5FD_s3comms_trim(dest, NULL, 3, &dest_len),
"should not fail when trimming a null string" );
@@ -2582,13 +2545,14 @@ test_trim(void)
return 0;
error:
- if (str != NULL)
+ if (str != NULL) {
free(str);
+ }
return -1;
-} /* test_trim */
-
+} /* end test_trim() */
+
/*----------------------------------------------------------------------------
*
* Function: test_uriencode()
@@ -2685,7 +2649,7 @@ test_uriencode(void)
free(dest);
dest = NULL;
- }
+ } /* end for each testcase */
/***************
* ERROR CASES *
@@ -2713,11 +2677,11 @@ error:
}
return -1;
-} /* test_uriencode */
-
+} /* end test_uriencode() */
+
/*-------------------------------------------------------------------------
* Function: main()
*
@@ -2774,7 +2738,8 @@ main(void)
if (bucket_url_env == NULL || bucket_url_env[0] == '\0') {
HDprintf("WARNING: S3 bucket url is not defined in enviornment " \
"variable 'HDF5_ROS3_TEST_BUCKET_URL'!\n");
- } else {
+ }
+ else {
HDstrncpy(s3_test_bucket_url, bucket_url_env, S3_TEST_MAX_URL_SIZE);
s3_test_bucket_defined = TRUE;
}
@@ -2799,12 +2764,12 @@ main(void)
nerrors += test_s3r_get_filesize() < 0 ? 1 : 0;
nerrors += test_s3r_read() < 0 ? 1 : 0;
- if(nerrors) {
+ if (nerrors) {
HDprintf("***** %d S3comms TEST%s FAILED! *****\n",
nerrors,
nerrors > 1 ? "S" : "");
return 1;
- } /* end if */
+ }
HDprintf("All S3comms tests passed.\n");