Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 62 additions & 55 deletions code/logic/fossil/test/mocking.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,69 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

// *****************************************************************************
// Type declarations
// *****************************************************************************

typedef struct fossil_mock_call_t {
char *function_name;
char **arguments;
int num_args;
struct fossil_mock_call_t *next;
} fossil_mock_call_t;

typedef struct {
fossil_mock_call_t *head;
fossil_mock_call_t *tail;
int size;
} fossil_mock_calllist_t;

// *****************************************************************************
// Function declarations
// *****************************************************************************

/**
* Initializes a fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to initialize.
*/
void fossil_mock_init(fossil_mock_calllist_t *list);

/**
* Destroys a fossil_mock_calllist_t and frees all associated memory.
*
* @param list The fossil_mock_calllist_t to destroy.
*/
void fossil_mock_destroy(fossil_mock_calllist_t *list);

/**
* Adds a fossil_mock_call_t to the fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to add the fossil_mock_call_t to.
* @param function_name The name of the function being called.
* @param arguments The arguments passed to the function.
* @param num_args The number of arguments.
*/
void fossil_mock_add_call(fossil_mock_calllist_t *list, const char *function_name, char **arguments, int num_args);

/**
* Prints the contents of a fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to print.
*/
void fossil_mock_print(fossil_mock_calllist_t *list);

#ifdef __cplusplus
}
#endif

/**
* @brief Macro for initializing the mock list.
Expand Down Expand Up @@ -112,58 +173,4 @@
typedef struct name
#endif

#ifdef __cplusplus
extern "C" {
#endif

// C interface

typedef struct fossil_mock_call_t {
char *function_name;
char **arguments;
int num_args;
struct fossil_mock_call_t *next;
} fossil_mock_call_t;

typedef struct {
fossil_mock_call_t *head;
fossil_mock_call_t *tail;
int size;
} fossil_mock_calllist_t;

/**
* Initializes a fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to initialize.
*/
void fossil_mock_init(fossil_mock_calllist_t *list);

/**
* Destroys a fossil_mock_calllist_t and frees all associated memory.
*
* @param list The fossil_mock_calllist_t to destroy.
*/
void fossil_mock_destroy(fossil_mock_calllist_t *list);

/**
* Adds a fossil_mock_call_t to the fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to add the fossil_mock_call_t to.
* @param function_name The name of the function being called.
* @param arguments The arguments passed to the function.
* @param num_args The number of arguments.
*/
void fossil_mock_add_call(fossil_mock_calllist_t *list, const char *function_name, char **arguments, int num_args);

/**
* Prints the contents of a fossil_mock_calllist_t.
*
* @param list The fossil_mock_calllist_t to print.
*/
void fossil_mock_print(fossil_mock_calllist_t *list);

#ifdef __cplusplus
}
#endif

#endif // FOSSIL_MOCK_FRAMEWORK_H
4 changes: 4 additions & 0 deletions code/logic/mocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

extern char *_custom_fossil_test_strdup(const char *str);

// *****************************************************************************
// Function declarations
// *****************************************************************************

void fossil_mock_init(fossil_mock_calllist_t *list) {
if (!list) {
return;
Expand Down