1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* GData Client
* Copyright (C) Philip Withnall 2010 <philip@tecnocode.co.uk>
*
* GData Client is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* GData Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include "gdata.h"
#include "common.h"
static void
test_parse_feed (void)
{
GDataFeed *feed;
GError *error = NULL;
feed = GDATA_FEED (gdata_parsable_new_from_xml (GDATA_TYPE_FEED,
"<feed xmlns='http://www.w3.org/2005/Atom' "
"xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' "
"xmlns:gd='http://schemas.google.com/g/2005' "
"gd:etag='W/\"D08FQn8-eil7ImA9WxZbFEw.\"'>"
"<id>http://example.com/id</id>"
"<updated>2009-02-25T14:07:37.880860Z</updated>"
"<title type='text'>Test feed</title>"
"<subtitle type='text'>Test subtitle</subtitle>"
"<logo>http://example.com/logo.png</logo>"
"<icon>http://example.com/icon.png</icon>"
"<link rel='alternate' type='text/html' href='http://alternate.example.com/'/>"
"<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://example.com/id'/>"
"<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://example.com/post'/>"
"<link rel='self' type='application/atom+xml' href='http://example.com/id'/>"
"<category scheme='http://example.com/categories' term='feed'/>"
"<author>"
"<name>Joe Smith</name>"
"<email>j.smith@example.com</email>"
"</author>"
"<generator version='0.6' uri='http://example.com/'>Example Generator</generator>"
"<openSearch:totalResults>2</openSearch:totalResults>"
"<openSearch:startIndex>0</openSearch:startIndex>"
"<openSearch:itemsPerPage>50</openSearch:itemsPerPage>"
"<entry>"
"<id>entry1</id>"
"<title type='text'>Testing unhandled XML</title>"
"<updated>2009-01-25T14:07:37.880860Z</updated>"
"<published>2009-01-23T14:06:37.880860Z</published>"
"<content type='text'>Here we test unhandled XML elements.</content>"
"</entry>"
"<entry>"
"<id>entry2</id>"
"<title type='text'>Testing unhandled XML 2</title>"
"<updated>2009-02-25T14:07:37.880860Z</updated>"
"<published>2009-02-23T14:06:37.880860Z</published>"
"<content type='text'>Here we test unhandled XML elements again.</content>"
"</entry>"
"</feed>", -1, &error));
g_assert_no_error (error);
g_assert (GDATA_IS_FEED (feed));
g_clear_error (&error);
g_object_unref (feed);
}
int
main (int argc, char *argv[])
{
GTimeVal start_time, end_time;
guint i;
gdouble total_time;
#define ITERATIONS 10000
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
/* Test feed parsing time */
g_get_current_time (&start_time);
for (i = 0; i < ITERATIONS; i++)
test_parse_feed ();
g_get_current_time (&end_time);
total_time = (gdouble) (end_time.tv_sec - start_time.tv_sec) + (gdouble) (end_time.tv_usec - start_time.tv_usec) / (gdouble) G_USEC_PER_SEC;
g_message ("Parsing a feed %u times took:\n * Total: %fs\n * Per iteration: %fs",
ITERATIONS, total_time, total_time / (gdouble) ITERATIONS);
return 0;
}
|