tests: file lists [not finished]
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
Start testing: Jun 12 15:32 EEST
|
||||
Start testing: Jun 18 18:29 EEST
|
||||
----------------------------------------------------------
|
||||
End testing: Jun 12 15:32 EEST
|
||||
End testing: Jun 18 18:29 EEST
|
||||
|
||||
@@ -36,7 +36,7 @@ void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
||||
case 1:
|
||||
fl_args.page = DEF_PAGE_NUM;
|
||||
}
|
||||
file_list(sess, s_d, &fl_args);
|
||||
file_list(sess, &fl_args);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
||||
fl_args.name = s_val;
|
||||
}
|
||||
|
||||
file_list(sess, s_d, &fl_args);
|
||||
file_list(sess, &fl_args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,20 @@ char *extract_second_arg(char *);
|
||||
size_t get_file_size(char *, char *);
|
||||
|
||||
void clear_list(fl_t **a_start, fl_t **a_current) {
|
||||
if (a_start == NULL) return;
|
||||
if (a_start == NULL)
|
||||
return;
|
||||
fl_t *start = *a_start;
|
||||
if (start != NULL) {
|
||||
fl_t *curr = start;
|
||||
fl_t *next;
|
||||
do {
|
||||
next = curr->next;
|
||||
if (curr->description != NULL) free(curr->description);
|
||||
if (curr->name != NULL) free(curr->name);
|
||||
if (curr->owner != NULL) free(curr->owner);
|
||||
if (curr->description != NULL)
|
||||
free(curr->description);
|
||||
if (curr->name != NULL)
|
||||
free(curr->name);
|
||||
if (curr->owner != NULL)
|
||||
free(curr->owner);
|
||||
free(curr);
|
||||
} while ((curr = next) != NULL);
|
||||
}
|
||||
@@ -50,7 +54,7 @@ void clear_list(fl_t **a_start, fl_t **a_current) {
|
||||
}
|
||||
}
|
||||
|
||||
void file_list(session *sess, server_data_t *s_d, i_file_list_t *f_args) {
|
||||
void file_list(session *sess, i_file_list_t *f_args) {
|
||||
fl_t *fl_start, *fl_current;
|
||||
char item_h[256];
|
||||
i_get_files_db args;
|
||||
@@ -67,6 +71,7 @@ void file_list(session *sess, server_data_t *s_d, i_file_list_t *f_args) {
|
||||
args.offset = f_args->limit * (f_args->page - 1);
|
||||
args.sort_by = ID;
|
||||
args.sort_direction = ASC;
|
||||
|
||||
if (f_args->name != NULL) {
|
||||
strcpy(args.search_str, f_args->name);
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@ enum f_actions {
|
||||
};
|
||||
|
||||
void clear_list(fl_t **a_start, fl_t **a_current);
|
||||
void file_list(session *, server_data_t *, i_file_list_t *l_args);
|
||||
void file_list(session *, i_file_list_t *l_args);
|
||||
int file_send_prepare(session *, char *, server_data_t *);
|
||||
int file_receive_prepare(session *sess, char *line, server_data_t *s_d);
|
||||
int file_upload_description(session *sess, char *line, server_data_t *s_d);
|
||||
|
||||
@@ -28,6 +28,6 @@ target_link_libraries(file_list
|
||||
main
|
||||
)
|
||||
|
||||
target_link_options(file_list PRIVATE -Wl,--wrap=db_get_files_data)
|
||||
target_link_options(file_list PRIVATE -Wl,--wrap=db_get_files_data,--wrap=write)
|
||||
|
||||
add_test(NAME file_p_file_list_test_1 COMMAND file_list)
|
||||
+32
-6
@@ -11,18 +11,44 @@
|
||||
#include <file_p.h>
|
||||
#include <main.h>
|
||||
#include <string.h>
|
||||
/* TODO: complete */
|
||||
#include <sys/cdefs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
dbuf_t *dbuf;
|
||||
|
||||
fl_t fl_sample = {
|
||||
.name = "test_file", .description = "Hello test file", .owner = "user1234"};
|
||||
.name = "test_file", .description = "Hello test file", .owner = "user1234", .next = NULL};
|
||||
|
||||
ssize_t __wrap_write(int __fd, const void *__buf, size_t __n) __wur {
|
||||
dbuf_write(__buf, __n, &dbuf);
|
||||
return __n;
|
||||
}
|
||||
|
||||
int32_t __wrap_db_get_files_data(i_get_files_db *arg, fl_t **fl_start,
|
||||
int32_t *full_count) {
|
||||
fill_list_with_samples(&fl_sample, fl_start, NULL, 123);
|
||||
*full_count = 123;
|
||||
return 123;
|
||||
fill_list_with_samples(&fl_sample, fl_start, NULL, arg->limit);
|
||||
*full_count = arg->limit;
|
||||
return arg->limit;
|
||||
}
|
||||
|
||||
void test__file_list(void **state) {}
|
||||
#define COUNT 20
|
||||
|
||||
void test__file_list(void **state) {
|
||||
session sess = {
|
||||
.fl_start = NULL,
|
||||
.fl_current = NULL,
|
||||
.uname = "user1234",
|
||||
};
|
||||
i_file_list_t fl_args = {.page = 1, .limit = COUNT, .name = NULL};
|
||||
dbuf = dbuf_init(INBUFSIZE);
|
||||
file_list(&sess, &fl_args);
|
||||
assert_int_not_equal(dbuf->len, 0);
|
||||
char *end_str = strstr(dbuf->ptr, ":END: PAGE");
|
||||
char strcmp[128];
|
||||
sprintf(strcmp, ":END: PAGE 1/1 COUNT: %d/%d\n", COUNT, COUNT);
|
||||
assert_string_equal(strcmp, end_str);
|
||||
dbuf_destroy(&dbuf);
|
||||
}
|
||||
|
||||
int setup(void **state) { return 0; }
|
||||
int tear_down(void **state) { return 0; }
|
||||
|
||||
+47
-4
@@ -1,13 +1,54 @@
|
||||
#include "../../src/main.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "utils.h"
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
fl_t **fl_cur, int amount) {
|
||||
dbuf_t *dbuf_init(size_t init_sz) {
|
||||
dbuf_t *dbuf = malloc(sizeof(dbuf_t));
|
||||
dbuf->ptr = malloc(init_sz);
|
||||
dbuf->len = 0;
|
||||
dbuf->capacity = init_sz;
|
||||
return dbuf;
|
||||
}
|
||||
|
||||
static int it_times = 0;
|
||||
|
||||
int32_t dbuf_write(const char *text, size_t text_len, dbuf_t **__dbuf) {
|
||||
dbuf_t *dbuf = *__dbuf;
|
||||
if (text_len > (dbuf->capacity - dbuf->len)) {
|
||||
if (text_len > (dbuf->capacity * 2 - dbuf->len)) {
|
||||
dbuf->capacity = text_len * 2;
|
||||
} else {
|
||||
dbuf->capacity = dbuf->capacity * 2;
|
||||
}
|
||||
(*__dbuf)->ptr = realloc(dbuf->ptr, dbuf->capacity);
|
||||
dbuf = *__dbuf;
|
||||
}
|
||||
|
||||
it_times++;
|
||||
int _it_times = it_times;
|
||||
strncpy(dbuf->ptr + dbuf->len, text, text_len);
|
||||
dbuf->len += text_len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dbuf_destroy(dbuf_t **dbuf) {
|
||||
free((*dbuf)->ptr);
|
||||
free(*dbuf);
|
||||
*dbuf = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st, fl_t **fl_cur,
|
||||
int amount) {
|
||||
fl_t *_fl_st, *_fl_cur;
|
||||
|
||||
if (fl_st == NULL) return;
|
||||
if (fl_st == NULL)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (i == 0) {
|
||||
@@ -19,6 +60,8 @@ void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
_fl_cur = _fl_cur->next;
|
||||
}
|
||||
|
||||
_fl_cur->next = NULL;
|
||||
|
||||
_fl_cur->name = malloc(sizeof(char) * (strlen(fl_sample->name) + 32));
|
||||
_fl_cur->description =
|
||||
malloc(sizeof(char) * strlen(fl_sample->description) + 1);
|
||||
@@ -32,6 +75,6 @@ void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
}
|
||||
*fl_st = _fl_st;
|
||||
if (fl_cur != NULL) {
|
||||
*fl_cur = _fl_cur;
|
||||
*fl_cur = _fl_cur;
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -1,4 +1,13 @@
|
||||
#include "../../src/main.h"
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_samples, fl_t **fl_st,
|
||||
fl_t **fl_cur, int amount);
|
||||
typedef struct {
|
||||
char *ptr;
|
||||
size_t len;
|
||||
size_t capacity;
|
||||
} dbuf_t;
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_samples, fl_t **fl_st, fl_t **fl_cur,
|
||||
int amount);
|
||||
dbuf_t *dbuf_init(size_t init_sz);
|
||||
int32_t dbuf_write(const char *text, size_t len, dbuf_t **dbuf);
|
||||
int32_t dbuf_destroy(dbuf_t **dbuf);
|
||||
Reference in New Issue
Block a user