summaryrefslogtreecommitdiff
path: root/tests/cpp
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-28 00:42:09 +0600
committervalmat <ufabiz@gmail.com>2014-03-28 00:42:09 +0600
commit28152192b85cbe9bf5ea08ebe8c706d12e2e13e5 (patch)
treed8a5cbee7e39f6b21c0e698d1ac10ac764b00193 /tests/cpp
parentf56cff9e4f67a949e6f0ae35ca63aaaea16d9a41 (diff)
add test: class_obj/003-comparable.phpt
Diffstat (limited to 'tests/cpp')
-rw-r--r--tests/cpp/include/Classes_and_objects.h (renamed from tests/cpp/include/MyCustomClass.h)62
-rw-r--r--tests/cpp/main.cpp15
2 files changed, 71 insertions, 6 deletions
diff --git a/tests/cpp/include/MyCustomClass.h b/tests/cpp/include/Classes_and_objects.h
index 02ff44b..e9b7434 100644
--- a/tests/cpp/include/MyCustomClass.h
+++ b/tests/cpp/include/Classes_and_objects.h
@@ -1,7 +1,7 @@
/**
*
*
- *
+ * Classes_and_objects.h
*
*/
@@ -12,10 +12,6 @@
namespace TestBaseClass {
-/**
- * Namespace to use
- */
- using namespace std;
class MyCustomClass : public Php::Base, public Php::Countable
{
@@ -61,6 +57,62 @@ namespace TestBaseClass {
};
+ /**
+ * 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/main.cpp b/tests/cpp/main.cpp
index e5150ed..7569a0b 100644
--- a/tests/cpp/main.cpp
+++ b/tests/cpp/main.cpp
@@ -9,7 +9,7 @@
// Test includes
#include "include/ValueIterator.h"
-#include "include/MyCustomClass.h"
+#include "include/Classes_and_objects.h"
#include "include/variables.h"
@@ -33,7 +33,14 @@ extern "C"
// add the interface to the extension
//extension.add(interface);
+
+
+
+ /**
+ * Classes and objects
+ *
+ */
// we are going to define a class
Php::Class<TestBaseClass::MyCustomClass> customClass("TestBaseClass\\MyClass");
@@ -45,6 +52,12 @@ extern "C"
// add the class to the extension
extension.add(customClass);
+ // Comparable
+ extension.add( Php::Class<TestBaseClass::Comparable>("TestBaseClass\\Comparable") );
+
+
+
+
/**
* tests for Iterators
*