mirror of
https://github.com/tbamud/tbamud.git
synced 2026-01-24 01:46:10 +01:00
Testing do_remove
Mocking the send_to_char function to check messages to the user. Still doesn't work for act() though. Requires libmocka-dev and libunwind-setjmp0-dev
This commit is contained in:
parent
217eac8cb3
commit
7d3acb0e3d
4 changed files with 83 additions and 5 deletions
|
|
@ -2,6 +2,8 @@
|
|||
#include "test.handler.h"
|
||||
#include "test.act.item.h"
|
||||
|
||||
void simple_world();
|
||||
|
||||
static MunitSuite suites[] = {
|
||||
{ "/handler.c", handler_c_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE },
|
||||
{ "/act.item.c", act_item_c_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE },
|
||||
|
|
@ -18,8 +20,48 @@ static const MunitSuite test_suite = {
|
|||
};
|
||||
|
||||
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
|
||||
/* Finally, we'll actually run our test suite! That second argument
|
||||
* is the user_data parameter which will be passed either to the
|
||||
* test or (if provided) the fixture setup function. */
|
||||
logfile = stderr;
|
||||
simple_world();
|
||||
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* test-fixtures common for many tests
|
||||
*/
|
||||
|
||||
void simple_world()
|
||||
{
|
||||
CREATE(world, struct room_data, 1);
|
||||
top_of_world = 1;
|
||||
}
|
||||
|
||||
static char testbuf[MAX_OUTPUT_BUFFER];
|
||||
static int testbuf_size = 0;
|
||||
|
||||
size_t __wrap_send_to_char(struct char_data *ch, const char *messg, ...)
|
||||
{
|
||||
int size = testbuf_size;
|
||||
va_list args;
|
||||
|
||||
va_start(args, messg);
|
||||
testbuf_size += vsnprintf(testbuf + size, MAX_OUTPUT_BUFFER - size, messg, args);
|
||||
va_end(args);
|
||||
|
||||
return testbuf_size;
|
||||
}
|
||||
|
||||
size_t __wrap_vwrite_to_output(struct descriptor_data *t, const char *format, va_list args)
|
||||
{
|
||||
int size = testbuf_size;
|
||||
testbuf_size += vsnprintf(testbuf + size, MAX_OUTPUT_BUFFER - size, format, args);
|
||||
return testbuf_size;
|
||||
}
|
||||
|
||||
char *get_last_messages()
|
||||
{
|
||||
char *stored_response = strdup(testbuf);
|
||||
testbuf_size = 0;
|
||||
*testbuf = '\0';
|
||||
return stored_response;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue