forked from coreos/rpm-ostree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some basic coverage of the json parsing.
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
include $(top_srcdir)/buildutil/glib-tap.mk | ||
|
||
tests_shutil_CPPFLAGS = -I $(srcdir)/src | ||
tests_shutil_CFLAGS = $(BUILDDEP_GIO_UNIX_CFLAGS) | ||
tests_shutil_LDADD = $(BUILDDEP_GIO_UNIX_LIBS) libgsystem.la | ||
tests_jsonutil_CPPFLAGS = -I $(srcdir)/src | ||
tests_jsonutil_CFLAGS = $(PKGDEP_RPMOSTREE_CFLAGS) | ||
tests_jsonutil_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostree.la | ||
|
||
installed_test_data = tests/libtest.sh | ||
|
||
test_scripts = \ | ||
tests/test-basic.sh \ | ||
$(NULL) | ||
|
||
test_programs = \ | ||
tests/jsonutil \ | ||
$(NULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <glib-unix.h> | ||
#include <libgsystem.h> | ||
#include "rpmostree-json-parsing.h" | ||
|
||
static const gchar *test_data = | ||
"{ \"text\" : \"hello, world!\", \"foo\" : null, \"blah\" : 47, \"double\" : 42.47 }"; | ||
|
||
static JsonObject * | ||
get_test_data (void) | ||
{ | ||
GError *error = NULL; | ||
gs_unref_object JsonParser *parser = json_parser_new (); | ||
(void)json_parser_load_from_data (parser, test_data, -1, &error); | ||
g_assert_no_error (error); | ||
return json_object_ref (json_node_get_object (json_parser_get_root (parser))); | ||
} | ||
|
||
static void | ||
test_get_optional_string_member (void) | ||
{ | ||
GError *error = NULL; | ||
JsonObject *obj = get_test_data (); | ||
const char *str; | ||
|
||
(void) _rpmostree_jsonutil_object_get_optional_string_member (obj, "nomember", &str, &error); | ||
g_assert_no_error (error); | ||
g_assert (str == NULL); | ||
|
||
(void) _rpmostree_jsonutil_object_get_optional_string_member (obj, "text", &str, &error); | ||
g_assert_no_error (error); | ||
g_assert_cmpstr (str, ==, "hello, world!"); | ||
|
||
str = _rpmostree_jsonutil_object_require_string_member (obj, "nomember", &error); | ||
g_assert (error != NULL); | ||
g_clear_error (&error); | ||
g_assert (str == NULL); | ||
|
||
str = _rpmostree_jsonutil_object_require_string_member (obj, "text", &error); | ||
g_assert_no_error (error); | ||
g_assert_cmpstr (str, ==, "hello, world!"); | ||
|
||
json_object_unref (obj); | ||
} | ||
|
||
int | ||
main (int argc, | ||
char *argv[]) | ||
{ | ||
g_test_init (&argc, &argv, NULL); | ||
|
||
g_test_add_func ("/jsonparsing/get-optional-member", test_get_optional_string_member); | ||
|
||
return g_test_run (); | ||
} |