Add json_boolean() macro
[jansson.git] / test / suites / api / test_simple.c
index 0284879..4e2bb2f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
+ * Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org>
  *
  * Jansson is free software; you can redistribute it and/or modify
  * it under the terms of the MIT license. See LICENSE for details.
 #include "util.h"
 
 /* Call the simple functions not covered by other tests of the public API */
-int main()
+static void run_tests()
 {
     json_t *value;
 
+    value = json_boolean(1);
+    if(!json_is_true(value))
+        fail("json_boolean(1) failed");
+    json_decref(value);
+
+    value = json_boolean(-123);
+    if(!json_is_true(value))
+        fail("json_boolean(-123) failed");
+    json_decref(value);
+
+    value = json_boolean(0);
+    if(!json_is_false(value))
+        fail("json_boolean(0) failed");
+    json_decref(value);
+
+
     value = json_integer(1);
     if(json_typeof(value) != JSON_INTEGER)
         fail("json_typeof failed");
@@ -150,5 +166,34 @@ int main()
         fail("json_null failed");
     json_decref(value);
 
-    return 0;
+    /* Test reference counting on singletons (true, false, null) */
+    value = json_true();
+    if(value->refcount != (size_t)-1)
+      fail("refcounting true works incorrectly");
+    json_decref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting true works incorrectly");
+    json_incref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting true works incorrectly");
+
+    value = json_false();
+    if(value->refcount != (size_t)-1)
+      fail("refcounting false works incorrectly");
+    json_decref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting false works incorrectly");
+    json_incref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting false works incorrectly");
+
+    value = json_null();
+    if(value->refcount != (size_t)-1)
+      fail("refcounting null works incorrectly");
+    json_decref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting null works incorrectly");
+    json_incref(value);
+    if(value->refcount != (size_t)-1)
+      fail("refcounting null works incorrectly");
 }