/src/test/test_ext_options.cpp

https://github.com/fungos/hiphop-php · C++ · 424 lines · 348 code · 58 blank · 18 comment · 1 complexity · 624eef4b5ca1fd46391736996a4ea21c 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_options.h>
  17. #include <runtime/ext/ext_options.h>
  18. ///////////////////////////////////////////////////////////////////////////////
  19. bool TestExtOptions::RunTests(const std::string &which) {
  20. bool ret = true;
  21. RUN_TEST(test_assert_options);
  22. RUN_TEST(test_assert);
  23. RUN_TEST(test_dl);
  24. RUN_TEST(test_extension_loaded);
  25. RUN_TEST(test_get_loaded_extensions);
  26. RUN_TEST(test_get_extension_funcs);
  27. RUN_TEST(test_get_cfg_var);
  28. RUN_TEST(test_get_current_user);
  29. RUN_TEST(test_get_defined_constants);
  30. RUN_TEST(test_get_include_path);
  31. RUN_TEST(test_restore_include_path);
  32. RUN_TEST(test_set_include_path);
  33. RUN_TEST(test_get_included_files);
  34. RUN_TEST(test_inclued_get_data);
  35. RUN_TEST(test_get_magic_quotes_gpc);
  36. RUN_TEST(test_get_magic_quotes_runtime);
  37. RUN_TEST(test_get_required_files);
  38. RUN_TEST(test_getenv);
  39. RUN_TEST(test_getlastmod);
  40. RUN_TEST(test_getmygid);
  41. RUN_TEST(test_getmyinode);
  42. RUN_TEST(test_getmypid);
  43. RUN_TEST(test_getmyuid);
  44. RUN_TEST(test_getopt);
  45. RUN_TEST(test_getrusage);
  46. RUN_TEST(test_clock_getres);
  47. RUN_TEST(test_clock_gettime);
  48. RUN_TEST(test_clock_settime);
  49. RUN_TEST(test_cpu_get_count);
  50. RUN_TEST(test_cpu_get_model);
  51. RUN_TEST(test_ini_alter);
  52. RUN_TEST(test_ini_get_all);
  53. RUN_TEST(test_ini_get);
  54. RUN_TEST(test_ini_restore);
  55. RUN_TEST(test_ini_set);
  56. RUN_TEST(test_memory_get_peak_usage);
  57. RUN_TEST(test_memory_get_usage);
  58. RUN_TEST(test_php_ini_scanned_files);
  59. RUN_TEST(test_php_logo_guid);
  60. RUN_TEST(test_php_sapi_name);
  61. RUN_TEST(test_php_uname);
  62. RUN_TEST(test_phpcredits);
  63. RUN_TEST(test_phpinfo);
  64. RUN_TEST(test_phpversion);
  65. RUN_TEST(test_putenv);
  66. RUN_TEST(test_set_magic_quotes_runtime);
  67. RUN_TEST(test_set_time_limit);
  68. RUN_TEST(test_sys_get_temp_dir);
  69. RUN_TEST(test_version_compare);
  70. RUN_TEST(test_zend_logo_guid);
  71. RUN_TEST(test_zend_thread_id);
  72. RUN_TEST(test_zend_version);
  73. return ret;
  74. }
  75. ///////////////////////////////////////////////////////////////////////////////
  76. bool TestExtOptions::test_assert_options() {
  77. f_assert_options(1);
  78. return Count(true);
  79. }
  80. bool TestExtOptions::test_assert() {
  81. f_assert(true);
  82. try {
  83. f_assert(false);
  84. } catch (Assertion e) {
  85. return Count(true);
  86. }
  87. return Count(true);
  88. }
  89. bool TestExtOptions::test_dl() {
  90. VS(f_dl(""), 0);
  91. return Count(true);
  92. }
  93. bool TestExtOptions::test_extension_loaded() {
  94. VERIFY(f_extension_loaded("phpmcc"));
  95. VERIFY(f_extension_loaded("bcmath"));
  96. VERIFY(f_extension_loaded("spl"));
  97. VERIFY(f_extension_loaded("curl"));
  98. VERIFY(f_extension_loaded("simplexml"));
  99. VERIFY(f_extension_loaded("mysql"));
  100. return Count(true);
  101. }
  102. bool TestExtOptions::test_get_loaded_extensions() {
  103. VERIFY(!f_get_loaded_extensions().empty());
  104. return Count(true);
  105. }
  106. bool TestExtOptions::test_get_extension_funcs() {
  107. try {
  108. f_get_extension_funcs("");
  109. } catch (NotSupportedException e) {
  110. return Count(true);
  111. }
  112. return Count(false);
  113. }
  114. bool TestExtOptions::test_get_cfg_var() {
  115. try {
  116. f_get_cfg_var("");
  117. } catch (NotSupportedException e) {
  118. return Count(true);
  119. }
  120. return Count(false);
  121. }
  122. bool TestExtOptions::test_get_current_user() {
  123. f_get_current_user();
  124. return Count(true);
  125. }
  126. bool TestExtOptions::test_get_defined_constants() {
  127. try {
  128. f_get_defined_constants(true);
  129. return Count(false);
  130. } catch (NotSupportedException e) {
  131. return Count(true);
  132. }
  133. f_get_defined_constants();
  134. return Count(true);
  135. }
  136. bool TestExtOptions::test_get_include_path() {
  137. f_get_include_path();
  138. return Count(true);
  139. }
  140. bool TestExtOptions::test_restore_include_path() {
  141. f_restore_include_path();
  142. return Count(true);
  143. }
  144. bool TestExtOptions::test_set_include_path() {
  145. f_set_include_path("");
  146. return Count(true);
  147. }
  148. bool TestExtOptions::test_get_included_files() {
  149. VS(f_get_included_files(), Array::Create());
  150. return Count(true);
  151. }
  152. bool TestExtOptions::test_inclued_get_data() {
  153. VS(f_inclued_get_data(), Array::Create());
  154. return Count(true);
  155. }
  156. bool TestExtOptions::test_get_magic_quotes_gpc() {
  157. VS(f_get_magic_quotes_gpc(), 0);
  158. return Count(true);
  159. }
  160. bool TestExtOptions::test_get_magic_quotes_runtime() {
  161. try {
  162. f_get_magic_quotes_runtime();
  163. } catch (NotSupportedException e) {
  164. return Count(true);
  165. }
  166. return Count(false);
  167. }
  168. bool TestExtOptions::test_get_required_files() {
  169. try {
  170. f_get_required_files();
  171. } catch (NotSupportedException e) {
  172. return Count(true);
  173. }
  174. return Count(false);
  175. }
  176. bool TestExtOptions::test_getenv() {
  177. VS(f_getenv("NOTTHERE"), false);
  178. return Count(true);
  179. }
  180. bool TestExtOptions::test_getlastmod() {
  181. try {
  182. f_getlastmod();
  183. } catch (NotSupportedException e) {
  184. return Count(true);
  185. }
  186. return Count(false);
  187. }
  188. bool TestExtOptions::test_getmygid() {
  189. f_getmygid();
  190. return Count(true);
  191. }
  192. bool TestExtOptions::test_getmyinode() {
  193. try {
  194. f_getmyinode();
  195. } catch (NotSupportedException e) {
  196. return Count(true);
  197. }
  198. return Count(false);
  199. }
  200. bool TestExtOptions::test_getmypid() {
  201. VERIFY(f_getmypid());
  202. return Count(true);
  203. }
  204. bool TestExtOptions::test_getmyuid() {
  205. f_getmyuid();
  206. return Count(true);
  207. }
  208. bool TestExtOptions::test_getopt() {
  209. f_getopt("");
  210. return Count(true);
  211. }
  212. bool TestExtOptions::test_getrusage() {
  213. VERIFY(!f_getrusage().empty());
  214. return Count(true);
  215. }
  216. bool TestExtOptions::test_clock_getres() {
  217. Variant sec, nsec;
  218. VERIFY(f_clock_getres(k_CLOCK_THREAD_CPUTIME_ID, ref(sec), ref(nsec)));
  219. VS(sec, 0);
  220. VS(nsec, 1);
  221. return Count(true);
  222. }
  223. bool TestExtOptions::test_clock_gettime() {
  224. Variant sec, nsec;
  225. VERIFY(f_clock_gettime(k_CLOCK_THREAD_CPUTIME_ID, ref(sec), ref(nsec)));
  226. return Count(true);
  227. }
  228. bool TestExtOptions::test_clock_settime() {
  229. f_clock_settime(k_CLOCK_THREAD_CPUTIME_ID, 100, 100);
  230. return Count(true);
  231. }
  232. bool TestExtOptions::test_cpu_get_count() {
  233. VERIFY(f_cpu_get_count() > 0);
  234. return Count(true);
  235. }
  236. bool TestExtOptions::test_cpu_get_model() {
  237. VERIFY(!f_cpu_get_model().empty());
  238. return Count(true);
  239. }
  240. bool TestExtOptions::test_ini_alter() {
  241. try {
  242. f_ini_alter("", "");
  243. } catch (NotSupportedException e) {
  244. return Count(true);
  245. }
  246. return Count(false);
  247. }
  248. bool TestExtOptions::test_ini_get_all() {
  249. try {
  250. f_ini_get_all();
  251. } catch (NotSupportedException e) {
  252. return Count(true);
  253. }
  254. return Count(false);
  255. }
  256. bool TestExtOptions::test_ini_get() {
  257. VS(f_ini_get(""), "");
  258. f_ini_set("memory_limit", 50000000);
  259. VS(f_ini_get("memory_limit"), "50000000");
  260. f_set_time_limit(30);
  261. VS(f_ini_get("max_execution_time"), "30");
  262. f_ini_set("max_execution_time", 40);
  263. VS(f_ini_get("max_execution_time"), "40");
  264. return Count(true);
  265. }
  266. bool TestExtOptions::test_ini_restore() {
  267. f_ini_restore("");
  268. return Count(true);
  269. }
  270. bool TestExtOptions::test_ini_set() {
  271. f_ini_set("", "");
  272. return Count(true);
  273. }
  274. bool TestExtOptions::test_memory_get_peak_usage() {
  275. f_memory_get_peak_usage();
  276. return Count(true);
  277. }
  278. bool TestExtOptions::test_memory_get_usage() {
  279. f_memory_get_usage();
  280. return Count(true);
  281. }
  282. bool TestExtOptions::test_php_ini_scanned_files() {
  283. try {
  284. f_php_ini_scanned_files();
  285. } catch (NotSupportedException e) {
  286. return Count(true);
  287. }
  288. return Count(false);
  289. }
  290. bool TestExtOptions::test_php_logo_guid() {
  291. try {
  292. f_php_logo_guid();
  293. } catch (NotSupportedException e) {
  294. return Count(true);
  295. }
  296. return Count(false);
  297. }
  298. bool TestExtOptions::test_php_sapi_name() {
  299. f_php_sapi_name();
  300. return Count(true);
  301. }
  302. bool TestExtOptions::test_php_uname() {
  303. VERIFY(!f_php_uname().empty());
  304. return Count(true);
  305. }
  306. bool TestExtOptions::test_phpcredits() {
  307. try {
  308. f_phpcredits();
  309. } catch (NotSupportedException e) {
  310. return Count(true);
  311. }
  312. return Count(false);
  313. }
  314. bool TestExtOptions::test_phpinfo() {
  315. //f_phpinfo();
  316. return Count(true);
  317. }
  318. bool TestExtOptions::test_phpversion() {
  319. VS(f_phpversion(), "5.3.3.hiphop");
  320. return Count(true);
  321. }
  322. bool TestExtOptions::test_putenv() {
  323. VERIFY(f_putenv("FOO=bar"));
  324. VERIFY(!f_putenv("FOO"));
  325. return Count(true);
  326. }
  327. bool TestExtOptions::test_set_magic_quotes_runtime() {
  328. f_set_magic_quotes_runtime(false);
  329. return Count(true);
  330. }
  331. bool TestExtOptions::test_set_time_limit() {
  332. f_set_time_limit(2);
  333. return Count(true);
  334. }
  335. bool TestExtOptions::test_sys_get_temp_dir() {
  336. VERIFY(f_sys_get_temp_dir() == "/tmp");
  337. return Count(true);
  338. }
  339. bool TestExtOptions::test_version_compare() {
  340. VERIFY(!f_version_compare("1.3.0.dev", "1.1.2", "<"));
  341. return Count(true);
  342. }
  343. bool TestExtOptions::test_zend_logo_guid() {
  344. try {
  345. f_zend_logo_guid();
  346. } catch (NotSupportedException e) {
  347. return Count(true);
  348. }
  349. return Count(false);
  350. }
  351. bool TestExtOptions::test_zend_thread_id() {
  352. try {
  353. f_zend_thread_id();
  354. } catch (NotSupportedException e) {
  355. return Count(true);
  356. }
  357. return Count(false);
  358. }
  359. bool TestExtOptions::test_zend_version() {
  360. try {
  361. f_zend_version();
  362. } catch (NotSupportedException e) {
  363. return Count(true);
  364. }
  365. return Count(false);
  366. }