summaryrefslogtreecommitdiff
path: root/tests/cpp/include/class_obj
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-28 19:00:17 +0600
committervalmat <ufabiz@gmail.com>2014-03-28 19:00:17 +0600
commit708a22fae15b13db871ca5ffc73004c70f0584fe (patch)
tree639e424f544f8ca5c950803620399c57fceb69bd /tests/cpp/include/class_obj
parent7bc500847e3027bb785c5525a21078ff72acc2ab (diff)
Changed the structure of the test file. With the increasing number of tests the old structure became uncomfortable.
Diffstat (limited to 'tests/cpp/include/class_obj')
-rw-r--r--tests/cpp/include/class_obj/001-002.h66
-rw-r--r--tests/cpp/include/class_obj/003-comparable.h74
-rw-r--r--tests/cpp/include/class_obj/004-static-funct.h90
-rw-r--r--tests/cpp/include/class_obj/tpl.h25
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 &params)
+ {
+ // 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 &params)
+ {
+ 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 &params)
+ {
+ 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 &params)
+ {
+ 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
+ */
+}
+