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
RevLine 
[1105]1#include <stdio.h>
2#include <stdlib.h>
[1178]3#include <string.h>
[1105]4#include <assert.h>
5
[1139]6#include "mr_mem.h"
7#include "mr_file.h"
8
[1421]9void (*mr_cleanup)(void) = NULL;
10
[1105]11void is_null(const char* str)
12{
[1139]13 if (str == NULL)
14 printf("pointer is null\n");
15 else
16 printf("pointer is NOT null\n");
[1105]17}
18
19int main(void)
20{
[1140]21 char *str = NULL;
[1139]22 FILE *fd = NULL;
23 size_t n = 0;
[1105]24
[1139]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);
[1105]30
[1139]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);
[1105]35
[1178]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
[1196]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
[1139]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);
[1140]54 mr_getline(&str,&n,fd);
55 strcpy(str,"another line\n");
56 printf("3rd Result: %s",str);
[1139]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;
[1105]66}
67
Note: See TracBrowser for help on using the repository browser.