diff options
Diffstat (limited to 'tests/cpp/include/class_obj')
-rw-r--r-- | tests/cpp/include/class_obj/001-002.h | 66 | ||||
-rw-r--r-- | tests/cpp/include/class_obj/003-comparable.h | 74 | ||||
-rw-r--r-- | tests/cpp/include/class_obj/004-static-funct.h | 90 | ||||
-rw-r--r-- | tests/cpp/include/class_obj/tpl.h | 25 |
4 files changed, 255 insertions, 0 deletions
diff --git a/tests/cpp/include/class_obj/001-002.h b/tests/cpp/include/class_obj/001-002.h new file mode 100644 index 0000000..2a3b4df --- /dev/null +++ b/tests/cpp/include/class_obj/001-002.h @@ -0,0 +1,66 @@ +/** + * + * Test Classes and objects + * 001.phpt + * 002.phpt + * + */ + + + + +/** + * Set up namespace + */ +namespace TestBaseClass { + + + class MyCustomClass : public Php::Base, public Php::Countable + { + private: + int _x = 3; + + public: + MyCustomClass() + { + std::cerr << "MyCustomClass::MyCustomClass()" << std::endl; + } + + MyCustomClass(int value) : _x(value) + { + std::cerr << "MyCustomClass::MyCustomClass(" << value << ")" << std::endl; + } + + MyCustomClass(const MyCustomClass &that) + { + //std::cerr << "MyCustomClass::MyCustomClass copy constructor" << std::endl; + } + + virtual ~MyCustomClass() + { + std::cerr << "MyCustomClass::~MyCustomClass" << std::endl; + } + + virtual long int count() override + { + return 33; + } + + Php::Value myMethod(Php::Parameters ¶ms) + { + // check number of parameters + //if (params.size() != 1) throw Php::Exception("Invalid number of parameters supplied"); + + Php::out << "myMethod is called for object " << _x << std::endl; + + return 5; + + } + }; + + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/include/class_obj/003-comparable.h b/tests/cpp/include/class_obj/003-comparable.h new file mode 100644 index 0000000..8a384dc --- /dev/null +++ b/tests/cpp/include/class_obj/003-comparable.h @@ -0,0 +1,74 @@ +/** + * + * Test Classes and objects + * 003-comparable.phpt + * + */ + + + + +/** + * Set up namespace + */ +namespace TestBaseClass { + + + /** + * Test custom comparison operator + */ + class Comparable : public Php::Base + { + private: + /** + * Internal value of the class + * @var int + */ + static int count; + int _nom; + int _value; + + public: + /** + * C++ constructor + */ + Comparable() + { + // start with random value + //_value = rand(); + _nom = ++count; + _value = _nom%2+1; + } + + /** + * C++ destructor + */ + virtual ~Comparable() {} + + /** + * Cast the object to a string + * @return std::string + */ + std::string __toString() + { + return "Obj#" + std::to_string(_nom) + "(" + std::to_string(_value) + ")"; + } + + /** + * Compare with a different object + * @param that + * @return int + */ + int __compare(const Comparable &that) const + { + return _value - that._value; + } + }; + int Comparable::count = 0; + + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/include/class_obj/004-static-funct.h b/tests/cpp/include/class_obj/004-static-funct.h new file mode 100644 index 0000000..d6816ab --- /dev/null +++ b/tests/cpp/include/class_obj/004-static-funct.h @@ -0,0 +1,90 @@ +/** + * + * Test Classes and objects + * 004-static-funct.phpt + * test static functions + * + */ + + + + +/** + * Set up namespace + */ +namespace TestBaseClass { + + + /** + * Regular function + * + * Because a regular function does not have a 'this' pointer, + * it has the same signature as static methods + * + * @param params Parameters passed to the function + */ + void testStaticRegFunc(Php::Parameters ¶ms) + { + Php::out << "testStatic regular function"<< std::endl; + } + + /** + * A very simple class that will not be exported to PHP + */ + class testStaticPrivClass + { + public: + /** + * C++ constructor and destructor + */ + testStaticPrivClass() {} + virtual ~testStaticPrivClass() {} + + /** + * Static method + * + * A static method also has no 'this' pointer and has + * therefore a signature identical to regular functions + * + * @param params Parameters passed to the method + */ + static void staticMethod(Php::Parameters ¶ms) + { + Php::out << "testStaticPrivClass::staticMethod()"<< std::endl; + } + }; + + /** + * A very simple class that will be exported to PHP + */ + class testStaticPubClass : public Php::Base + { + public: + /** + * C++ constructor and destructor + */ + testStaticPubClass() {} + virtual ~testStaticPubClass() {} + + /** + * Another static method + * + * This static has exactly the same signature as the + * regular function and static method that were mentioned + * before + * + * @param params Parameters passed to the method + */ + static void staticMethod(Php::Parameters ¶ms) + { + Php::out << "testStaticPubClass::staticMethod()"<< std::endl; + } + }; + + + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/include/class_obj/tpl.h b/tests/cpp/include/class_obj/tpl.h new file mode 100644 index 0000000..7dfdcfc --- /dev/null +++ b/tests/cpp/include/class_obj/tpl.h @@ -0,0 +1,25 @@ +/** + * + * Test Classes and objects + * phptname.phpt + * + */ + + + + +/** + * Set up namespace + */ +namespace TestBaseClass { + + + + + + +/** + * End of namespace + */ +} + |