From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>
Subject: [Qemu-devel] [PATCH 07/11] qjson: Use QBool for true/false keywords
Date: Sat, 17 Oct 2009 08:36:07 -0500 [thread overview]
Message-ID: <1255786571-3528-8-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1255786571-3528-1-git-send-email-aliguori@us.ibm.com>
Instead of parsing true/false as QInt, parse them as QBool and update the
test suite accordingly.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile | 2 +-
check-qjson.c | 19 ++++++++++---------
qjson.c | 5 +++--
3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/Makefile b/Makefile
index 095d2ce..fe6c9bf 100644
--- a/Makefile
+++ b/Makefile
@@ -217,7 +217,7 @@ check-qstring: check-qstring.o qstring.o qemu-malloc.o
check-qdict: check-qdict.o qdict.o qint.o qstring.o qemu-malloc.o
check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o
check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o
-check-qjson: check-qjson.o qjson.o qstring.o qint.o qdict.o qlist.o qfloat.o qemu-malloc.o
+check-qjson: check-qjson.o qjson.o qstring.o qint.o qdict.o qlist.o qfloat.o qbool.o qemu-malloc.o
clean:
# avoid old build problems by removing potentially incorrect old files
diff --git a/check-qjson.c b/check-qjson.c
index 0f661b9..32aa33c 100644
--- a/check-qjson.c
+++ b/check-qjson.c
@@ -15,6 +15,7 @@
#include "qdict.h"
#include "qlist.h"
#include "qfloat.h"
+#include "qbool.h"
#include "qjson.h"
#include "qemu-common.h"
@@ -259,28 +260,28 @@ END_TEST
START_TEST(keyword_literal)
{
QObject *obj;
- QInt *qint;
+ QBool *qbool;
size_t length = 0;
obj = qobject_from_json("true", &length);
fail_unless(obj != NULL);
- fail_unless(qobject_type(obj) == QTYPE_QINT);
+ fail_unless(qobject_type(obj) == QTYPE_QBOOL);
fail_unless(length == 4);
- qint = qobject_to_qint(obj);
- fail_unless(qint_get_int(qint) != 0);
+ qbool = qobject_to_qbool(obj);
+ fail_unless(qbool_get_int(qbool) != 0);
- QDECREF(qint);
+ QDECREF(qbool);
obj = qobject_from_json("false", &length);
fail_unless(obj != NULL);
- fail_unless(qobject_type(obj) == QTYPE_QINT);
+ fail_unless(qobject_type(obj) == QTYPE_QBOOL);
fail_unless(length == 5);
- qint = qobject_to_qint(obj);
- fail_unless(qint_get_int(qint) == 0);
+ qbool = qobject_to_qbool(obj);
+ fail_unless(qbool_get_int(qbool) == 0);
- QDECREF(qint);
+ QDECREF(qbool);
}
END_TEST
diff --git a/qjson.c b/qjson.c
index 64cecc6..ce2c942 100644
--- a/qjson.c
+++ b/qjson.c
@@ -17,6 +17,7 @@
#include "qdict.h"
#include "qlist.h"
#include "qfloat.h"
+#include "qbool.h"
#include "qjson.h"
typedef struct JSONParserContext
@@ -627,9 +628,9 @@ static QObject *parse_keyword(JSONParserContext *ctxt, const char *data, size_t
}
if (strcmp(qstring_get_str(str), "true") == 0) {
- obj = QOBJECT(qint_from_int(1));
+ obj = QOBJECT(qbool_from_int(1));
} else if (strcmp(qstring_get_str(str), "false") == 0) {
- obj = QOBJECT(qint_from_int(0));
+ obj = QOBJECT(qbool_from_int(0));
}
if (obj) {
--
1.6.2.5
next prev parent reply other threads:[~2009-10-17 13:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-17 13:36 [Qemu-devel] [PATCH 0/11] json parser (v2) Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 01/11] Add append method to qstring and empty constructor Anthony Liguori
2009-10-18 21:36 ` Luiz Capitulino
2009-10-23 19:33 ` Jamie Lokier
2009-10-17 13:36 ` [Qemu-devel] [PATCH 02/11] Add support for qfloat Anthony Liguori
2009-10-18 22:21 ` Luiz Capitulino
2009-10-19 14:18 ` Anthony Liguori
2009-10-22 8:49 ` Amit Shah
2009-10-22 14:01 ` Anthony Liguori
2009-10-22 14:05 ` Amit Shah
2009-10-23 19:25 ` Jamie Lokier
2009-10-23 19:36 ` Daniel P. Berrange
2009-10-17 13:36 ` [Qemu-devel] [PATCH 03/11] Add a test case " Anthony Liguori
2009-10-17 14:00 ` Edgar E. Iglesias
2009-10-17 16:21 ` Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 04/11] Add json->qobject parser Anthony Liguori
2009-10-23 17:45 ` Luiz Capitulino
2009-10-17 13:36 ` [Qemu-devel] [PATCH 05/11] Add unit test for json parser Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 06/11] qobject: add QBool type Anthony Liguori
2009-10-18 21:50 ` Luiz Capitulino
2009-10-19 14:17 ` Anthony Liguori
2009-10-19 14:21 ` Luiz Capitulino
2009-10-17 13:36 ` Anthony Liguori [this message]
2009-10-17 13:36 ` [Qemu-devel] [PATCH 08/11] qjson: add %i for parsing bools Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 09/11] qjson: add unit test for varargs bool parsing Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 10/11] qjson: add vararg format for embedded qobjects Anthony Liguori
2009-10-17 13:36 ` [Qemu-devel] [PATCH 11/11] qjson: add unit test to check %p format Anthony Liguori
2009-10-18 21:34 ` [Qemu-devel] [PATCH 0/11] json parser (v2) Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1255786571-3528-8-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).