mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-29 13:01:13 +03:00
misc: Refactor ssh_strerror to check return values
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
8cf9c8162f
commit
41f2ee92c6
@ -732,6 +732,34 @@ static void torture_ssh_strreplace(void **state)
|
||||
assert_null(replaced_string);
|
||||
}
|
||||
|
||||
static void torture_ssh_strerror(void **state)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t bufflen = sizeof(buf);
|
||||
char *out = NULL;
|
||||
|
||||
(void) state;
|
||||
|
||||
out = ssh_strerror(ENOENT, buf, 1); /* too short */
|
||||
assert_string_equal(out, "\0");
|
||||
|
||||
out = ssh_strerror(256, buf, bufflen); /* unknown error code */
|
||||
/* This error is always different:
|
||||
* Freebd: "Unknown error: 256"
|
||||
* MinGW/Win: "Unknown error"
|
||||
* Linux/glibc: "Unknown error 256"
|
||||
* Alpine/musl: "No error information"
|
||||
*/
|
||||
assert_non_null(out);
|
||||
|
||||
out = ssh_strerror(ENOMEM, buf, bufflen);
|
||||
/* This actually differs too for glibc/musl:
|
||||
* musl: "Out of memory"
|
||||
* everything else: "Cannot allocate memory"
|
||||
*/
|
||||
assert_non_null(out);
|
||||
}
|
||||
|
||||
int torture_run_tests(void) {
|
||||
int rc;
|
||||
struct CMUnitTest tests[] = {
|
||||
@ -755,6 +783,7 @@ int torture_run_tests(void) {
|
||||
cmocka_unit_test(torture_ssh_mkdirs),
|
||||
cmocka_unit_test(torture_ssh_quote_file_name),
|
||||
cmocka_unit_test(torture_ssh_strreplace),
|
||||
cmocka_unit_test(torture_ssh_strerror),
|
||||
};
|
||||
|
||||
ssh_init();
|
||||
|
Reference in New Issue
Block a user