grim/guifications3
Clone
Summary
Browse
Changes
Graph
merging
2011-05-16, Gary Kramlich
8e6f170cb062
merging
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<check.h>
#include
<dlfcn.h>
#include
<glib.h>
#include
"test_objects.h"
/******************************************************************************
* Types
*****************************************************************************/
typedef
GType
(
*
RegistrationFunc
)(
void
);
typedef
struct
{
gchar
*
name
;
gchar
*
ancestor
;
gboolean
abstract
;
RegistrationFunc
reg_func
;
GList
*
properties
;
}
GfObjectInfo
;
typedef
struct
{
GfObjectInfo
*
current
;
}
GfObjectParserData
;
/******************************************************************************
* Globals
*****************************************************************************/
static
GList
*
objects
=
NULL
;
/******************************************************************************
* Helpers
*****************************************************************************/
#define gf_object_test_find_registration_func(name) \
((RegistrationFunc)dlsym(NULL, (name)))
/******************************************************************************
* Data file loading
*****************************************************************************/
static
void
gf_object_test_parse_object
(
GfObjectParserData
*
gopd
,
const
gchar
*
name
,
const
gchar
**
anames
,
const
gchar
**
avalues
)
{
gint
attrib
=
0
;
gopd
->
current
=
g_new0
(
GfObjectInfo
,
1
);
for
(
attrib
=
0
;
anames
[
attrib
];
attrib
++
)
{
if
(
!
g_ascii_strcasecmp
(
anames
[
attrib
],
"name"
))
{
gopd
->
current
->
name
=
g_strdup
(
avalues
[
attrib
]);
}
else
if
(
!
g_ascii_strcasecmp
(
anames
[
attrib
],
"registration"
))
{
gopd
->
current
->
reg_func
=
gf_object_test_find_registration_func
(
avalues
[
attrib
]);
}
else
if
(
!
g_ascii_strcasecmp
(
anames
[
attrib
],
"ancestor"
))
{
gopd
->
current
->
ancestor
=
g_strdup
(
avalues
[
attrib
]);
}
else
if
(
!
g_ascii_strcasecmp
(
anames
[
attrib
],
"abstract"
))
{
gopd
->
current
->
abstract
=
(
!
g_ascii_strcasecmp
(
avalues
[
attrib
],
"1"
))
?
TRUE
:
FALSE
;
}
}
}
static
void
gf_object_test_parse_property
(
GfObjectParserData
*
gopd
,
const
gchar
*
name
,
const
gchar
**
anames
,
const
gchar
**
avalues
)
{
GParamSpec
*
spec
=
NULL
;
gint
attrib
=
0
;
}
static
void
gf_object_test_element_start
(
GMarkupParseContext
*
ctx
,
const
gchar
*
name
,
const
gchar
**
anames
,
const
gchar
**
avalues
,
gpointer
data
,
GError
**
error
)
{
GfObjectParserData
*
gopd
=
(
GfObjectParserData
*
)
data
;
if
(
!
g_ascii_strcasecmp
(
name
,
"object"
))
gf_object_test_parse_object
(
gopd
,
name
,
anames
,
avalues
);
else
if
(
!
g_ascii_strcasecmp
(
name
,
"property"
))
gf_object_test_parse_property
(
gopd
,
name
,
anames
,
avalues
);
}
static
void
gf_object_test_element_end
(
GMarkupParseContext
*
ctx
,
const
gchar
*
name
,
gpointer
data
,
GError
**
error
)
{
GfObjectParserData
*
gopd
=
(
GfObjectParserData
*
)
data
;
objects
=
g_list_append
(
objects
,
gopd
->
current
);
gopd
->
current
=
NULL
;
}
static
GMarkupParser
parser
=
{
gf_object_test_element_start
,
gf_object_test_element_end
,
NULL
,
NULL
,
NULL
};
static
void
gf_object_test_load_data
(
const
gchar
*
filename
)
{
GfObjectParserData
data
;
GMarkupParseContext
*
ctx
=
NULL
;
GError
*
error
=
NULL
;
gchar
*
contents
=
NULL
;
gsize
len
;
if
(
!
g_file_get_contents
(
filename
,
&
contents
,
&
len
,
&
error
))
{
gf_log_warning
(
"GfObjectTest"
,
"Failed to read '%s'; %s.
\n
"
,
filename
,
(
error
->
message
)
?
error
->
message
:
"Unknown error"
);
g_error_free
(
error
);
return
;
}
ctx
=
g_markup_parse_context_new
(
&
parser
,
0
,
&
data
,
NULL
);
if
(
!
g_markup_parse_context_parse
(
ctx
,
contents
,
len
,
NULL
))
{
gf_log_warning
(
"GfObjectTest"
,
"Failed to parse '%s'.
\n
"
,
filename
);
g_markup_parse_context_free
(
ctx
);
g_free
(
contents
);
return
;
}
if
(
!
g_markup_parse_context_end_parse
(
ctx
,
NULL
))
{
gf_log_warning
(
"GfObjectTest"
,
"Error parsing '%s'.
\n
"
,
filename
);
g_markup_parse_context_free
(
ctx
);
g_free
(
contents
);
return
;
}
g_markup_parse_context_free
(
ctx
);
g_free
(
contents
);
}
/******************************************************************************
* Suite
*****************************************************************************/
Suite
*
object_suite
(
void
)
{
Suite
*
s
=
suite_create
(
"Object suite"
);
TCase
*
tc
=
NULL
;
gf_object_test_load_data
(
"test_objects.xml"
);
}