summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKota Tsuyuzaki <tsuyuzaki.kota@lab.ntt.co.jp>2016-10-18 02:10:01 -0700
committerPete Zaitcev <zaitcev@kotori.zaitcev.us>2016-11-04 18:42:11 +0000
commite8b5a64d8d68c6f379fcd8aa69d934682b9e1a25 (patch)
tree4a7d290a0bc89e14b9a0958536ac102c0e4538c3 /test
parentcb0daba975dfb3b7bffe402d7aa73fac19180f73 (diff)
downloadliberasurecode-e8b5a64d8d68c6f379fcd8aa69d934682b9e1a25.tar.gz
Fix liberasurecode skipping a bunch of invalid_args tests
Since the commit a01b1818c874a65d1d1fb8f11ea441e9d3e18771, we have been to able to test some parameters for each tests. However, instead, the NULL which means the end of the test parameters causes skipping a bunch of unit tests which doesn't take args (e.g. test_create_backend_invalid_args). That is the worse because we have not tested anymore for the tests since the commit. This patch fixes to make it tested and more, fix a minor bug for a case that corrupted header incomming to get_metadata. Closes-Bug: #1634403 Change-Id: Ib99a8aa6032f02d0c7d1ab94b8da1ebfd9047d74
Diffstat (limited to 'test')
-rw-r--r--test/liberasurecode_test.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/test/liberasurecode_test.c b/test/liberasurecode_test.c
index f71ba89..c94c466 100644
--- a/test/liberasurecode_test.c
+++ b/test/liberasurecode_test.c
@@ -475,10 +475,11 @@ static void test_backend_available(ec_backend_id_t be_id) {
assert(1 == liberasurecode_backend_available(be_id));
}
-static void test_backend_available_invalid_args(ec_backend_id_t be_id)
+static void test_backend_available_invalid_args()
{
int ret = liberasurecode_backend_available(EC_BACKENDS_MAX);
- assert(ret < 0);
+ // returns 1 if a backend is available; 0 otherwise
+ assert(0 == ret);
}
static void test_create_backend_invalid_args()
@@ -640,12 +641,13 @@ static void test_decode_invalid_args()
rc = liberasurecode_decode(desc, avail_frags, num_avail_frags,
strlen(fake_data), 1,
&decoded_data, &decoded_data_len);
- // force_metadata_checks results in EINSUFFFRAGS
- assert(rc == -EINSUFFFRAGS);
+ // no metadata headers w/ force_metadata_checks results in EBADHEADER
+ assert(rc == -EBADHEADER);
rc = liberasurecode_decode(desc, avail_frags, num_avail_frags,
strlen(fake_data), 0,
&decoded_data, &decoded_data_len);
+ // no metadata headers w/o force_metadata_checks also results in EBADHEADER
assert(rc == -EBADHEADER);
// test with num_fragments < (k)
@@ -810,7 +812,7 @@ static void test_get_fragment_metadata_invalid_args() {
memset(frag, 0, 1024); //clears magic
rc = liberasurecode_get_fragment_metadata(frag, &metadata);
- assert(rc < 0);
+ assert(rc == -EBADHEADER);
free(frag);
}
@@ -2008,25 +2010,36 @@ int main(int argc, char **argv)
int max_backend_tests = max_tests_for_backends();
for (i = 0; i < max_backend_tests; i++) {
- for (ii = 0; testcases[ii].description != NULL; ++ii) {
- const char *testname = get_name_from_backend_id(testcases[ii].be_id);
- fflush(stdout);
- if (testcases[ii].skip) {
- fprintf(stdout, "ok # SKIP %d - %s: %s (idx=%d)\n", num_cases,
- testcases[ii].description,
- (testname) ? testname : "", i);
- continue;
- }
- struct ec_args *args = create_ec_args(testcases[ii].be_id, testcases[ii].ct, i);
+ for (ii = 0; testcases[ii].description != NULL; ++ii) {
+ const char *testname = get_name_from_backend_id(testcases[ii].be_id);
+ fflush(stdout);
+ if (testcases[ii].skip) {
+ fprintf(stdout, "ok # SKIP %d - %s: %s (idx=%d)\n", num_cases,
+ testcases[ii].description,
+ (testname) ? testname : "", i);
+ continue;
+ }
+ if (testcases[ii].be_id == EC_BACKENDS_MAX) {
+ /* EC_BACKEND_MAX basically designed for invalid args tests
+ * and not takes the args so call the function w/o args here */
+ testcases[ii].function();
+ fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases,
+ testcases[ii].description,
+ (testname) ? testname : "", i);
+ fflush(stdout);
+ num_cases++;
+ continue;
+ }
+ struct ec_args *args = create_ec_args(testcases[ii].be_id, testcases[ii].ct, i);
if (NULL != args) {
- testcases[ii].function(testcases[ii].be_id, args);
- fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases,
- testcases[ii].description,
- (testname) ? testname : "", i);
- fflush(stdout);
- free(args);
- num_cases++;
- }
+ testcases[ii].function(testcases[ii].be_id, args);
+ fprintf(stdout, "ok %d - %s: %s (idx=%d)\n", num_cases,
+ testcases[ii].description,
+ (testname) ? testname : "", i);
+ fflush(stdout);
+ free(args);
+ num_cases++;
+ }
}
}
return 0;