lib: move all UNITTEST prototypes to C files

- make extract-unit-protos handle multi-line prototypes - but they need
  to be above the implementation

- Prototypes for static functions we use in unit tests should not be in
  header files. We generate lib/unitprotos.h for this purpose

- Removed some function wrappers written for unit tests and make them
  use UNITTEST function directly.

- Renamed time2str() in the tool to timebuf() since we have the same
  name in lib/ and in unit tests they can both be used non-static in a
  build.

This reverts commit f95fadd116.

Follow-up to #21010

Closes #21014
This commit is contained in:
Daniel Stenberg 2026-03-19 17:04:00 +01:00
parent 7242cea7f6
commit 98d8e82c74
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
42 changed files with 109 additions and 149 deletions

View file

@ -28,7 +28,10 @@
/* The point of this function would be to return a string of the input data,
but never longer than 5 columns (+ one zero byte).
Add suffix k, M, G when suitable... */
Add suffix k, M, G when suitable...
Unit test @1622
*/
UNITTEST char *max5data(curl_off_t bytes, char *max5, size_t mlen)
{
/* a signed 64-bit value is 8192 petabytes maximum */
@ -85,8 +88,11 @@ int xferinfo_cb(void *clientp,
return 0;
}
/* Provide a time string that is 8 letters long (plus the zero byte) */
UNITTEST void time2str(char *r, size_t rlen, curl_off_t seconds)
/* Provide a time string that is 8 letters long (plus the zero byte)
Unit test @1622
*/
UNITTEST void timebuf(char *r, size_t rlen, curl_off_t seconds)
{
curl_off_t h;
if(seconds <= 0) {
@ -260,14 +266,14 @@ bool progress_meter(CURLM *multi, struct curltime *start, bool final)
if(dlknown && speed) {
curl_off_t est = all_dltotal / speed;
curl_off_t left = (all_dltotal - all_dlnow) / speed;
time2str(time_left, sizeof(time_left), left);
time2str(time_total, sizeof(time_total), est);
timebuf(time_left, sizeof(time_left), left);
timebuf(time_total, sizeof(time_total), est);
}
else {
time2str(time_left, sizeof(time_left), 0);
time2str(time_total, sizeof(time_total), 0);
timebuf(time_left, sizeof(time_left), 0);
timebuf(time_total, sizeof(time_total), 0);
}
time2str(time_spent, sizeof(time_spent), spent);
timebuf(time_spent, sizeof(time_spent), spent);
(void)curl_multi_get_offt(multi, CURLMINFO_XFERS_ADDED, &xfers_added);
(void)curl_multi_get_offt(multi, CURLMINFO_XFERS_RUNNING, &xfers_running);

View file

@ -39,7 +39,7 @@ void progress_finalize(struct per_transfer *per);
#ifdef UNITTESTS
UNITTEST char *max5data(curl_off_t bytes, char *max5, size_t mlen);
UNITTEST void time2str(char *r, size_t rlen, curl_off_t seconds);
UNITTEST void timebuf(char *r, size_t rlen, curl_off_t seconds);
#endif
#endif /* HEADER_CURL_TOOL_PROGRESS_H */