medit/tests/markup.c

106 lines
2.1 KiB
C
Raw Normal View History

2005-06-23 13:18:45 -07:00
/*
* tests/markup.c
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
2005-06-23 13:18:45 -07:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
2005-06-22 11:20:32 -07:00
#include "mooutils/moomarkup.h"
#include <string.h>
#include <glib.h>
const char *markup =
2007-06-15 15:27:03 -07:00
"<doc>\n"
2005-06-22 11:20:32 -07:00
"<blah>\n"
"<!-- COMMENT -->\n"
" <bam a=\"ddd\" g=\"ferfer\"> ffff </bam>\n"
"<!-- COMMENT -->\n"
2007-06-15 15:27:03 -07:00
"<!---->\n"
2005-06-22 11:20:32 -07:00
" <rgrg/>\n"
"</blah>\n"
"<!-- COMMENT -->\n"
"<fffff/>\n"
2007-06-15 15:27:03 -07:00
"</doc>\n"
2005-06-22 11:20:32 -07:00
;
2007-06-15 15:27:03 -07:00
#define NTIMES 1000
static void
profile (const char *filename)
{
guint i;
char *content;
double time = 0.;
if (!g_file_get_contents (filename, &content, NULL, NULL))
g_error ("oops");
for (i = 0; i < NTIMES; ++i)
{
GTimer *timer = g_timer_new ();
MooMarkupDoc *doc = moo_markup_parse_memory (content, -1, NULL);
time += g_timer_elapsed (timer, NULL);
moo_markup_doc_unref (doc);
g_timer_destroy (timer);
}
g_print ("%f\n", time / NTIMES);
}
2005-06-22 11:20:32 -07:00
int main (int argc, char *argv[])
{
2005-06-23 13:18:45 -07:00
gboolean print = TRUE;
const char *file = NULL;
MooMarkupDoc *doc = NULL;
GError *err = NULL;
if (argc > 1)
file = argv[1];
if (argc > 2)
print = FALSE;
2005-06-22 11:20:32 -07:00
if (file)
2007-06-15 15:27:03 -07:00
{
profile (file);
return 0;
2005-06-22 11:20:32 -07:00
doc = moo_markup_parse_file (file, &err);
2007-06-15 15:27:03 -07:00
}
2005-06-22 11:20:32 -07:00
else
doc = moo_markup_parse_memory (markup, -1, &err);
2005-06-23 13:18:45 -07:00
if (!doc)
{
2005-06-22 11:20:32 -07:00
g_print ("ERROR\n");
2005-06-23 13:18:45 -07:00
if (err)
{
2007-06-15 15:27:03 -07:00
g_print ("%s\n", err->message);
2005-06-22 11:20:32 -07:00
g_error_free (err);
}
}
2005-06-23 13:18:45 -07:00
else
{
2005-06-22 11:20:32 -07:00
g_print ("SUCCESS\n");
2005-06-23 13:18:45 -07:00
if (print)
{
char *text = moo_markup_node_get_string (MOO_MARKUP_NODE (doc));
2005-06-22 11:20:32 -07:00
g_print ("%s\n", text);
g_free (text);
g_print ("------------------------------\n");
}
2005-06-23 13:18:45 -07:00
2005-06-22 11:20:32 -07:00
moo_markup_doc_unref (doc);
}
2005-09-04 21:24:21 -07:00
return 0;
2005-06-22 11:20:32 -07:00
}