Skip to content

Commit 1ba1801

Browse files
Merge pull request #70 from dreamer-coding/clean_mock
Clean mock
2 parents 9e1c65b + a4c42aa commit 1ba1801

File tree

2 files changed

+66
-55
lines changed

2 files changed

+66
-55
lines changed

code/logic/fossil/test/mocking.h

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,69 @@
1919

2020
#include <stdio.h>
2121
#include <stdlib.h>
22-
#include <string.h>
22+
#include <stddef.h>
2323
#include <stdbool.h>
24+
#include <string.h>
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
// *****************************************************************************
31+
// Type declarations
32+
// *****************************************************************************
33+
34+
typedef struct fossil_mock_call_t {
35+
char *function_name;
36+
char **arguments;
37+
int num_args;
38+
struct fossil_mock_call_t *next;
39+
} fossil_mock_call_t;
40+
41+
typedef struct {
42+
fossil_mock_call_t *head;
43+
fossil_mock_call_t *tail;
44+
int size;
45+
} fossil_mock_calllist_t;
46+
47+
// *****************************************************************************
48+
// Function declarations
49+
// *****************************************************************************
50+
51+
/**
52+
* Initializes a fossil_mock_calllist_t.
53+
*
54+
* @param list The fossil_mock_calllist_t to initialize.
55+
*/
56+
void fossil_mock_init(fossil_mock_calllist_t *list);
57+
58+
/**
59+
* Destroys a fossil_mock_calllist_t and frees all associated memory.
60+
*
61+
* @param list The fossil_mock_calllist_t to destroy.
62+
*/
63+
void fossil_mock_destroy(fossil_mock_calllist_t *list);
64+
65+
/**
66+
* Adds a fossil_mock_call_t to the fossil_mock_calllist_t.
67+
*
68+
* @param list The fossil_mock_calllist_t to add the fossil_mock_call_t to.
69+
* @param function_name The name of the function being called.
70+
* @param arguments The arguments passed to the function.
71+
* @param num_args The number of arguments.
72+
*/
73+
void fossil_mock_add_call(fossil_mock_calllist_t *list, const char *function_name, char **arguments, int num_args);
74+
75+
/**
76+
* Prints the contents of a fossil_mock_calllist_t.
77+
*
78+
* @param list The fossil_mock_calllist_t to print.
79+
*/
80+
void fossil_mock_print(fossil_mock_calllist_t *list);
81+
82+
#ifdef __cplusplus
83+
}
84+
#endif
2485

2586
/**
2687
* @brief Macro for initializing the mock list.
@@ -112,58 +173,4 @@
112173
typedef struct name
113174
#endif
114175

115-
#ifdef __cplusplus
116-
extern "C" {
117-
#endif
118-
119-
// C interface
120-
121-
typedef struct fossil_mock_call_t {
122-
char *function_name;
123-
char **arguments;
124-
int num_args;
125-
struct fossil_mock_call_t *next;
126-
} fossil_mock_call_t;
127-
128-
typedef struct {
129-
fossil_mock_call_t *head;
130-
fossil_mock_call_t *tail;
131-
int size;
132-
} fossil_mock_calllist_t;
133-
134-
/**
135-
* Initializes a fossil_mock_calllist_t.
136-
*
137-
* @param list The fossil_mock_calllist_t to initialize.
138-
*/
139-
void fossil_mock_init(fossil_mock_calllist_t *list);
140-
141-
/**
142-
* Destroys a fossil_mock_calllist_t and frees all associated memory.
143-
*
144-
* @param list The fossil_mock_calllist_t to destroy.
145-
*/
146-
void fossil_mock_destroy(fossil_mock_calllist_t *list);
147-
148-
/**
149-
* Adds a fossil_mock_call_t to the fossil_mock_calllist_t.
150-
*
151-
* @param list The fossil_mock_calllist_t to add the fossil_mock_call_t to.
152-
* @param function_name The name of the function being called.
153-
* @param arguments The arguments passed to the function.
154-
* @param num_args The number of arguments.
155-
*/
156-
void fossil_mock_add_call(fossil_mock_calllist_t *list, const char *function_name, char **arguments, int num_args);
157-
158-
/**
159-
* Prints the contents of a fossil_mock_calllist_t.
160-
*
161-
* @param list The fossil_mock_calllist_t to print.
162-
*/
163-
void fossil_mock_print(fossil_mock_calllist_t *list);
164-
165-
#ifdef __cplusplus
166-
}
167-
#endif
168-
169176
#endif // FOSSIL_MOCK_FRAMEWORK_H

code/logic/mocking.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
extern char *_custom_fossil_test_strdup(const char *str);
2020

21+
// *****************************************************************************
22+
// Function declarations
23+
// *****************************************************************************
24+
2125
void fossil_mock_init(fossil_mock_calllist_t *list) {
2226
if (!list) {
2327
return;

0 commit comments

Comments
 (0)