Files
libakstdlib/tests/consumer/main.c

74 lines
1.7 KiB
C
Raw Normal View History

/*
* Smoke test for the installed package. See CMakeLists.txt beside this file.
*
* Deliberately touches one function from each translation unit -- the version
* entry points, a string buffer, a formatted append and a print -- so that a
* library installed with a source file missing from its link line fails here
* rather than in whatever consumer discovers it next.
*
* Returns a distinct status per step, so a CI failure names the step.
*/
#include <akstdlib.h>
int main(void)
{
akerr_ErrorContext *e = NULL;
aksl_StrBuf buf;
const char *text = NULL;
size_t len = 0;
uint32_t hash = 0;
int count = 0;
/* The header and the .so have to agree, which is the whole point of the
* version machinery: the soname catches this first in normal use, and this
* catches a hand-install that bypassed it. */
e = AKSL_VERSION_CHECK();
if ( e != NULL ) {
return 1;
}
/* src/collections.c */
e = aksl_strbuf_init(&buf, 0);
if ( e != NULL ) {
return 2;
}
e = aksl_strbuf_appendf(&buf, "libakstdlib %s, soname %s",
aksl_version_string(), aksl_version_soname());
if ( e != NULL ) {
return 3;
}
e = aksl_strbuf_cstr(&buf, &text);
if ( e != NULL ) {
return 4;
}
/* src/string.c */
e = aksl_strlen(text, &len);
if ( e != NULL ) {
return 5;
}
/* src/stdlib.c */
e = aksl_strhash_djb2(text, len, &hash);
if ( e != NULL ) {
return 6;
}
e = aksl_printf(&count, "%s (%zu bytes, djb2 %u)\n", text, len, hash);
if ( e != NULL ) {
return 7;
}
/* src/stream.c */
e = aksl_fflush(NULL);
if ( e != NULL ) {
return 8;
}
e = aksl_strbuf_free(&buf);
if ( e != NULL ) {
return 9;
}
return 0;
}