diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/objecttypeoperators.cpp | 22 | ||||
-rw-r--r-- | tests/libsample/objecttypeoperators.h | 8 | ||||
-rw-r--r-- | tests/samplebinding/objecttypeoperators_test.py | 9 |
3 files changed, 33 insertions, 6 deletions
diff --git a/tests/libsample/objecttypeoperators.cpp b/tests/libsample/objecttypeoperators.cpp index 08c49b1a4..43aedc5de 100644 --- a/tests/libsample/objecttypeoperators.cpp +++ b/tests/libsample/objecttypeoperators.cpp @@ -31,13 +31,27 @@ bool ObjectTypeOperators::operator==(const ObjectTypeOperators& other) const return m_key == other.m_key; } -bool ObjectTypeOperators::operator==(const std::string& other) const +const ObjectTypeOperators& ObjectTypeOperators::operator<(const ObjectTypeOperators& other) const { - return m_key == other; + return m_key < other.m_key ? *this : other; } -const ObjectTypeOperators& ObjectTypeOperators::operator<(const ObjectTypeOperators& other) const +bool operator==(const ObjectTypeOperators* obj, const std::string& str) { - return m_key < other.m_key ? *this : other; + return obj->key() == str; +} + +bool operator==(const std::string& str, const ObjectTypeOperators* obj) +{ + return str == obj->key(); +} + +std::string operator+(const ObjectTypeOperators* obj, const std::string& str) +{ + return obj->key() + str; } +std::string operator+(const std::string& str, const ObjectTypeOperators* obj) +{ + return str + obj->key(); +} diff --git a/tests/libsample/objecttypeoperators.h b/tests/libsample/objecttypeoperators.h index 1d65eb167..9c1a85dc7 100644 --- a/tests/libsample/objecttypeoperators.h +++ b/tests/libsample/objecttypeoperators.h @@ -29,10 +29,9 @@ class LIBSAMPLE_API ObjectTypeOperators { public: - ObjectTypeOperators(const std::string key); + explicit ObjectTypeOperators(const std::string key); bool operator==(const ObjectTypeOperators& other) const; - bool operator==(const std::string& other) const; const ObjectTypeOperators& operator<(const ObjectTypeOperators& other) const; // chaos! @@ -47,4 +46,9 @@ private: ObjectTypeOperators& operator=(ObjectTypeOperators&); }; +LIBSAMPLE_API bool operator==(const ObjectTypeOperators* obj, const std::string& str); +LIBSAMPLE_API bool operator==(const std::string& str, const ObjectTypeOperators* obj); +LIBSAMPLE_API std::string operator+(const ObjectTypeOperators* obj, const std::string& str); +LIBSAMPLE_API std::string operator+(const std::string& str, const ObjectTypeOperators* obj); + #endif // OBJECTTYPEOPERATORS_H diff --git a/tests/samplebinding/objecttypeoperators_test.py b/tests/samplebinding/objecttypeoperators_test.py index d03c9bc48..148bc3591 100644 --- a/tests/samplebinding/objecttypeoperators_test.py +++ b/tests/samplebinding/objecttypeoperators_test.py @@ -39,5 +39,14 @@ class ObjectTypeOperatorsTest(unittest.TestCase): self.assertEqual(None, a > b) self.assertEqual(a.key(), "aoperator>") + def testPointerOpeators(self): + a = ObjectTypeOperators("a") + b = ObjectTypeOperators("b") + self.assertEqual(a + "bc", "abc") + self.assertEqual("bc" + a, "bca") + self.assertEqual("a", a) + self.assertEqual(a, "a") + + if __name__ == '__main__': unittest.main() |