diff UnitTestsSources/RestApi.cpp @ 707:203157cb4fde

unit tests of httpclient
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Feb 2014 14:37:35 +0100
parents 17815b9d4280
children 3d6f9b7d0add
line wrap: on
line diff
--- a/UnitTestsSources/RestApi.cpp	Thu Feb 13 12:46:39 2014 +0100
+++ b/UnitTestsSources/RestApi.cpp	Thu Feb 13 14:37:35 2014 +0100
@@ -3,6 +3,8 @@
 #include <ctype.h>
 #include <glog/logging.h>
 
+#include "../Core/ChunkedBuffer.h"
+#include "../Core/HttpClient.h"
 #include "../Core/RestApi/RestApi.h"
 #include "../Core/Uuid.h"
 #include "../Core/OrthancException.h"
@@ -10,6 +12,51 @@
 
 using namespace Orthanc;
 
+#if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS)
+#error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS"
+#endif
+
+TEST(HttpClient, Basic)
+{
+  HttpClient c;
+  ASSERT_FALSE(c.IsVerbose());
+  c.SetVerbose(true);
+  ASSERT_TRUE(c.IsVerbose());
+  c.SetVerbose(false);
+  ASSERT_FALSE(c.IsVerbose());
+
+#if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1
+  Json::Value v;
+  c.SetUrl("http://orthanc.googlecode.com/hg/Resources/Configuration.json");
+  c.Apply(v);
+  ASSERT_TRUE(v.isMember("StorageDirectory"));
+  //ASSERT_EQ(GetLastStatusText());
+
+  v = Json::nullValue;
+
+  HttpClient cc(c);
+  cc.SetUrl("https://orthanc.googlecode.com/hg/Resources/Configuration.json");
+  cc.Apply(v);
+  ASSERT_TRUE(v.isMember("LuaScripts"));
+#endif
+}
+
+TEST(RestApi, ChunkedBuffer)
+{
+  ChunkedBuffer b;
+  ASSERT_EQ(0, b.GetNumBytes());
+
+  b.AddChunk("hello", 5);
+  ASSERT_EQ(5, b.GetNumBytes());
+
+  b.AddChunk("world", 5);
+  ASSERT_EQ(10, b.GetNumBytes());
+
+  std::string s;
+  b.Flatten(s);
+  ASSERT_EQ("helloworld", s);
+}
+
 TEST(RestApi, ParseCookies)
 {
   HttpHandler::Arguments headers;