forked from github/server
fixed: tests that try to create duplicate spells do not spam stderr.
This commit is contained in:
parent
c032091b39
commit
2c5063095d
|
@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
#include <quicklist.h>
|
||||
|
|
|
@ -71,7 +71,7 @@ spell * create_spell(const char * name, unsigned int id)
|
|||
assert(len + sizeof(sp) < sizeof(buffer));
|
||||
|
||||
if (cb_find_str(&cb_spells, name)) {
|
||||
log_error("create_spell: duplicate name '%s'\n", name);
|
||||
log_error("create_spell: duplicate name '%s'", name);
|
||||
return 0;
|
||||
}
|
||||
sp = (spell *)calloc(1, sizeof(spell));
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <platform.h>
|
||||
|
||||
#include <quicklist.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <util/log.h>
|
||||
|
||||
#include <util/log.h>
|
||||
#include <util/lists.h>
|
||||
|
||||
#include <quicklist.h>
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
|
@ -23,17 +25,30 @@ static void test_create_a_spell(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void log_list(void *udata, int flags, const char *module, const char *format, va_list args) {
|
||||
strlist **slp = (strlist **)udata;
|
||||
addstrlist(slp, format);
|
||||
}
|
||||
|
||||
static void test_create_duplicate_spell(CuTest * tc)
|
||||
{
|
||||
spell *sp;
|
||||
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
||||
struct log_t *log;
|
||||
strlist *sl = 0;
|
||||
|
||||
test_setup();
|
||||
test_log_stderr(0);
|
||||
log = log_create(LOG_CPERROR, &sl, log_list);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
||||
|
||||
sp = create_spell("testspell", 0);
|
||||
CuAssertPtrEquals(tc, 0, create_spell("testspell", 0));
|
||||
CuAssertPtrNotNull(tc, sl);
|
||||
CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
|
||||
CuAssertPtrEquals(tc, 0, sl->next);
|
||||
freestrlist(sl);
|
||||
log_destroy(log);
|
||||
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
||||
test_cleanup();
|
||||
}
|
||||
|
@ -41,14 +56,22 @@ static void test_create_duplicate_spell(CuTest * tc)
|
|||
static void test_create_spell_with_id(CuTest * tc)
|
||||
{
|
||||
spell *sp;
|
||||
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
||||
struct log_t *log;
|
||||
strlist *sl = 0;
|
||||
|
||||
test_setup();
|
||||
test_log_stderr(0);
|
||||
log = log_create(LOG_CPERROR, &sl, log_list);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, find_spellbyid(42));
|
||||
sp = create_spell("testspell", 42);
|
||||
CuAssertPtrEquals(tc, sp, find_spellbyid(42));
|
||||
CuAssertPtrEquals(tc, 0, create_spell("testspell", 47));
|
||||
CuAssertPtrNotNull(tc, sl);
|
||||
CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
|
||||
CuAssertPtrEquals(tc, 0, sl->next);
|
||||
freestrlist(sl);
|
||||
log_destroy(log);
|
||||
CuAssertPtrEquals(tc, 0, find_spellbyid(47));
|
||||
test_cleanup();
|
||||
}
|
||||
|
|
|
@ -2176,26 +2176,6 @@ static void eval_int36(struct opstack **stack, const void *userdata)
|
|||
|
||||
/*** END MESSAGE RENDERING ***/
|
||||
|
||||
/* - String Listen --------------------------------------------- */
|
||||
void addstrlist(strlist ** SP, const char *s)
|
||||
{
|
||||
strlist *slist = malloc(sizeof(strlist));
|
||||
slist->next = NULL;
|
||||
slist->s = _strdup(s);
|
||||
addlist(SP, slist);
|
||||
}
|
||||
|
||||
void freestrlist(strlist * s)
|
||||
{
|
||||
strlist *q, *p = s;
|
||||
while (p) {
|
||||
q = p->next;
|
||||
free(p->s);
|
||||
free(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
#include <util/nrmessage.h>
|
||||
|
||||
static void log_orders(const struct message *msg)
|
||||
|
|
|
@ -121,14 +121,7 @@ extern "C" {
|
|||
size_t f_regionid(const struct region *r, const struct faction *f,
|
||||
char *buffer, size_t size);
|
||||
|
||||
typedef struct strlist {
|
||||
struct strlist *next;
|
||||
char *s;
|
||||
} strlist;
|
||||
|
||||
void addstrlist(strlist ** SP, const char *s);
|
||||
void freestrlist(strlist * s);
|
||||
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark);
|
||||
void split_paragraph(struct strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark);
|
||||
|
||||
int stream_printf(struct stream * out, const char *format, ...);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <kernel/spellbook.h>
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
|
||||
#include <quicklist.h>
|
||||
#include <stream.h>
|
||||
|
|
|
@ -121,3 +121,22 @@ unsigned int listlen(void *l)
|
|||
for (p = (void_list *)l, i = 0; p; p = p->next, i++);
|
||||
return i;
|
||||
}
|
||||
/* - String Listen --------------------------------------------- */
|
||||
void addstrlist(strlist ** SP, const char *s)
|
||||
{
|
||||
strlist *slist = malloc(sizeof(strlist));
|
||||
slist->next = NULL;
|
||||
slist->s = _strdup(s);
|
||||
addlist(SP, slist);
|
||||
}
|
||||
|
||||
void freestrlist(strlist * s)
|
||||
{
|
||||
strlist *q, *p = s;
|
||||
while (p) {
|
||||
q = p->next;
|
||||
free(p->s);
|
||||
free(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,13 @@ extern "C" {
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct strlist {
|
||||
struct strlist *next;
|
||||
char *s;
|
||||
} strlist;
|
||||
|
||||
void addstrlist(strlist ** SP, const char *s);
|
||||
void freestrlist(strlist * s);
|
||||
void addlist(void *l1, void *p1);
|
||||
void translist(void *l1, void *l2, void *p);
|
||||
#ifndef MALLOCDBG
|
||||
|
|
|
@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <platform.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "assert.h"
|
||||
|
||||
/* libc includes */
|
||||
|
|
Loading…
Reference in New Issue