tests: process_client_command
This commit is contained in:
@@ -12,6 +12,6 @@ target_link_libraries(process_client_command
|
||||
test_utils
|
||||
)
|
||||
|
||||
target_link_options(process_client_command PRIVATE -Wl,--wrap=file_list,--wrap=file_send_prepare,--wrap=file_receive_prepare)
|
||||
target_link_options(process_client_command PRIVATE -Wl,--wrap=file_list,--wrap=file_send_prepare,--wrap=file_receive_prepare,--wrap=session_send_string)
|
||||
|
||||
add_test(NAME client_process_client_command_test_1 COMMAND process_client_command)
|
||||
@@ -13,16 +13,31 @@
|
||||
#include <string.h>
|
||||
|
||||
int file_list_calls = 0;
|
||||
int _limit = 15;
|
||||
int _page = 2;
|
||||
int _limit = DIF_LIMIT;
|
||||
int _page = DIF_PAGE_NUM;
|
||||
char *_name = NULL;
|
||||
char _line[128];
|
||||
char file_name[] = "hello_file";
|
||||
int file_size = 121212;
|
||||
int file_perm = 1;
|
||||
char *str2snd = NULL;
|
||||
|
||||
void __wrap_session_send_string(struct session *sess, const char *fmt, ...) {
|
||||
if (str2snd != NULL) {
|
||||
assert_string_equal(fmt, str2snd);
|
||||
str2snd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void __wrap_file_list(session *sess, i_file_list_t *f_args) {
|
||||
assert_int_equal(_limit, f_args->limit);
|
||||
if (_limit != DIF_LIMIT) _limit = DIF_LIMIT;
|
||||
if (_page != DIF_PAGE_NUM) _page = DIF_PAGE_NUM;
|
||||
assert_int_equal(_page, f_args->page);
|
||||
if (_name != NULL) {
|
||||
assert_string_equal(_name, f_args->name);
|
||||
_name = NULL;
|
||||
}
|
||||
file_list_calls++;
|
||||
}
|
||||
|
||||
@@ -71,6 +86,116 @@ void test__process_client_command__file_upload_fail(void **state) {
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_download(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
|
||||
will_return(__wrap_file_send_prepare, 0);
|
||||
sprintf(_line, "file download \"%s\" %d %d", file_name, file_size, file_perm);
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(sess.state, OP_DOWNLOAD);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_download_fail(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
|
||||
will_return(__wrap_file_send_prepare, 1);
|
||||
sprintf(_line, "file download \"%s\" %d %d", file_name, file_size, file_perm);
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_search(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
_name = "name";
|
||||
_limit = 20;
|
||||
_page = 2;
|
||||
|
||||
sprintf(_line, "file search %s \"%s\" %d %d", _name, file_name, _limit, _page);
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_search_no_page(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
_name = "name";
|
||||
_limit = 20;
|
||||
|
||||
sprintf(_line, "file search %s \"%s\" %d", _name, file_name, _limit);
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_search_no_limit(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
_name = "name";
|
||||
|
||||
sprintf(_line, "file search %s \"%s\"", _name, file_name);
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_search_no_name(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
_name = "name";
|
||||
|
||||
sprintf(_line, "file search name");
|
||||
str2snd = "The file name is not specified!";
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file_search_no_type(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
|
||||
sprintf(_line, "file search");
|
||||
str2snd = "The search criteria is not specified!";
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__file(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
|
||||
sprintf(_line, "file");
|
||||
str2snd = "Available commands: list, upload, download, search";
|
||||
|
||||
process_client_command(_line, &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, OP_WAIT);
|
||||
}
|
||||
|
||||
void test__process_client_command__exit(void **state) {
|
||||
session sess = {.state = OP_WAIT};
|
||||
str2snd = "OK. Bye!\n";
|
||||
|
||||
process_client_command("exit", &sess, NULL);
|
||||
|
||||
assert_int_equal(file_list_calls, 0);
|
||||
assert_int_equal(sess.state, ERR);
|
||||
assert_int_equal(sess.reason, EXIT);
|
||||
}
|
||||
|
||||
int setup(void **state) { return 0; }
|
||||
int tear_down(void **state) { return 0; }
|
||||
|
||||
@@ -79,6 +204,15 @@ int main(int argc, char **argv) {
|
||||
cmocka_unit_test(test__process_client_command__file_list),
|
||||
cmocka_unit_test(test__process_client_command__file_upload),
|
||||
cmocka_unit_test(test__process_client_command__file_upload_fail),
|
||||
cmocka_unit_test(test__process_client_command__file_download),
|
||||
cmocka_unit_test(test__process_client_command__file_download_fail),
|
||||
cmocka_unit_test(test__process_client_command__file_search),
|
||||
cmocka_unit_test(test__process_client_command__file_search_no_page),
|
||||
cmocka_unit_test(test__process_client_command__file_search_no_limit),
|
||||
cmocka_unit_test(test__process_client_command__file_search_no_name),
|
||||
cmocka_unit_test(test__process_client_command__file_search_no_type),
|
||||
cmocka_unit_test(test__process_client_command__file),
|
||||
cmocka_unit_test(test__process_client_command__exit),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, setup, tear_down);
|
||||
|
||||
Reference in New Issue
Block a user