doc: Add screenshot to spiv page.
[gfxprim/pasky.git] / tests / framework / tst_msg.c
blobb4f150fba0d8dd5d30eca5ff6160a0739d607158
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <errno.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
28 #include "tst_test.h"
30 #include "tst_msg.h"
32 void tst_msg_clear(struct tst_msg_store *self)
34 struct tst_msg *msg, *prev = NULL;
36 for (msg = self->first; msg != NULL; msg = msg->next) {
37 free(prev);
38 prev = msg;
41 free(prev);
43 self->first = NULL;
44 self->last = NULL;
47 int tst_msg_append(struct tst_msg_store *self, int type, const char *msg_text)
49 size_t len = strlen(msg_text);
50 struct tst_msg *msg;
52 msg = malloc(sizeof(struct tst_msg) + len + 1);
54 if (msg == NULL) {
55 tst_warn("tst_msg: malloc() failed: %s", strerror(errno));
56 return 1;
59 msg->type = type;
60 msg->next = NULL;
61 strcpy(msg->msg, msg_text);
63 if (self->last == NULL) {
64 self->first = msg;
65 self->last = msg;
66 } else {
67 self->last->next = msg;
68 self->last = msg;
71 return 0;
74 static char type_to_char(enum tst_report_type type)
76 switch (type) {
77 case TST_MSG:
78 return 'M';
79 case TST_WARN:
80 return 'W';
81 case TST_ERR:
82 return 'E';
83 default:
84 return '?';
88 void tst_msg_print(const struct tst_msg_store *self)
90 struct tst_msg *msg;
92 for (msg = self->first; msg != NULL; msg = msg->next)
93 fprintf(stderr, "%c: %s\n", type_to_char(msg->type), msg->msg);