summaryrefslogtreecommitdiff
path: root/testing/misc_tools.h
diff options
context:
space:
mode:
Diffstat (limited to 'testing/misc_tools.h')
-rw-r--r--testing/misc_tools.h73
1 files changed, 34 insertions, 39 deletions
diff --git a/testing/misc_tools.h b/testing/misc_tools.h
index 9a3d5b40..0ffd51e7 100644
--- a/testing/misc_tools.h
+++ b/testing/misc_tools.h
@@ -34,36 +34,36 @@ unsigned char *hex_string_to_bin(char hex_string[]);
34 * wiki.tox.im/index.php/Internal_functions_and_data_structures#Debugging 34 * wiki.tox.im/index.php/Internal_functions_and_data_structures#Debugging
35 *********************************************************/ 35 *********************************************************/
36#ifdef DEBUG 36#ifdef DEBUG
37#include <assert.h> 37 #include <assert.h>
38#include <stdio.h> 38 #include <stdio.h>
39#include <string.h> 39 #include <string.h>
40 40
41#define DEBUG_PRINT(str, ...) do { \ 41 #define DEBUG_PRINT(str, ...) do { \
42 char msg[1000]; \ 42 char msg[1000]; \
43 sprintf(msg, "%s(): line %d (file %s): %s%%c\n", __FUNCTION__, __LINE__, __FILE__, str); \ 43 sprintf(msg, "%s(): line %d (file %s): %s%%c\n", __FUNCTION__, __LINE__, __FILE__, str); \
44 fprintf(stderr, msg, __VA_ARGS__); \ 44 fprintf(stderr, msg, __VA_ARGS__); \
45} while (0) 45 } while (0)
46 46
47#define WARNING(...) do { \ 47 #define WARNING(...) do { \
48 fprintf(stderr, "warning in "); \ 48 fprintf(stderr, "warning in "); \
49 DEBUG_PRINT(__VA_ARGS__, ' '); \ 49 DEBUG_PRINT(__VA_ARGS__, ' '); \
50} while (0) 50 } while (0)
51 51
52#define INFO(...) do { \ 52 #define INFO(...) do { \
53 DEBUG_PRINT(__VA_ARGS__, ' '); \ 53 DEBUG_PRINT(__VA_ARGS__, ' '); \
54} while (0) 54 } while (0)
55 55
56#undef ERROR 56 #undef ERROR
57#define ERROR(exit_status, ...) do { \ 57 #define ERROR(exit_status, ...) do { \
58 fprintf(stderr, "error in "); \ 58 fprintf(stderr, "error in "); \
59 DEBUG_PRINT(__VA_ARGS__, ' '); \ 59 DEBUG_PRINT(__VA_ARGS__, ' '); \
60 exit(exit_status); \ 60 exit(exit_status); \
61} while (0) 61 } while (0)
62#else 62#else
63#define WARNING(...) 63 #define WARNING(...)
64#define INFO(...) 64 #define INFO(...)
65#undef ERROR 65 #undef ERROR
66#define ERROR(...) 66 #define ERROR(...)
67#endif // DEBUG 67#endif // DEBUG
68 68
69/************************Linked List*********************** 69/************************Linked List***********************
@@ -104,8 +104,7 @@ static inline void tox_list_add(tox_list *lst, tox_list *new_lst)
104 new_lst->prev = lst; 104 new_lst->prev = lst;
105} 105}
106 106
107static inline void 107static inline void tox_list_remove(tox_list *lst)
108tox_list_remove(tox_list *lst)
109{ 108{
110 lst->prev->next = lst->next; 109 lst->prev->next = lst->next;
111 lst->next->prev = lst->prev; 110 lst->next->prev = lst->prev;
@@ -123,23 +122,20 @@ typedef struct tox_array {
123 size_t elem_size; /* in bytes */ 122 size_t elem_size; /* in bytes */
124} tox_array; 123} tox_array;
125 124
126static inline void 125static inline void tox_array_init(tox_array *arr, size_t elem_size)
127tox_array_init(tox_array *arr, size_t elem_size)
128{ 126{
129 arr->len = 0; 127 arr->len = 0;
130 arr->elem_size = elem_size; 128 arr->elem_size = elem_size;
131 arr->data = NULL; 129 arr->data = NULL;
132} 130}
133 131
134static inline void 132static inline void tox_array_delete(tox_array *arr)
135tox_array_delete(tox_array *arr)
136{ 133{
137 free(arr->data); 134 free(arr->data);
138 arr->len = arr->elem_size = 0; 135 arr->len = arr->elem_size = 0;
139} 136}
140 137
141static inline void 138static inline void _tox_array_push(tox_array *arr, uint8_t *item)
142_tox_array_push(tox_array *arr, uint8_t *item)
143{ 139{
144 arr->data = realloc(arr->data, arr->elem_size * (arr->len+1)); 140 arr->data = realloc(arr->data, arr->elem_size * (arr->len+1));
145 141
@@ -151,8 +147,7 @@ _tox_array_push(tox_array *arr, uint8_t *item)
151/* Deletes num items from array. 147/* Deletes num items from array.
152 * Not same as pop in stacks, because to access elements you use data. 148 * Not same as pop in stacks, because to access elements you use data.
153 */ 149 */
154static inline void 150static inline void tox_array_pop(tox_array *arr, uint32_t num)
155tox_array_pop(tox_array *arr, uint32_t num)
156{ 151{
157 arr->len--; 152 arr->len--;
158 arr->data = realloc(arr->data, arr->elem_size*arr->len); 153 arr->data = realloc(arr->data, arr->elem_size*arr->len);