source: MondoRescue/branches/stable/mondo/src/test/test-mem.c

Last change on this file was 1421, checked in by Bruno Cornec, 17 years ago

tests reviewed

File size: 1.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <assert.h>
5
6#include "mr_mem.h"
7#include "mr_file.h"
8
9void (*mr_cleanup)(void) = NULL;
10
11void is_null(const char* str)
12{
13 if (str == NULL)
14 printf("pointer is null\n");
15 else
16 printf("pointer is NOT null\n");
17}
18
19int main(void)
20{
21 char *str = NULL;
22 FILE *fd = NULL;
23 size_t n = 0;
24
25 printf("*** Test with mr_malloc/mr_free\n");
26 str = mr_malloc(10);
27 is_null(str);
28 mr_free(str);
29 is_null(str);
30
31 printf("*** Test with mr_asprintf/mr_free\n");
32 mr_asprintf(&str,"Chain %s","of trust");
33 printf("Result: %s\n",str);
34 mr_free(str);
35
36 printf("*** Test with mr_strcat\n");
37 mr_asprintf(&str,"Another Chain");
38 mr_strcat(str," of trust");
39 printf("Result: %s\n",str);
40 mr_free(str);
41
42 printf("*** Test2 with mr_strcat\n");
43 mr_asprintf(&str,"Another Chain");
44 mr_strcat(str," %s", "of distrust");
45 printf("Result: %s\n",str);
46 mr_free(str);
47
48 printf("*** Test with mr_getline/mr_free\n");
49 fd = mr_fopen("/etc/passwd","r");
50 mr_getline(&str,&n,fd);
51 printf("1st Result: %s",str);
52 mr_getline(&str,&n,fd);
53 printf("2nd Result: %s",str);
54 mr_getline(&str,&n,fd);
55 strcpy(str,"another line\n");
56 printf("3rd Result: %s",str);
57 mr_free(str);
58
59 printf("*** Test with NULL\n");
60 str = NULL;
61 is_null(str);
62 mr_free(str);
63 is_null(str);
64
65 return 0;
66}
67
Note: See TracBrowser for help on using the repository browser.