Skip to content

Commit 4a3bd46

Browse files
committed
[acquire/tests/test_*.h] Increase test coverage ; [acquire_*.h] Modify code fixing issues test failures found ; check for #if defined(USE_) && USE_ rather than just #ifdef [reports/test_coverage.svg] Regenerate on latest ctest run
1 parent 5c9d884 commit 4a3bd46

22 files changed

+404
-118
lines changed

USAGE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ void non_blocking_extraction(const char *archive_path, const char *destination_d
240240
status = acquire_extract_async_poll(handle);
241241
if (status == ACQUIRE_IN_PROGRESS) {
242242
printf("Extracting: %s\n", handle->current_file);
243+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
244+
Sleep(100); /* 100ms */
245+
#else
246+
usleep(100000); /* 100ms */
247+
#endif
243248
}
244249
} while (status == ACQUIRE_IN_PROGRESS);
245250

acquire/acquire_checksums.h

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#ifdef __cplusplus
55
extern "C" {
6-
#endif
6+
#endif /* __cplusplus */
77

88
#include "acquire_handle.h"
99
#include "libacquire_export.h"
@@ -26,11 +26,16 @@ extern LIBACQUIRE_EXPORT int acquire_verify_sync(struct acquire_handle *handle,
2626
enum Checksum algorithm,
2727
const char *expected_hash);
2828

29-
#if defined(LIBACQUIRE_IMPLEMENTATION)
30-
#ifndef ACQUIRE_CHECKSUMS_IMPL_
31-
#define ACQUIRE_CHECKSUMS_IMPL_
29+
#ifdef LIBACQUIRE_IMPLEMENTATION
30+
3231
#include <string.h>
3332

33+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
34+
#include <synchapi.h> /* For Sleep() */
35+
#else
36+
#include <unistd.h> /* For usleep() */
37+
#endif
38+
3439
enum Checksum string2checksum(const char *const s) {
3540
if (s == NULL)
3641
return LIBACQUIRE_UNSUPPORTED_CHECKSUM;
@@ -56,17 +61,18 @@ int acquire_verify_async_start(struct acquire_handle *handle,
5661
handle->status = ACQUIRE_IDLE;
5762
handle->error.code = ACQUIRE_OK;
5863
handle->error.message[0] = '\0';
59-
#if defined(LIBACQUIRE_USE_LIBRHASH)
64+
#if defined(LIBACQUIRE_USE_LIBRHASH) && LIBACQUIRE_USE_LIBRHASH
6065
if (_librhash_verify_async_start(handle, filepath, algorithm,
6166
expected_hash) == 0) {
6267
handle->active_backend = ACQUIRE_BACKEND_CHECKSUM_LIBRHASH;
6368
return 0;
6469
}
6570
if (handle->error.code != ACQUIRE_OK)
6671
return -1;
67-
#endif
68-
#if defined(LIBACQUIRE_USE_COMMON_CRYPTO) || \
69-
defined(LIBACQUIRE_USE_OPENSSL) || defined(LIBACQUIRE_USE_LIBRESSL)
72+
#endif /* defined(LIBACQUIRE_USE_LIBRHASH) && LIBACQUIRE_USE_LIBRHASH */
73+
#if defined(LIBACQUIRE_USE_COMMON_CRYPTO) && LIBACQUIRE_USE_COMMON_CRYPTO || \
74+
defined(LIBACQUIRE_USE_OPENSSL) && LIBACQUIRE_USE_OPENSSL || \
75+
defined(LIBACQUIRE_USE_LIBRESSL) && LIBACQUIRE_USE_LIBRESSL
7076
if (_openssl_verify_async_start(handle, filepath, algorithm, expected_hash) ==
7177
0) {
7278
handle->active_backend = ACQUIRE_BACKEND_CHECKSUM_OPENSSL;
@@ -75,24 +81,24 @@ int acquire_verify_async_start(struct acquire_handle *handle,
7581
if (handle->error.code != ACQUIRE_OK)
7682
return -1;
7783
#endif
78-
#if defined(LIBACQUIRE_USE_WINCRYPT)
84+
#if defined(LIBACQUIRE_USE_WINCRYPT) && LIBACQUIRE_USE_WINCRYPT
7985
if (_wincrypt_verify_async_start(handle, filepath, algorithm,
8086
expected_hash) == 0) {
8187
handle->active_backend = ACQUIRE_BACKEND_CHECKSUM_WINCRYPT;
8288
return 0;
8389
}
8490
if (handle->error.code != ACQUIRE_OK)
8591
return -1;
86-
#endif
87-
#if defined(LIBACQUIRE_USE_CRC32C)
92+
#endif /* defined(LIBACQUIRE_USE_WINCRYPT) && LIBACQUIRE_USE_WINCRYPT */
93+
#if defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C
8894
if (_crc32c_verify_async_start(handle, filepath, algorithm, expected_hash) ==
8995
0) {
9096
handle->active_backend = ACQUIRE_BACKEND_CHECKSUM_CRC32C;
9197
return 0;
9298
}
9399
if (handle->error.code != ACQUIRE_OK)
94100
return -1;
95-
#endif
101+
#endif /* defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C */
96102
acquire_handle_set_error(handle, ACQUIRE_ERROR_UNSUPPORTED_CHECKSUM_FORMAT,
97103
"Unsupported checksum or no backend");
98104
return -1;
@@ -102,23 +108,24 @@ enum acquire_status acquire_verify_async_poll(struct acquire_handle *handle) {
102108
if (!handle)
103109
return ACQUIRE_ERROR;
104110
switch (handle->active_backend) {
105-
#if defined(LIBACQUIRE_USE_LIBRHASH)
111+
#if defined(LIBACQUIRE_USE_LIBRHASH) && LIBACQUIRE_USE_LIBRHASH
106112
case ACQUIRE_BACKEND_CHECKSUM_LIBRHASH:
107113
return _librhash_verify_async_poll(handle);
108114
#endif
109-
#if defined(LIBACQUIRE_USE_COMMON_CRYPTO) || \
110-
defined(LIBACQUIRE_USE_OPENSSL) || defined(LIBACQUIRE_USE_LIBRESSL)
115+
#if defined(LIBACQUIRE_USE_COMMON_CRYPTO) && LIBACQUIRE_USE_COMMON_CRYPTO || \
116+
defined(LIBACQUIRE_USE_OPENSSL) && LIBACQUIRE_USE_OPENSSL || \
117+
defined(LIBACQUIRE_USE_LIBRESSL) && LIBACQUIRE_USE_LIBRESSL
111118
case ACQUIRE_BACKEND_CHECKSUM_OPENSSL:
112119
return _openssl_verify_async_poll(handle);
113120
#endif
114-
#if defined(LIBACQUIRE_USE_WINCRYPT)
121+
#if defined(LIBACQUIRE_USE_WINCRYPT) && LIBACQUIRE_USE_WINCRYPT
115122
case ACQUIRE_BACKEND_CHECKSUM_WINCRYPT:
116123
return _wincrypt_verify_async_poll(handle);
117-
#endif
118-
#if defined(LIBACQUIRE_USE_CRC32C)
124+
#endif /* defined(LIBACQUIRE_USE_WINCRYPT) && LIBACQUIRE_USE_WINCRYPT */
125+
#if defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C
119126
case ACQUIRE_BACKEND_CHECKSUM_CRC32C:
120127
return _crc32c_verify_async_poll(handle);
121-
#endif
128+
#endif /* defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C */
122129
default:
123130
if (handle->status != ACQUIRE_IN_PROGRESS)
124131
return handle->status;
@@ -141,15 +148,19 @@ int acquire_verify_sync(struct acquire_handle *handle, const char *filepath,
141148
return -1;
142149
do {
143150
status = acquire_verify_async_poll(handle);
151+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
152+
Sleep(100); /* 100ms */
153+
#else
154+
usleep(100000); /* 100ms */
155+
#endif
144156
} while (status == ACQUIRE_IN_PROGRESS);
145157
return (status == ACQUIRE_COMPLETE) ? 0 : -1;
146158
}
147159

148-
#endif /* ACQUIRE_CHECKSUMS_IMPL_ */
149-
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) */
160+
#endif /* LIBACQUIRE_IMPLEMENTATION */
150161

151162
#ifdef __cplusplus
152163
}
153-
#endif
164+
#endif /* __cplusplus */
154165

155166
#endif /* !LIBACQUIRE_ACQUIRE_CHECKSUMS_H */

acquire/acquire_common_defs.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#ifdef __cplusplus
55
extern "C" {
6-
#endif
6+
#endif /* __cplusplus */
77

88
#include "acquire_status_codes.h"
99

@@ -20,12 +20,8 @@ enum Checksum {
2020
#define PATH_SEP "/"
2121
#endif
2222

23-
#if (defined(WIN32) || defined(_WIN32)) && !defined(__WIN32__)
24-
#define __WIN32__ 1
25-
#endif
26-
2723
#ifdef __cplusplus
2824
}
29-
#endif
25+
#endif /* __cplusplus */
3026

3127
#endif /* !LIBACQUIRE_ACQUIRE_COMMON_DEFS_H */

acquire/acquire_crc32c.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ extern "C" {
99

1010
struct acquire_handle; /* Forward declaration */
1111

12-
#if defined(LIBACQUIRE_USE_CRC32C)
12+
#if defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C
1313
int _crc32c_verify_async_start(struct acquire_handle *handle,
1414
const char *filepath, enum Checksum algorithm,
1515
const char *expected_hash);
1616
enum acquire_status _crc32c_verify_async_poll(struct acquire_handle *handle);
1717
void _crc32c_verify_async_cancel(struct acquire_handle *handle);
18-
#endif
18+
#endif /* defined(LIBACQUIRE_USE_CRC32C) && LIBACQUIRE_USE_CRC32C */
1919

20-
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_USE_CRC32C)
20+
#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_USE_CRC32C) && \
21+
LIBACQUIRE_USE_CRC32C
2122

2223
#include "acquire_handle.h"
2324
#include <errno.h>
@@ -27,7 +28,7 @@ void _crc32c_verify_async_cancel(struct acquire_handle *handle);
2728

2829
#ifndef CHUNK_SIZE
2930
#define CHUNK_SIZE 4096
30-
#endif
31+
#endif /* !CHUNK_SIZE */
3132

3233
struct checksum_backend {
3334
FILE *file;
@@ -176,7 +177,7 @@ void _crc32c_verify_async_cancel(struct acquire_handle *handle) {
176177
}
177178

178179
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_USE_CRC32C) \
179-
*/
180+
&& LIBACQUIRE_USE_CRC32C */
180181

181182
#ifdef __cplusplus
182183
}

acquire/acquire_libcurl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <unistd.h>
1818
#endif
1919

20+
#include "acquire_config.h"
2021
#include "acquire_download.h"
2122
#include "acquire_handle.h"
2223

@@ -38,7 +39,7 @@ static void acquire_curl_global_cleanup(void) {
3839
}
3940
/* --- */
4041

41-
#if defined(LIBACQUIRE_DOWNLOAD_DIR_IMPL)
42+
#ifdef LIBACQUIRE_DOWNLOAD_DIR_IMPL
4243
const char *get_download_dir(void) { return ".downloads"; }
4344
#endif /* LIBACQUIRE_DOWNLOAD_DIR_IMPL */
4445

@@ -152,6 +153,8 @@ int acquire_download_async_start(struct acquire_handle *handle, const char *url,
152153
curl_easy_setopt(be->easy_handle, CURLOPT_NOPROGRESS, 0L);
153154
curl_easy_setopt(be->easy_handle, CURLOPT_FOLLOWLOCATION, 1L);
154155
curl_easy_setopt(be->easy_handle, CURLOPT_FAILONERROR, 1L);
156+
curl_easy_setopt(be->easy_handle, CURLOPT_USERAGENT,
157+
"libacquire/" LIBACQUIRE_VERSION);
155158
curl_easy_setopt(be->easy_handle, CURLOPT_SSLVERSION,
156159
CURL_SSLVERSION_TLSv1_2);
157160

acquire/acquire_libfetch.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#if defined(LIBACQUIRE_USE_LIBFETCH) && LIBACQUIRE_USE_LIBFETCH && \
55
defined(LIBACQUIRE_IMPLEMENTATION)
6-
#define LIBACQUIRE_LIBFETCH_H
76

87
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
98
#include <synchapi.h>
@@ -19,7 +18,7 @@
1918
#include "acquire_download.h"
2019
#include "fetch.h"
2120

22-
#if defined(LIBACQUIRE_DOWNLOAD_DIR_IMPL)
21+
#ifdef LIBACQUIRE_DOWNLOAD_DIR_IMPL
2322
const char *get_download_dir(void) { return ".downloads"; }
2423
#endif /* LIBACQUIRE_DOWNLOAD_DIR_IMPL */
2524

@@ -149,7 +148,7 @@ void acquire_download_async_cancel(struct acquire_handle *handle) {
149148
}
150149
}
151150

152-
#endif /* defined(LIBACQUIRE_USE_LIBFETCH) && \
153-
LIBACQUIRE_USE_LIBFETCH && defined(LIBACQUIRE_IMPLEMENTATION) */
151+
#endif /* defined(LIBACQUIRE_USE_LIBFETCH) && LIBACQUIRE_USE_LIBFETCH && \
152+
defined(LIBACQUIRE_IMPLEMENTATION) */
154153

155154
#endif /* !LIBACQUIRE_LIBFETCH_H */

acquire/acquire_librhash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LIBACQUIRE_ACQUIRE_LIBRHASH_H
22
#define LIBACQUIRE_ACQUIRE_LIBRHASH_H
33

4-
#ifdef LIBACQUIRE_USE_LIBRHASH
4+
#if defined(LIBACQUIRE_USE_LIBRHASH) && LIBACQUIRE_USE_LIBRHASH
55

66
#ifdef __cplusplus
77
extern "C" {
@@ -172,6 +172,6 @@ void _librhash_verify_async_cancel(struct acquire_handle *handle) {
172172
}
173173
#endif /* __cplusplus */
174174

175-
#endif /* LIBACQUIRE_USE_LIBRHASH */
175+
#endif /* defined(LIBACQUIRE_USE_LIBRHASH) && LIBACQUIRE_USE_LIBRHASH */
176176

177177
#endif /* !LIBACQUIRE_ACQUIRE_LIBRHASH_H */

0 commit comments

Comments
 (0)