diff options
-rw-r--r-- | include/value.h | 11 | ||||
-rw-r--r-- | tests/cpp/h/variables.h | 1 | ||||
-rw-r--r-- | tests/cpp/include/variables/028-029-compare.h | 194 | ||||
-rw-r--r-- | tests/cpp/main.cpp | 3 | ||||
-rw-r--r-- | tests/php/phpt/variables/028-compare1.phpt | 53 | ||||
-rw-r--r-- | tests/php/phpt/variables/029-compare2.phpt | 74 | ||||
-rw-r--r-- | zend/value.cpp | 30 |
7 files changed, 366 insertions, 0 deletions
diff --git a/include/value.h b/include/value.h index 63e8e6f..e8337a0 100644 --- a/include/value.h +++ b/include/value.h @@ -322,6 +322,17 @@ public: bool operator> (const char *value) const { return ::strcmp(rawValue(), value) > 0; } /** + * Comparison operators for hardcoded Value + * @param value + */ + bool operator==(const Value &value) const; + bool operator!=(const Value &value) const { return !operator==(value); } + bool operator< (const Value &value) const; + bool operator> (const Value &value) const { return value.operator<(*this); } + bool operator<=(const Value &value) const { return !operator>(value); } + bool operator>=(const Value &value) const { return !operator<(value); } + + /** * Comparison operators * @param value */ diff --git a/tests/cpp/h/variables.h b/tests/cpp/h/variables.h index 8a074cd..0b684dd 100644 --- a/tests/cpp/h/variables.h +++ b/tests/cpp/h/variables.h @@ -27,6 +27,7 @@ #include "../include/variables/025-post-raw1.h" #include "../include/variables/026-post-raw2.h" #include "../include/variables/027-env.h" +#include "../include/variables/028-029-compare.h" //#include "../include/variables/.h" diff --git a/tests/cpp/include/variables/028-029-compare.h b/tests/cpp/include/variables/028-029-compare.h new file mode 100644 index 0000000..bd95298 --- /dev/null +++ b/tests/cpp/include/variables/028-029-compare.h @@ -0,0 +1,194 @@ +/** + * + * Test variables + * phptname.phpt + * + */ + + + + +/** + * Set up namespace + */ +namespace TestVariables { + + /* + * Test bool Value::operator==(const Value &value) const + */ + void test_compare1() + { + Php::Value v1(5), v2(5.0), v3("5"), v4("5.0"); + + Php::out << "true:" << std::endl; + Php::out << (v1 == v2) << std::endl; + Php::out << (v1 == v3) << std::endl; + Php::out << (v1 == v4) << std::endl; + Php::out << (v2 == v1) << std::endl; + Php::out << (v2 == v3) << std::endl; + Php::out << (v2 == v4) << std::endl; + Php::out << (v3 == v1) << std::endl; + Php::out << (v3 == v2) << std::endl; + Php::out << (v3 == v4) << std::endl; + Php::out << (v4 == v1) << std::endl; + Php::out << (v4 == v2) << std::endl; + Php::out << (v4 == v3) << std::endl; + + Php::Value v5(6), v6(6.0), v7("6"), v8("6.0"); + + Php::out << "false:" << std::endl; + Php::out << (v1 == v5) << std::endl; + Php::out << (v1 == v6) << std::endl; + Php::out << (v1 == v7) << std::endl; + Php::out << (v1 == v8) << std::endl; + + Php::out << (v2 == v5) << std::endl; + Php::out << (v2 == v6) << std::endl; + Php::out << (v2 == v7) << std::endl; + Php::out << (v2 == v8) << std::endl; + + Php::out << (v3 == v5) << std::endl; + Php::out << (v3 == v6) << std::endl; + Php::out << (v3 == v7) << std::endl; + Php::out << (v3 == v8) << std::endl; + + Php::out << (v4 == v5) << std::endl; + Php::out << (v4 == v6) << std::endl; + Php::out << (v4 == v7) << std::endl; + Php::out << (v4 == v8) << std::endl; + + Php::Value v9, v10, v11, v12; + v9[0] = 5; + v9[1] = 6; + + v10[0] = 5; + v10[1] = "Hello!"; + + v11[0] = 5; + v11[1] = 6; + + v12[0] = 5; + + Php::out << "Compare array:" << std::endl; + Php::out << (v1 == v9) << std::endl; + Php::out << (v5 == v9) << std::endl; + Php::out << (v9 == v10) << std::endl; + Php::out << (v11 == v9) << std::endl; + Php::out << (v12 == v9) << std::endl; + + Php::Value v13 = false, v14, v15 = 0; + Php::out << "Compare NULL:" << std::endl; + Php::out << (v1 == v13) << std::endl; + Php::out << (v1 == v14) << std::endl; + Php::out << (v1 == v15) << std::endl; + + Php::out << (v13 == v14) << std::endl; + Php::out << (v13 == v15) << std::endl; + Php::out << (v14 == v15) << std::endl; + } + + /* + * Test bool Value::operator< (const Value &value) const + */ + void test_compare2() + { + Php::Value v1(5), v2(5.0), v3("5"), v4("5.0"); + + Php::out << "false:" << std::endl; + Php::out << (v1 < v2) << std::endl; + Php::out << (v1 < v3) << std::endl; + Php::out << (v1 < v4) << std::endl; + Php::out << (v2 < v1) << std::endl; + Php::out << (v2 < v3) << std::endl; + Php::out << (v2 < v4) << std::endl; + Php::out << (v3 < v1) << std::endl; + Php::out << (v3 < v2) << std::endl; + Php::out << (v3 < v4) << std::endl; + Php::out << (v4 < v1) << std::endl; + Php::out << (v4 < v2) << std::endl; + Php::out << (v4 < v3) << std::endl; + + Php::Value v5(6), v6(6.0), v7("6"), v8("6.0"); + + Php::out << "true:" << std::endl; + Php::out << (v1 < v5) << std::endl; + Php::out << (v1 < v6) << std::endl; + Php::out << (v1 < v7) << std::endl; + Php::out << (v1 < v8) << std::endl; + + Php::out << (v2 < v5) << std::endl; + Php::out << (v2 < v6) << std::endl; + Php::out << (v2 < v7) << std::endl; + Php::out << (v2 < v8) << std::endl; + + Php::out << (v3 < v5) << std::endl; + Php::out << (v3 < v6) << std::endl; + Php::out << (v3 < v7) << std::endl; + Php::out << (v3 < v8) << std::endl; + + Php::out << (v4 < v5) << std::endl; + Php::out << (v4 < v6) << std::endl; + Php::out << (v4 < v7) << std::endl; + Php::out << (v4 < v8) << std::endl; + + Php::out << "false:" << std::endl; + Php::out << (v1 > v5) << std::endl; + Php::out << (v1 > v6) << std::endl; + Php::out << (v1 > v7) << std::endl; + Php::out << (v1 > v8) << std::endl; + + Php::out << (v2 > v5) << std::endl; + Php::out << (v2 > v6) << std::endl; + Php::out << (v2 > v7) << std::endl; + Php::out << (v2 > v8) << std::endl; + + Php::out << (v3 > v5) << std::endl; + Php::out << (v3 > v6) << std::endl; + Php::out << (v3 > v7) << std::endl; + Php::out << (v3 > v8) << std::endl; + + Php::out << (v4 > v5) << std::endl; + Php::out << (v4 > v6) << std::endl; + Php::out << (v4 > v7) << std::endl; + Php::out << (v4 > v8) << std::endl; + + Php::Value v9, v10, v11, v12; + v9[0] = 5; + v9[1] = 6; + + v10[0] = 5; + v10[1] = "Hello!"; + + v11[0] = 5; + v11[1] = 6; + + v12[0] = 5; + + Php::out << "Compare array:" << std::endl; + Php::out << (v1 < v9) << std::endl; + Php::out << (v5 < v9) << std::endl; + Php::out << (v9 < v10) << std::endl; + Php::out << (v9 > v10) << std::endl; + Php::out << (v11 < v9) << std::endl; + Php::out << (v12 < v9) << std::endl; + + Php::Value v13 = false, v14, v15 = 0; + Php::out << "Compare NULL:" << std::endl; + Php::out << (v1 < v13) << std::endl; + Php::out << (v1 < v14) << std::endl; + Php::out << (v1 < v15) << std::endl; + + Php::out << (v1 > v13) << std::endl; + Php::out << (v1 > v14) << std::endl; + Php::out << (v1 > v15) << std::endl; + + Php::out << (v13 < v14) << std::endl; + Php::out << (v13 < v15) << std::endl; + Php::out << (v14 < v15) << std::endl; + } + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 37ba5ed..47cd90d 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -125,6 +125,9 @@ extern "C" extension.add("TestVariables\\post_raw1", TestVariables::post_raw1); extension.add("TestVariables\\post_raw2", TestVariables::post_raw2); extension.add("TestVariables\\test_env", TestVariables::test_env); + extension.add("TestVariables\\test_compare1", TestVariables::test_compare1); + extension.add("TestVariables\\test_compare2", TestVariables::test_compare2); + diff --git a/tests/php/phpt/variables/028-compare1.phpt b/tests/php/phpt/variables/028-compare1.phpt new file mode 100644 index 0000000..2885fe8 --- /dev/null +++ b/tests/php/phpt/variables/028-compare1.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test bool Value::operator==(const Value &value) const +--SKIPIF-- +<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?> +--FILEEOF-- +<?php + +TestVariables\test_compare1(); + +--EXPECT-- +true: +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +false: +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +Compare array: +0 +0 +0 +1 +0 +Compare NULL: +0 +0 +0 +1 +1 +1
\ No newline at end of file diff --git a/tests/php/phpt/variables/029-compare2.phpt b/tests/php/phpt/variables/029-compare2.phpt new file mode 100644 index 0000000..333ede1 --- /dev/null +++ b/tests/php/phpt/variables/029-compare2.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test bool Value::operator< (const Value &value) const +--SKIPIF-- +<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?> +--FILEEOF-- +<?php + +TestVariables\test_compare2(); + +--EXPECT-- +false: +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +true: +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +false: +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +Compare array: +1 +1 +0 +1 +0 +1 +Compare NULL: +0 +0 +0 +1 +1 +1 +0 +0 +0
\ No newline at end of file diff --git a/zend/value.cpp b/zend/value.cpp index 7592f57..6458bd5 100644 --- a/zend/value.cpp +++ b/zend/value.cpp @@ -1312,6 +1312,36 @@ Value Value::exec(const char *name, int argc, struct _zval_struct ***params) } /** + * Comparison operators== for hardcoded Value + * @param value + */ +bool Value::operator==(const Value &value) const +{ + zval result; + if(SUCCESS != compare_function(&result, _val, value._val TSRMLS_CC) ) + { + throw Php::Exception("Not comparable"); + return false; + } + return (0 == result.value.lval); +} + +/** + * Comparison operators< for hardcoded Value + * @param value + */ +bool Value::operator< (const Value &value) const +{ + zval result; + if(SUCCESS != compare_function(&result, _val, value._val TSRMLS_CC) ) + { + throw Php::Exception("Not comparable"); + return false; + } + return (-1 == result.value.lval); +} + +/** * The type of object * @return Type */ |