/src/test/test_ext_zlib.cpp

https://github.com/tmjnaid/hiphop-php · C++ · 202 lines · 141 code · 31 blank · 30 comment · 0 complexity · af024fab7b03e78822819f871f670358 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. #include <test/test_ext_zlib.h>
  17. #include <runtime/ext/ext_zlib.h>
  18. #include <runtime/ext/ext_file.h>
  19. #include <runtime/ext/ext_output.h>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. bool TestExtZlib::RunTests(const std::string &which) {
  22. bool ret = true;
  23. RUN_TEST(test_readgzfile);
  24. RUN_TEST(test_gzfile);
  25. RUN_TEST(test_gzcompress);
  26. RUN_TEST(test_gzuncompress);
  27. RUN_TEST(test_gzdeflate);
  28. RUN_TEST(test_gzinflate);
  29. RUN_TEST(test_gzencode);
  30. RUN_TEST(test_gzdecode);
  31. RUN_TEST(test_zlib_get_coding_type);
  32. RUN_TEST(test_gzopen);
  33. RUN_TEST(test_gzclose);
  34. RUN_TEST(test_gzrewind);
  35. RUN_TEST(test_gzeof);
  36. RUN_TEST(test_gzgetc);
  37. RUN_TEST(test_gzgets);
  38. RUN_TEST(test_gzgetss);
  39. RUN_TEST(test_gzread);
  40. RUN_TEST(test_gzpassthru);
  41. RUN_TEST(test_gzseek);
  42. RUN_TEST(test_gztell);
  43. RUN_TEST(test_gzwrite);
  44. RUN_TEST(test_gzputs);
  45. return ret;
  46. }
  47. ///////////////////////////////////////////////////////////////////////////////
  48. bool TestExtZlib::test_readgzfile() {
  49. f_ob_start();
  50. f_readgzfile("test/test_ext_zlib.gz");
  51. VS(f_ob_get_clean(), "Testing Ext Zlib\n");
  52. f_ob_end_clean();
  53. return Count(true);
  54. }
  55. bool TestExtZlib::test_gzfile() {
  56. VS(f_gzfile("test/test_ext_zlib.gz"), CREATE_VECTOR1("Testing Ext Zlib\n"));
  57. return Count(true);
  58. }
  59. bool TestExtZlib::test_gzcompress() {
  60. VS(f_gzuncompress(f_gzcompress("testing gzcompress")), "testing gzcompress");
  61. return Count(true);
  62. }
  63. bool TestExtZlib::test_gzuncompress() {
  64. // tested in gzcompress
  65. return Count(true);
  66. }
  67. bool TestExtZlib::test_gzdeflate() {
  68. VS(f_gzinflate(f_gzdeflate("testing gzdeflate")), "testing gzdeflate");
  69. return Count(true);
  70. }
  71. bool TestExtZlib::test_gzinflate() {
  72. // tested in gzdeflate
  73. return Count(true);
  74. }
  75. bool TestExtZlib::test_gzencode() {
  76. Variant zipped = f_gzencode("testing gzencode");
  77. Variant f = f_fopen("test/test_ext_zlib.tmp", "w");
  78. f_fwrite(f, zipped);
  79. f_fclose(f);
  80. f_ob_start();
  81. f_readgzfile("test/test_ext_zlib.tmp");
  82. VS(f_ob_get_clean(), "testing gzencode");
  83. f_ob_end_clean();
  84. return Count(true);
  85. }
  86. bool TestExtZlib::test_gzdecode() {
  87. Variant zipped = f_gzencode("testing gzencode");
  88. VS(f_gzdecode(zipped), "testing gzencode");
  89. return Count(true);
  90. }
  91. bool TestExtZlib::test_zlib_get_coding_type() {
  92. try {
  93. f_zlib_get_coding_type();
  94. } catch (NotSupportedException e) {
  95. return Count(true);
  96. }
  97. return Count(false);
  98. }
  99. bool TestExtZlib::test_gzopen() {
  100. Variant f = f_gzopen("test/test_ext_zlib.tmp", "w");
  101. VERIFY(!same(f, false));
  102. f_gzputs(f, "testing gzputs\n");
  103. f_gzwrite(f, "<html>testing gzwrite</html>\n");
  104. f_gzclose(f);
  105. f = f_gzopen("test/test_ext_zlib.tmp", "r");
  106. VS(f_gzread(f, 7), "testing");
  107. VS(f_gzgetc(f), " ");
  108. VS(f_gzgets(f), "gzputs\n");
  109. VS(f_gzgetss(f), "testing gzwrite\n");
  110. VS(f_gztell(f), 44);
  111. VERIFY(f_gzeof(f));
  112. VERIFY(f_gzrewind(f));
  113. VS(f_gztell(f), 0);
  114. VERIFY(!f_gzeof(f));
  115. f_gzseek(f, -7, k_SEEK_END);
  116. VS(f_gzgets(f), "testing gzputs\n");
  117. f_gzclose(f);
  118. return Count(true);
  119. }
  120. bool TestExtZlib::test_gzclose() {
  121. // tested in gzopen
  122. return Count(true);
  123. }
  124. bool TestExtZlib::test_gzrewind() {
  125. // tested in gzopen
  126. return Count(true);
  127. }
  128. bool TestExtZlib::test_gzeof() {
  129. // tested in gzopen
  130. return Count(true);
  131. }
  132. bool TestExtZlib::test_gzgetc() {
  133. // tested in gzopen
  134. return Count(true);
  135. }
  136. bool TestExtZlib::test_gzgets() {
  137. // tested in gzopen
  138. return Count(true);
  139. }
  140. bool TestExtZlib::test_gzgetss() {
  141. // tested in gzopen
  142. return Count(true);
  143. }
  144. bool TestExtZlib::test_gzread() {
  145. // tested in gzopen
  146. return Count(true);
  147. }
  148. bool TestExtZlib::test_gzpassthru() {
  149. Variant f = f_gzopen("test/test_ext_zlib.gz", "r");
  150. f_ob_start();
  151. f_gzpassthru(f);
  152. VS(f_ob_get_clean(), "Testing Ext Zlib\n");
  153. f_ob_end_clean();
  154. return Count(true);
  155. }
  156. bool TestExtZlib::test_gzseek() {
  157. // tested in gzopen
  158. return Count(true);
  159. }
  160. bool TestExtZlib::test_gztell() {
  161. // tested in gzopen
  162. return Count(true);
  163. }
  164. bool TestExtZlib::test_gzwrite() {
  165. // tested in gzopen
  166. return Count(true);
  167. }
  168. bool TestExtZlib::test_gzputs() {
  169. // tested in gzopen
  170. return Count(true);
  171. }