~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/libs3/src/testsimplexml.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** **************************************************************************
2
 
 * testsimplexml.c
3
 
 * 
4
 
 * Copyright 2008 Bryan Ischo <bryan@ischo.com>
5
 
 * 
6
 
 * This file is part of libs3.
7
 
 * 
8
 
 * libs3 is free software: you can redistribute it and/or modify it under the
9
 
 * terms of the GNU General Public License as published by the Free Software
10
 
 * Foundation, version 3 of the License.
11
 
 *
12
 
 * In addition, as a special exception, the copyright holders give
13
 
 * permission to link the code of this library and its programs with the
14
 
 * OpenSSL library, and distribute linked combinations including the two.
15
 
 *
16
 
 * libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
17
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19
 
 * details.
20
 
 *
21
 
 * You should have received a copy of the GNU General Public License version 3
22
 
 * along with libs3, in a file named COPYING.  If not, see
23
 
 * <http://www.gnu.org/licenses/>.
24
 
 *
25
 
 ************************************************************************** **/
26
 
 
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#include <stdio.h>
30
 
#include <time.h>
31
 
#include "simplexml.h"
32
 
 
33
 
static S3Status simpleXmlCallback(const char *elementPath, const char *data,
34
 
                                  int dataLen, void *callbackData)
35
 
{
36
 
    (void) callbackData;
37
 
 
38
 
    printf("[%s]: [%.*s]\n", elementPath, dataLen, data);
39
 
 
40
 
    return S3StatusOK;
41
 
}
42
 
 
43
 
 
44
 
// The only argument allowed is a specification of the random seed to use
45
 
int main(int argc, char **argv)
46
 
{
47
 
    if (argc > 1) {
48
 
        char *arg = argv[1];
49
 
        int seed = 0;
50
 
        while (*arg) {
51
 
            seed *= 10;
52
 
            seed += (*arg++ - '0');
53
 
        }
54
 
        
55
 
        srand(seed);
56
 
    }
57
 
    else {
58
 
        srand(time(0));
59
 
    }
60
 
 
61
 
    SimpleXml simpleXml;
62
 
 
63
 
    simplexml_initialize(&simpleXml, &simpleXmlCallback, 0);
64
 
 
65
 
    // Read chunks of 10K from stdin, and then feed them in random chunks
66
 
    // to simplexml_add
67
 
    char inbuf[10000];
68
 
 
69
 
    int amt_read;
70
 
    while ((amt_read = fread(inbuf, 1, sizeof(inbuf), stdin)) > 0) {
71
 
        char *buf = inbuf;
72
 
        while (amt_read) {
73
 
            int amt = (rand() % amt_read) + 1;
74
 
            S3Status status = simplexml_add(&simpleXml, buf, amt);
75
 
            if (status != S3StatusOK) {
76
 
                fprintf(stderr, "ERROR: Parse failure: %d\n", status);
77
 
                simplexml_deinitialize(&simpleXml);
78
 
                return -1;
79
 
            }
80
 
            buf += amt, amt_read -= amt;
81
 
        }
82
 
    }
83
 
 
84
 
    simplexml_deinitialize(&simpleXml);
85
 
 
86
 
    return 0;
87
 
}