コード例 #1
0
ファイル: test-ws.cpp プロジェクト: bsletten/monarch
/**
 * Check a GET to a url returns a certain code and data.
 */
static void _checkUrlText(
   TestRunner& tr, Url* url, int code, const char* expected, int length)
{
   // create client
   HttpClient client;

   // connect
   assertNoException(client.connect(url));

   if(tr.getVerbosityLevel() > 1)
   {
      printf("Connected to: %s\n", url->toString().c_str());
      InternetAddress address(url->getHost().c_str(), url->getPort());
      printf("%s\n", address.toString().c_str());
   }

   // do get
   HttpResponse* response = client.get(url);
   assert(response != NULL);

   if(tr.getVerbosityLevel() > 1)
   {
      printf("Response header:\n%s\n",
         response->getHeader()->toString().c_str());
   }

   if(response->getHeader()->getStatusCode() != code)
   {
      printf("Expecting response status code: %d, got %d\n",
         response->getHeader()->getStatusCode(), code);
   }
   assert(response->getHeader()->getStatusCode() == code);

   // receive content
   HttpTrailer trailer;
   ByteBuffer b;
   ByteArrayOutputStream baos(&b);
   assertNoException(client.receiveContent(&baos, &trailer));

   // put data in strings for strcmp since it may not be NULL terminated
   string strexpected;
   strexpected.assign(expected, length);

   string strdata;
   strdata.assign(b.data(), b.length());

   if(tr.getVerbosityLevel() > 1)
   {
      printf("Response content (%d bytes):\n%s\n", b.length(), strdata.c_str());
      printf("Response trailers:\n%s\n", trailer.toString().c_str());
   }

   // check content
   assertStrCmp(strdata.c_str(), strexpected.c_str());
   assert(b.length() == length);

   client.disconnect();

   assertNoExceptionSet();
}
コード例 #2
0
ファイル: test-config.cpp プロジェクト: digitalbazaar/bitmunk
static void runConfigTest(Node& node, TestRunner& tr)
{
   tr.group("config");

   tr.test("user configs");
   {
      /*{
         printf("config debug:\n");
         Config c = node.getConfigManager()->getDebugInfo();
         JsonWriter::writeToStdOut(c, false, false);
         assertNoException();
      }*/
      UserId userId;
      bool loggedin = node.login("devuser", "password", &userId);
      assertNoExceptionSet();
      assert(loggedin);
      {
         Config c = node.getConfigManager()->getUserConfig(userId, true);
         assert(!c.isNull());
         if(tr.getVerbosityLevel() > 1)
         {
            printf("raw user %" PRIu64 " config:\n", userId);
            JsonWriter::writeToStdOut(c, false, false);
            assertNoExceptionSet();
         }
      }
      {
         Config c = node.getConfigManager()->getUserConfig(userId);
         assert(!c.isNull());
         if(tr.getVerbosityLevel() > 1)
         {
            printf("user %" PRIu64 " config:\n", userId);
            JsonWriter::writeToStdOut(c, false, false);
            assertNoExceptionSet();
         }
      }
      node.logout(userId);
      assertNoExceptionSet();
   }
   tr.passIfNoException();

   tr.ungroup();
}