~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to source/torture/t_strappend.c

  • Committer: jerry
  • Date: 2006-07-14 21:48:39 UTC
  • Revision ID: vcs-imports@canonical.com-20060714214839-586d8c489a8fcead
gutting trunk to move to svn:externals

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2005 by Volker Lendecke
3
 
 *
4
 
 * Test harness for sprintf_append
5
 
 */
6
 
 
7
 
#include "includes.h"
8
 
#include <assert.h>
9
 
 
10
 
int main(int argc, char *argv[])
11
 
{
12
 
        TALLOC_CTX *mem_ctx;
13
 
        char *string = NULL;
14
 
        int len = 0;
15
 
        int bufsize = 4;
16
 
        int i;
17
 
 
18
 
        mem_ctx = talloc_init("t_strappend");
19
 
        if (mem_ctx == NULL) {
20
 
                fprintf(stderr, "talloc_init failed\n");
21
 
                return 1;
22
 
        }
23
 
 
24
 
        sprintf_append(mem_ctx, &string, &len, &bufsize, "");
25
 
        assert(strlen(string) == len);
26
 
        sprintf_append(mem_ctx, &string, &len, &bufsize, "");
27
 
        assert(strlen(string) == len);
28
 
        sprintf_append(mem_ctx, &string, &len, &bufsize,
29
 
                       "01234567890123456789012345678901234567890123456789\n");
30
 
        assert(strlen(string) == len);
31
 
 
32
 
 
33
 
        for (i=0; i<(100000); i++) {
34
 
                if (i%1000 == 0) {
35
 
                        printf("%d %d\r", i, bufsize);
36
 
                        fflush(stdout);
37
 
                }
38
 
                sprintf_append(mem_ctx, &string, &len, &bufsize, "%d\n", i);
39
 
                assert(strlen(string) == len);
40
 
        }
41
 
 
42
 
        talloc_destroy(mem_ctx);
43
 
 
44
 
        return 0;
45
 
}