1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-31 00:03:08 +03:00

tests: Fix gcc compile warnings

These were mostly due to missing and non-ANSI prototypes.
This commit is contained in:
Dan Fandrich
2022-12-30 13:54:51 -08:00
committed by Dan Fandrich
parent 6cba487395
commit e3ce906caf
28 changed files with 94 additions and 31 deletions

View File

@ -159,7 +159,7 @@ add_library(session_fixture STATIC session_fixture.h session_fixture.c)
target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2)
target_include_directories(session_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
add_library(runner STATIC runner.c)
add_library(runner STATIC runner.h runner.c)
target_link_libraries(runner session_fixture)
target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")

View File

@ -55,6 +55,7 @@ EXTRA_DIST = \
openssh_server/ssh_host_ed25519_key \
openssh_server/ssh_host_rsa_key \
runner.c \
runner.h \
session_fixture.c \
session_fixture.h \
simple.c \

View File

@ -216,7 +216,7 @@ static const char *docker_machine_name(void)
return getenv("DOCKER_MACHINE_NAME");
}
static int is_running_inside_a_container()
static int is_running_inside_a_container(void)
{
#ifdef WIN32
return 0;
@ -413,7 +413,7 @@ cleanup:
static char *running_container_id = NULL;
int start_openssh_fixture()
int start_openssh_fixture(void)
{
int ret;
#ifdef HAVE_WINSOCK2_H
@ -438,7 +438,7 @@ int start_openssh_fixture()
}
}
void stop_openssh_fixture()
void stop_openssh_fixture(void)
{
if(running_container_id) {
stop_openssh_server(running_container_id);
@ -450,7 +450,7 @@ void stop_openssh_fixture()
}
}
int open_socket_to_openssh_server()
int open_socket_to_openssh_server(void)
{
return open_socket_to_container(running_container_id);
}

View File

@ -38,8 +38,8 @@
#ifndef LIBSSH2_TESTS_OPENSSH_FIXTURE_H
#define LIBSSH2_TESTS_OPENSSH_FIXTURE_H
int start_openssh_fixture();
void stop_openssh_fixture();
int open_socket_to_openssh_server();
int start_openssh_fixture(void);
void stop_openssh_fixture(void);
int open_socket_to_openssh_server(void);
#endif

View File

@ -36,10 +36,9 @@
*/
#include "session_fixture.h"
#include "runner.h"
extern int test(LIBSSH2_SESSION *session);
int main()
int main(void)
{
int exit_code = 1;
LIBSSH2_SESSION *session = start_session_fixture();

43
tests/runner.h Normal file
View File

@ -0,0 +1,43 @@
/* Copyright (C) 2016 Alexander Lamaison
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the copyright holder nor the names
* of any other contributors may be used to endorse or
* promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*/
#ifndef LIBSSH2_TESTS_RUNNER_H
#define LIBSSH2_TESTS_RUNNER_H
int test(LIBSSH2_SESSION *session);
#endif

View File

@ -61,7 +61,7 @@
LIBSSH2_SESSION *connected_session = NULL;
int connected_socket = -1;
static int connect_to_server()
static int connect_to_server(void)
{
int rc;
connected_socket = open_socket_to_openssh_server();
@ -78,7 +78,7 @@ static int connect_to_server()
return 0;
}
void setup_fixture_workdir()
static void setup_fixture_workdir(void)
{
char *wd = getenv("FIXTURE_WORKDIR");
#ifdef FIXTURE_WORKDIR
@ -99,7 +99,7 @@ void setup_fixture_workdir()
chdir(wd);
}
LIBSSH2_SESSION *start_session_fixture()
LIBSSH2_SESSION *start_session_fixture(void)
{
int rc;
@ -146,7 +146,7 @@ void print_last_session_error(const char *function)
}
}
void stop_session_fixture()
void stop_session_fixture(void)
{
if(connected_session) {
libssh2_session_disconnect(connected_session, "test ended");

View File

@ -40,8 +40,8 @@
#include <libssh2.h>
LIBSSH2_SESSION *start_session_fixture();
void stop_session_fixture();
LIBSSH2_SESSION *start_session_fixture(void);
void stop_session_fixture(void);
void print_last_session_error(const char *function);
#endif

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include "libssh2_config.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -46,27 +46,27 @@
struct expected {
int rc;
int last_error_code;
char *last_error_message;
const char *last_error_message;
};
struct test_case {
char *data;
const char *data;
int data_len;
struct expected expected;
};
#define TEST_CASES_LEN 16
struct test_case test_cases[TEST_CASES_LEN] = {
/* to small */
/* too small */
{
NULL, 0,
{FAIL, -38,
"userauth keyboard data buffer too small to get length"}},
/* to small */
/* too small */
{
"1234", 4,
{FAIL, -38,
"userauth keyboard data buffer too small to get length"}},
/* smalest valid packet possible */
/* smallest valid packet possible */
{
"<"
"\0\0\0\0"
@ -219,9 +219,8 @@ static int free_count = 0;
static
LIBSSH2_ALLOC_FUNC(test_alloc)
{
alloc_count++;
int *threshold_int_ptr = *abstract;
alloc_count++;
if (*abstract != NULL && *threshold_int_ptr == alloc_count) {
return NULL;
}
@ -241,12 +240,15 @@ LIBSSH2_FREE_FUNC(test_free)
static
int test_case(int num,
char *data, int data_len, void *abstract,
const char *data, int data_len, void *abstract,
struct expected expected)
{
int rc;
char *message;
int error_code;
LIBSSH2_SESSION *session = NULL;
alloc_count = 0;
free_count = 0;
LIBSSH2_SESSION *session = NULL;
session = libssh2_session_init_ex(test_alloc, test_free, NULL, abstract);
if(session == NULL) {
fprintf(stderr, "libssh2_session_init_ex failed\n");
@ -257,7 +259,7 @@ int test_case(int num,
session->userauth_kybd_data_len = data_len;
memcpy(session->userauth_kybd_data, data, data_len);
int rc = userauth_keyboard_interactive_decode_info_request(session);
rc = userauth_keyboard_interactive_decode_info_request(session);
if(rc != expected.rc) {
fprintf(stdout,
@ -266,8 +268,7 @@ int test_case(int num,
return 1;
}
char *message;
int error_code = libssh2_session_last_error(session, &message, NULL, 0);
error_code = libssh2_session_last_error(session, &message, NULL, 0);
if(expected.last_error_code != error_code) {
fprintf(stdout,
@ -291,7 +292,7 @@ int test_case(int num,
return 0;
}
int main()
int main(void)
{
int i;
@ -332,4 +333,4 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
return -1;
}
#endif
#endif

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>

View File

@ -1,4 +1,5 @@
#include "session_fixture.h"
#include "runner.h"
#include <libssh2.h>