Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GLib
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1,026
Issues
1,026
List
Boards
Labels
Milestones
Merge Requests
77
Merge Requests
77
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GNOME
GLib
Commits
91008281
Commit
91008281
authored
Jul 30, 2010
by
Matthias Clasen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve option context test coverage
parent
027905c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
glib/tests/option-context.c
glib/tests/option-context.c
+65
-0
No files found.
glib/tests/option-context.c
View file @
91008281
...
...
@@ -1747,6 +1747,69 @@ test_basic (void)
g_option_context_free
(
context
);
}
static
void
test_main_group
(
void
)
{
GOptionContext
*
context
;
GOptionGroup
*
group
;
context
=
g_option_context_new
(
NULL
);
g_assert
(
g_option_context_get_main_group
(
context
)
==
NULL
);
group
=
g_option_group_new
(
"name"
,
"description"
,
"hlep"
,
NULL
,
NULL
);
g_option_context_add_group
(
context
,
group
);
g_assert
(
g_option_context_get_main_group
(
context
)
==
NULL
);
group
=
g_option_group_new
(
"name"
,
"description"
,
"hlep"
,
NULL
,
NULL
);
g_option_context_set_main_group
(
context
,
group
);
g_assert
(
g_option_context_get_main_group
(
context
)
==
group
);
g_option_context_free
(
context
);
}
static
gboolean
error_func_called
=
FALSE
;
static
void
error_func
(
GOptionContext
*
context
,
GOptionGroup
*
group
,
gpointer
data
,
GError
**
error
)
{
g_assert_cmpint
(
GPOINTER_TO_INT
(
data
),
==
,
1234
);
error_func_called
=
TRUE
;
}
static
void
test_error_hook
(
void
)
{
GOptionContext
*
context
;
gchar
*
arg
=
NULL
;
GOptionEntry
entries
[]
=
{
{
"test"
,
't'
,
0
,
G_OPTION_ARG_STRING
,
&
arg
,
NULL
,
NULL
},
{
NULL
}
};
GOptionGroup
*
group
;
gchar
**
argv
;
gint
argc
;
gboolean
retval
;
GError
*
error
=
NULL
;
context
=
g_option_context_new
(
NULL
);
group
=
g_option_group_new
(
"name"
,
"description"
,
"hlep"
,
GINT_TO_POINTER
(
1234
),
NULL
);
g_option_group_add_entries
(
group
,
entries
);
g_option_context_set_main_group
(
context
,
group
);
g_option_group_set_error_hook
(
g_option_context_get_main_group
(
context
),
error_func
);
argv
=
split_string
(
"program --test"
,
&
argc
);
retval
=
g_option_context_parse
(
context
,
&
argc
,
&
argv
,
&
error
);
g_assert
(
retval
==
FALSE
);
g_clear_error
(
&
error
);
g_assert
(
error_func_called
);
g_strfreev
(
argv
);
g_option_context_free
(
context
);
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
@@ -1757,6 +1820,8 @@ main (int argc,
g_test_add_func
(
"/option/basic"
,
test_basic
);
g_test_add_func
(
"/option/group/captions"
,
group_captions
);
g_test_add_func
(
"/option/group/main"
,
test_main_group
);
g_test_add_func
(
"/option/group/error-hook"
,
test_error_hook
);
/* Test that restoration on failure works */
g_test_add_func
(
"/option/restoration/int"
,
error_test1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment