PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/ext/test_server.h

https://gitlab.com/iranjith4/hhvm
C Header | 149 lines | 86 code | 30 blank | 33 comment | 9 complexity | e99fc244b58297c63d65fc1de94951e6 MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef incl_HPHP_TEST_SERVER_H_
  17. #define incl_HPHP_TEST_SERVER_H_
  18. #include "hphp/test/ext/test_code_run.h"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. /**
  21. * Testing HTTP server.
  22. */
  23. struct TestServer : TestCodeRun {
  24. TestServer() = delete;
  25. explicit TestServer(const std::string serverType);
  26. virtual bool RunTests(const std::string &which);
  27. // test test harness
  28. bool TestSanity();
  29. // test $_ variables
  30. bool TestServerVariables();
  31. // test things that need more than one request
  32. bool TestInteraction();
  33. bool TestGet();
  34. bool TestPost();
  35. bool TestExpectContinue();
  36. bool TestCookie();
  37. // test transport related extension functions
  38. bool TestResponseHeader();
  39. bool TestSetCookie();
  40. // test multithreaded request processing
  41. bool TestRequestHandling();
  42. // test inheriting server fd
  43. virtual bool TestInheritFdServer();
  44. // test takeover
  45. virtual bool TestTakeoverServer();
  46. // test HttpClient class that proxy server uses
  47. bool TestHttpClient();
  48. // test RPCServer
  49. bool TestRPCServer();
  50. // test XboxServer
  51. bool TestXboxServer();
  52. // test PageletServer
  53. bool TestPageletServer();
  54. protected:
  55. void RunServer();
  56. void StopServer();
  57. void KillServer();
  58. bool VerifyServerResponse(const char *input, const char *output,
  59. const char *url, const char *method,
  60. const char *header, const char *postdata,
  61. bool responseHeader,
  62. const char *file = "", int line = 0,
  63. int port = 0) {
  64. return VerifyServerResponse(input, &output, &url, 1,
  65. method, header, postdata, responseHeader,
  66. file, line, port);
  67. }
  68. bool VerifyServerResponse(const char *input, const char **outputs,
  69. const char **urls, int nUrl, const char *method,
  70. const char *header, const char *postdata,
  71. bool responseHeader,
  72. const char *file = "", int line = 0,
  73. int port = 0);
  74. bool PreBindSocket();
  75. void CleanupPreBoundSocket();
  76. const std::string m_serverType;
  77. };
  78. ///////////////////////////////////////////////////////////////////////////////
  79. // macros
  80. #define VSR(input, output) \
  81. if (!Count(VerifyServerResponse(input, output, "string", "GET", nullptr, \
  82. nullptr, false, __FILE__,__LINE__))) \
  83. return false;
  84. #define VSR2(input, output) do { \
  85. const char* urls[2] = { "string", "string" }; \
  86. const char* outputs[2] = { output, output }; \
  87. if (!Count(VerifyServerResponse(input, outputs, urls, 2, "GET", \
  88. nullptr, nullptr, false, \
  89. __FILE__,__LINE__))) \
  90. return false; \
  91. } while (false)
  92. #define VSRES(input, output) \
  93. if (!Count(VerifyServerResponse(input, output, "string", "GET", nullptr, \
  94. nullptr, true, __FILE__,__LINE__))) \
  95. return false;
  96. #define VSGET(input, output, url) \
  97. if (!Count(VerifyServerResponse(input, output, url, "GET", nullptr, \
  98. nullptr, false, __FILE__,__LINE__))) \
  99. return false;
  100. #define VSGETP(input, output, url, port) \
  101. if (!Count(VerifyServerResponse(input, output, url, "GET", nullptr, \
  102. nullptr, false, __FILE__,__LINE__, \
  103. port))) \
  104. return false;
  105. #define VSPOST(input, output, url, postdata) \
  106. if (!Count(VerifyServerResponse(input, output, url, "POST", nullptr, \
  107. postdata, false, __FILE__,__LINE__))) \
  108. return false;
  109. #define VSRX(input, output, url, method, header, postdata) \
  110. if (!Count(VerifyServerResponse(input, output, url, method, header, \
  111. postdata, false, __FILE__,__LINE__))) \
  112. return false;
  113. #define WITH_PREBOUND_SOCKET(action) \
  114. if (!PreBindSocket()) \
  115. return false; \
  116. action \
  117. CleanupPreBoundSocket();
  118. ///////////////////////////////////////////////////////////////////////////////
  119. #endif // incl_HPHP_TEST_SERVER_H_