/src/test/test_server.h

https://github.com/kevlund/hiphop-php · C Header · 121 lines · 65 code · 25 blank · 31 comment · 7 complexity · 05c4714e7384590d09b1a86bac8c1928 MD5 · raw file

  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010- 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 __TEST_SERVER_H__
  17. #define __TEST_SERVER_H__
  18. #include <test/test_code_run.h>
  19. #include <runtime/base/complex_types.h>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. /**
  22. * Testing HTTP server.
  23. */
  24. class TestServer : public TestCodeRun {
  25. public:
  26. TestServer();
  27. virtual bool RunTests(const std::string &which);
  28. // test test harness
  29. bool TestSanity();
  30. // test $_ variables
  31. bool TestServerVariables();
  32. bool TestGet();
  33. bool TestPost();
  34. bool TestCookie();
  35. // test transport related extension functions
  36. bool TestResponseHeader();
  37. bool TestSetCookie();
  38. // test multithreaded request processing
  39. bool TestRequestHandling();
  40. bool TestLibeventServer();
  41. // test inheriting server fd
  42. bool TestInheritFdServer();
  43. // test HttpClient class that proxy server uses
  44. bool TestHttpClient();
  45. // test RPCServer
  46. bool TestRPCServer();
  47. // test XboxServer
  48. bool TestXboxServer();
  49. // test PageletServer
  50. bool TestPageletServer();
  51. protected:
  52. void RunServer();
  53. void StopServer();
  54. bool VerifyServerResponse(const char *input, const char *output,
  55. const char *url, const char *method,
  56. const char *header, const char *postdata,
  57. bool responseHeader,
  58. const char *file = "", int line = 0,
  59. int port = 0);
  60. bool PreBindSocket();
  61. void CleanupPreBoundSocket();
  62. };
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // macros
  65. #define VSR(input, output) \
  66. if (!Count(VerifyServerResponse(input, output, "string", "GET", NULL, \
  67. NULL, false, __FILE__,__LINE__))) \
  68. return false;
  69. #define VSRES(input, output) \
  70. if (!Count(VerifyServerResponse(input, output, "string", "GET", NULL, \
  71. NULL, true, __FILE__,__LINE__))) \
  72. return false;
  73. #define VSGET(input, output, url) \
  74. if (!Count(VerifyServerResponse(input, output, url, "GET", NULL, \
  75. NULL, false, __FILE__,__LINE__))) \
  76. return false;
  77. #define VSGETP(input, output, url, port) \
  78. if (!Count(VerifyServerResponse(input, output, url, "GET", NULL, \
  79. NULL, false, __FILE__,__LINE__, \
  80. port))) \
  81. return false;
  82. #define VSPOST(input, output, url, postdata) \
  83. if (!Count(VerifyServerResponse(input, output, url, "POST", NULL, \
  84. postdata, false, __FILE__,__LINE__))) \
  85. return false;
  86. #define VSRX(input, output, url, method, header, postdata) \
  87. if (!Count(VerifyServerResponse(input, output, url, method, header, \
  88. postdata, false, __FILE__,__LINE__))) \
  89. return false;
  90. #define WITH_PREBOUND_SOCKET(action) \
  91. if (!PreBindSocket()) \
  92. return false; \
  93. action \
  94. CleanupPreBoundSocket();
  95. ///////////////////////////////////////////////////////////////////////////////
  96. #endif // __TEST_SERVER_H__