Bladeren bron

alignment in how it handles json test cpoll_cppsp

stefanocasazza 10 jaren geleden
bovenliggende
commit
d5243caeae
2 gewijzigde bestanden met toevoegingen van 21 en 2 verwijderingen
  1. 2 2
      frameworks/C++/ULib/README.md
  2. 19 0
      frameworks/C++/ULib/src/json.usp

+ 2 - 2
frameworks/C++/ULib/README.md

@@ -40,10 +40,10 @@ Output
 HTTP/1.1 200 OK
 Date: Thu, 03 Jul 2014 10:11:10 GMT
 Server: ULib 
-Content-Length: 27
+Content-Length: 30
 Content-Type: application/json; charset=UTF-8
 
-{"message":"Hello, World!"}
+{ "message": "Hello, World!" }
 ```
 
 [/db](http://www.techempower.com/benchmarks/#section=db)

+ 19 - 0
frameworks/C++/ULib/src/json.usp

@@ -1,27 +1,46 @@
 <!--#declaration
+#define AS_cpoll_cppsp_DO
+
+#ifdef AS_cpoll_cppsp_DO
+#  include <json/json.h>
+#else
 static UString* pkey;
 static UString* pvalue;
+#endif
 
 static void usp_init_json()
 {
    U_TRACE(5, "::usp_init_json()")
 
+#ifndef AS_cpoll_cppsp_DO
    pkey   = U_NEW(U_STRING_FROM_CONSTANT("message"));
    pvalue = U_NEW(U_STRING_FROM_CONSTANT("Hello, World!"));
+#endif
 }
 
 static void usp_end_json()
 {
    U_TRACE(5, "::usp_end_json()")
 
+#ifndef AS_cpoll_cppsp_DO
    delete pkey;
    delete pvalue;
+#endif
 }
 -->
 <!--#header
 Content-Type: application/json; charset=UTF-8
 -->
 <!--#code
+#ifndef AS_cpoll_cppsp_DO
 UValue json(*pkey, *pvalue);
 USP_JSON_PUTS(json);
+#else
+json_object* hello = json_object_new_object();
+json_object_object_add(hello, "message", json_object_new_string("Hello, World!"));
+const char* hello_str = json_object_to_json_string(hello);
+USP_PUTS_STRING(hello_str);
+json_object_put(hello);
+#endif
+U_ClientImage_request_nocache = true;
 -->