Patchwork [07/11] qjson: Use QBool for true/false keywords

login
register
mail settings
Submitter Anthony Liguori
Date Oct. 17, 2009, 1:36 p.m.
Message ID <1255786571-3528-8-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/36307/
State New
Headers show

Comments

Anthony Liguori - Oct. 17, 2009, 1:36 p.m.
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(-)

Patch

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) {