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

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

ChangeLog for mindi UTF-8
mr_strcat much more powerful as taking a vararg (+ tests).
improved text output to log file for mondo
merge from trunk memory management for mondorestore (begining)

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