[pygccxml-commit] SF.net SVN: pygccxml: [949] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-03-07 07:49:53
|
Revision: 949
http://svn.sourceforge.net/pygccxml/?rev=949&view=rev
Author: roman_yakovenko
Date: 2007-03-06 23:29:32 -0800 (Tue, 06 Mar 2007)
Log Message:
-----------
adding new unit tests
Added Paths:
-----------
pyplusplus_dev/unittests/bpmodule_tester.py
pyplusplus_dev/unittests/custom_string_tester.py
pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp
Added: pyplusplus_dev/unittests/bpmodule_tester.py
===================================================================
--- pyplusplus_dev/unittests/bpmodule_tester.py (rev 0)
+++ pyplusplus_dev/unittests/bpmodule_tester.py 2007-03-07 07:29:32 UTC (rev 949)
@@ -0,0 +1,32 @@
+# Copyright 2004 Roman Yakovenko.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import os
+import sys
+import unittest
+import fundamental_tester_base
+
+class tester_t(fundamental_tester_base.fundamental_tester_base_t):
+ EXTENSION_NAME = 'bpmodule'
+
+ def __init__( self, *args ):
+ fundamental_tester_base.fundamental_tester_base_t.__init__(
+ self
+ , tester_t.EXTENSION_NAME
+ , *args )
+
+ def run_tests( self, module):
+ pass
+
+def create_suite():
+ suite = unittest.TestSuite()
+ suite.addTest( unittest.makeSuite(tester_t))
+ return suite
+
+def run_suite():
+ unittest.TextTestRunner(verbosity=2).run( create_suite() )
+
+if __name__ == "__main__":
+ run_suite()
Added: pyplusplus_dev/unittests/custom_string_tester.py
===================================================================
--- pyplusplus_dev/unittests/custom_string_tester.py (rev 0)
+++ pyplusplus_dev/unittests/custom_string_tester.py 2007-03-07 07:29:32 UTC (rev 949)
@@ -0,0 +1,83 @@
+# Copyright 2004 Roman Yakovenko.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import os
+import sys
+import unittest
+import fundamental_tester_base
+
+auto_convert_code = \
+"""
+namespace bp = boost::python;
+
+struct PyStringToUTF16{
+
+ typedef custom_strings::utf16_t string_type;
+
+ static void* convertible(PyObject* obj){
+ if( PyString_Check(obj) || PyUnicode_Check(obj) ){
+ return obj;
+ }
+ else{
+ return 0;
+ }
+ }
+
+ static void
+ construct( PyObject* obj, bp::converter::rvalue_from_python_stage1_data* data){
+ typedef bp::converter::rvalue_from_python_storage<string_type> string_storage_t;
+ string_storage_t* the_storage = reinterpret_cast<string_storage_t*>( data );
+ void* memory_chunk = the_storage->storage.bytes;
+
+ bp::object py_str( bp::handle<>( bp::borrowed( obj ) ) );
+ if( PyString_Check(obj) ){
+ std::string c_str = bp::extract<std::string>( py_str );
+ new (memory_chunk) string_type(c_str);
+ }
+ else{ //unicode
+ std::wstring c_str = bp::extract<std::wstring>( py_str );
+ new (memory_chunk) string_type(c_str);
+ }
+ data->convertible = memory_chunk;
+ }
+};
+"""
+
+register_auto_convert_code = \
+"""
+bp::converter::registry::push_back( &PyStringToUTF16::convertible
+ , &PyStringToUTF16::construct
+ , bp::type_id<PyStringToUTF16::string_type>() );
+
+"""
+
+class tester_t(fundamental_tester_base.fundamental_tester_base_t):
+ EXTENSION_NAME = 'custom_string'
+
+ def __init__( self, *args ):
+ fundamental_tester_base.fundamental_tester_base_t.__init__(
+ self
+ , tester_t.EXTENSION_NAME
+ , *args )
+
+ def customize( self, mb ):
+ mb.add_declaration_code( auto_convert_code )
+ mb.add_registration_code( register_auto_convert_code )
+ mb.constructors().allow_implicit_conversion = False
+
+ def run_tests( self, module):
+ self.failUnless( "1" == module.utf16_to_string( "1" ) )
+ self.failUnless( "22" == module.utf16_to_wstring( u"22" ) )
+
+def create_suite():
+ suite = unittest.TestSuite()
+ suite.addTest( unittest.makeSuite(tester_t))
+ return suite
+
+def run_suite():
+ unittest.TextTestRunner(verbosity=2).run( create_suite() )
+
+if __name__ == "__main__":
+ run_suite()
Added: pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp (rev 0)
+++ pyplusplus_dev/unittests/data/custom_string_to_be_exported.hpp 2007-03-07 07:29:32 UTC (rev 949)
@@ -0,0 +1,37 @@
+// Copyright 2004 Roman Yakovenko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef __custom_string_to_be_exported_hpp__
+#define __custom_string_to_be_exported_hpp__
+
+#include <string>
+
+namespace custom_strings{
+
+class utf16_t{
+public:
+ utf16_t() {}
+ explicit utf16_t(std::string const& value) : m_value_a(value) {}
+ explicit utf16_t(std::wstring const& value) : m_value_w(value) {}
+
+ std::string const& value_a() const { return m_value_a; }
+ std::wstring const& value_w() const { return m_value_w; }
+
+private:
+ std::wstring m_value_w;
+ std::string m_value_a;
+};
+
+inline std::string utf16_to_string( const utf16_t& x ){
+ return x.value_a();
+}
+
+inline std::wstring utf16_to_wstring( const utf16_t& x ){
+ return x.value_w();
+}
+
+}
+
+#endif//__custom_string_to_be_exported_hpp__
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|