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

Last change on this file since 1196 was 1196, checked in by bruno, 12 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
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 is_null(const char* str)
10{
11    if (str == NULL)
12          printf("pointer is null\n");
13    else
14          printf("pointer is NOT null\n");
15}
16
17int main(void)
18{
19    char *str = NULL;
20    FILE *fd = NULL;
21    size_t n = 0;
22
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);
28
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);
33
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
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
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);
52    mr_getline(&str,&n,fd);
53    strcpy(str,"another line\n");
54    printf("3rd Result: %s",str);
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;
64}
65
Note: See TracBrowser for help on using the repository browser.