Move sandbox bytecode generation out of HPHPc
[hiphop-php.git] / hphp / test / ext / test_base.cpp
blob43787766444b16b93e7ff74991fa9c0af14f8549
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 +----------------------------------------------------------------------+
17 #include "hphp/test/ext/test_base.h"
18 #include "hphp/test/ext/test.h"
19 #include "hphp/runtime/base/comparisons.h"
20 #include "hphp/runtime/ext/array/ext_array.h"
21 #include "hphp/runtime/ext/std/ext_std_variable.h"
23 ///////////////////////////////////////////////////////////////////////////////
25 TestBase::TestBase() {
28 bool TestBase::Count(bool result) {
29 if (result) {
30 Test::s_passed++;
31 pass_count++;
32 } else {
33 fail_count++;
36 Test::s_total++;
37 return result;
40 bool TestBase::CountSkip() {
41 skip_count++;
42 Test::s_skipped++;
43 Test::s_total++;
44 return true;
47 bool TestBase::VerifySame(const char *exp1, const char *exp2,
48 const Variant& v1, const Variant& v2) {
49 if (!same(v1, v2)) {
50 g_context->obEndAll();
51 printf("%s = \n", exp1); HHVM_FN(var_dump)(v1);
52 printf("%s = \n", exp2); HHVM_FN(var_dump)(v2);
53 return false;
55 return true;
58 bool TestBase::VerifyClose(const char *exp1, const char *exp2,
59 double v1, double v2) {
60 double diff = v1 > v2 ? v1 - v2 : v2 - v1;
61 if (diff > 0.00001) {
62 g_context->obEndAll();
63 printf("%s = \n", exp1); HHVM_FN(var_dump)(v1);
64 printf("%s = \n", exp2); HHVM_FN(var_dump)(v2);
65 return false;
67 return true;
70 bool TestBase::array_value_exists(const Variant& var, const Variant& value) {
71 bool found = !same(
72 Variant::attach(HHVM_FN(array_search)(value, var.toArray())),
73 false
75 if (!found) {
76 HHVM_FN(var_dump)(var);
78 return found;