source: MondoRescue/branches/2.2.10/mondo/test/test-msg.c @ 2310

Last change on this file since 2310 was 2310, checked in by Bruno Cornec, 11 years ago

Backport all test programs from trunk into 2.2.10

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1/*
2 * Test file to test the messages functions
3 *
4 * $Id$
5 *
6 */
7
8#ifndef _GNU_SOURCE
9#define _GNU_SOURCE
10#endif
11
12#include <stdio.h>
13#include <stdlib.h>
14
15#include "mr_msg.h"
16#include "mr_conf.h"
17#include "mr_mem.h"
18
19void (*mr_cleanup)(void) = NULL;
20
21int main(void) {
22    int ret = 0;
23    char *s = NULL;
24    int l = 0;
25    char *str = NULL;
26    size_t n = (size_t)0;
27    FILE *fd = NULL;
28
29    /* Get logfile name and log level from conf file */
30    if ((ret = mr_conf_open("mondo.conf")) != 0) {
31        fprintf(stderr,"Unable to open conf file (%d)\n",ret); 
32        exit(-1);
33    }
34    if ((s = mr_conf_sread("loglevel")) == NULL) {
35        fprintf(stderr,"Unable to get string\n");
36        exit(-1);
37    }
38    l = atoi(s);
39    mr_free(s);
40    fprintf(stdout, "Loglevel : ***%d***\n",l);
41
42    if ((s = mr_conf_sread("logfile")) == NULL) {
43        fprintf(stderr,"Unable to get string\n");
44        exit(-1);
45    }
46    fprintf(stdout, "Logfile : ***%s***\n",s);
47    mr_conf_close();
48
49    /* test messages functions */
50    mr_msg_init(s,l);
51
52    mr_msg(1, "Log sentence : %d %d %s %s\n", 12, l, s, "is a log file");
53
54    if ((fd = fopen(s,"r")) != NULL) {
55        (void)getline(&str, &n, fd);
56        fprintf(stdout, "%s", str);
57        mr_free(str);
58        fclose(fd);
59    } else {
60        fprintf(stderr,"Unable to open file %s\n", s);
61        exit(-1);
62    }
63
64    mr_free(s);
65    mr_msg_close();
66    exit(0);
67}
Note: See TracBrowser for help on using the repository browser.