diff --git a/doc/PyConDC_2003/python_cpp_mix.jpg b/doc/PyConDC_2003/python_cpp_mix.jpg new file mode 100755 index 00000000..755a9605 Binary files /dev/null and b/doc/PyConDC_2003/python_cpp_mix.jpg differ diff --git a/pyste/example/operators.h b/pyste/example/operators.h new file mode 100644 index 00000000..286401a0 --- /dev/null +++ b/pyste/example/operators.h @@ -0,0 +1,43 @@ +#include + +namespace operators { + +struct C +{ + static double x; + double value; + + const C operator+(const C other) const + { + C c; + c.value = value + other.value; + return c; + } + operator int() const + { + return value; + } + + double operator()() + { + return C::x; + } + + double operator()(double other) + { + return C::x + other; + } + + +}; + +double C::x = 10; + +const C operator*(const C& lhs, const C& rhs) +{ + C c; + c.value = lhs.value * rhs.value; + return c; +} + +} diff --git a/pyste/example/operators.pyste b/pyste/example/operators.pyste new file mode 100644 index 00000000..ed0f5083 --- /dev/null +++ b/pyste/example/operators.pyste @@ -0,0 +1 @@ +Class('operators::C', 'operators.h') diff --git a/pyste/example/unions.h b/pyste/example/unions.h new file mode 100644 index 00000000..06287dec --- /dev/null +++ b/pyste/example/unions.h @@ -0,0 +1,16 @@ +namespace unions { + +class UnionTest +{ +public: + union // unions are not supported for now + { + int i; + short s1; + short s2; + } mBad; + + int mGood; +}; + +} diff --git a/pyste/example/unions.pyste b/pyste/example/unions.pyste new file mode 100644 index 00000000..726ab6a2 --- /dev/null +++ b/pyste/example/unions.pyste @@ -0,0 +1,2 @@ +UnionTest = Class('unions::UnionTest', 'unions.h') +exclude(UnionTest.mBad) diff --git a/pyste/tests/build_pyste_nt.bat b/pyste/tests/build_pyste_nt.bat new file mode 100644 index 00000000..7f9d5817 --- /dev/null +++ b/pyste/tests/build_pyste_nt.bat @@ -0,0 +1,19 @@ +@echo off +setlocal +set MODULE_NAME=%1 +set PYSTE_FILE=%2 +set BOOST_ROOT=d:/programming/libraries/boost-cvs +set PYTHON_ROOT=c:/python +set STLPORT_ROOT=d:/programming/libraries/stlport-4.5.3 +set PYSTE_FILE_DIR=%@PATH[%PYSTE_FILE] + +python ../src/pyste.py -I%PYSTE_FILE_DIR --out=%MODULE_NAME.cpp --module=%MODULE_NAME %PYSTE_FILE + +icl /nologo /LD /GR /GX -I%PYSTE_FILE_DIR -I%STLPORT_ROOT/stlport -I%BOOST_ROOT/boost -I%PYTHON_ROOT/include %MODULE_NAME.cpp /link /libpath:%PYTHON_ROOT/libs /libpath:%BOOST_ROOT/lib /libpath:%STLPORT_ROOT/lib boost_python.lib + +rm %MODULE_NAME.cpp +rm %MODULE_NAME.exp +rm %MODULE_NAME.lib +rm %MODULE_NAME.obj + +endlocal diff --git a/pyste/tests/example_basicUT.py b/pyste/tests/example_basicUT.py new file mode 100644 index 00000000..813b4f02 --- /dev/null +++ b/pyste/tests/example_basicUT.py @@ -0,0 +1,27 @@ +import unittest +import os + +class BasicExampleTest(unittest.TestCase): + + def testIt(self): + from basic import C, call_f + + class D(C): + def f(self, x=10): + return x+1 + + d = D() + c = C() + + self.assertEqual(c.f(), 20) + self.assertEqual(c.f(3), 6) + self.assertEqual(d.f(), 11) + self.assertEqual(d.f(3), 4) + self.assertEqual(call_f(c), 20) + self.assertEqual(call_f(c, 4), 8) + self.assertEqual(call_f(d), 11) + self.assertEqual(call_f(d, 3), 4) + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_enumsUT.py b/pyste/tests/example_enumsUT.py new file mode 100644 index 00000000..01e3bdd8 --- /dev/null +++ b/pyste/tests/example_enumsUT.py @@ -0,0 +1,18 @@ +import unittest +from enums import * + +class EnumsTest(unittest.TestCase): + + def testIt(self): + self.assertEqual(int(color.Red), 0) + self.assertEqual(int(color.Blue), 1) + + self.assertEqual(int(X.Choices.Good), 1) + self.assertEqual(int(X.Choices.Bad), 2) + x = X() + self.assertEqual(x.set(x.Choices.Good), 1) + self.assertEqual(x.set(x.Choices.Bad), 2) + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_header_testUT.py b/pyste/tests/example_header_testUT.py new file mode 100644 index 00000000..1f57a9bf --- /dev/null +++ b/pyste/tests/example_header_testUT.py @@ -0,0 +1,15 @@ +import unittest +from header_test import * + +class HeaderTest(unittest.TestCase): + + def testIt(self): + self.assertEqual(choice.red, 0) + self.assertEqual(choice.blue, 1) + self.assertEqual(choice_str(choice.blue), 'blue') + self.assertEqual(choice_str(choice.red), 'red') + c = C() + c.c = choice.blue + self.assertEqual(c.get(), 'blue') + c.c = choice.red + self.assertEqual(c.get(), 'red') diff --git a/pyste/tests/example_nested.py b/pyste/tests/example_nested.py new file mode 100644 index 00000000..7c1685bc --- /dev/null +++ b/pyste/tests/example_nested.py @@ -0,0 +1,15 @@ +import unittest +from nested import * + +class NestedTest(unittest.TestCase): + + def testIt(self): + self.assertEqual(Root.staticXValue, 10) + self.assertEqual(Root.Y.staticYValue, 20) + z = Root.Y.Z() + z.valueZ = 3 + self.assertEqual(z.valueZ, 3) + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_operatorsUT.py b/pyste/tests/example_operatorsUT.py new file mode 100644 index 00000000..345a3a17 --- /dev/null +++ b/pyste/tests/example_operatorsUT.py @@ -0,0 +1,25 @@ +import unittest +from operators import * + +class OperatorTest(unittest.TestCase): + + def testIt(self): + c = C() + c.value = 3.0 + d = C() + d.value = 2.0 + self.assertEqual(c.x, 10) + self.assertEqual(C.x, 10) + self.assertEqual(C.x, 10) + self.assertEqual((c * d).value, 6.0) + self.assertEqual((c + d).value, 5.0) + self.assertEqual(int(c), 3) + self.assertEqual(int(d), 2) + self.assertEqual(c(), 10) + self.assertEqual(d(), 10) + self.assertEqual(c(3.0), 13.0) + self.assertEqual(d(6.0), 16.0) + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_templatesUT.py b/pyste/tests/example_templatesUT.py new file mode 100644 index 00000000..fe897c1b --- /dev/null +++ b/pyste/tests/example_templatesUT.py @@ -0,0 +1,26 @@ +import unittest +from templates import * + +class TemplatesTest(unittest.TestCase): + + def testIt(self): + fp = FPoint() + fp.i = 3.0 + fp.j = 4 + ip = IPoint() + ip.x = 10 + ip.y = 3.0 + + self.assertEqual(fp.i, 3.0) + self.assertEqual(fp.j, 4) + self.assertEqual(ip.x, 10) + self.assertEqual(ip.y, 3.0) + self.assertEqual(type(fp.i), float) + self.assertEqual(type(fp.j), int) + self.assertEqual(type(ip.x), int) + self.assertEqual(type(ip.y), float) + + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_virtual.py b/pyste/tests/example_virtual.py new file mode 100644 index 00000000..66b25c24 --- /dev/null +++ b/pyste/tests/example_virtual.py @@ -0,0 +1,31 @@ +import unittest +from virtual import * + +class VirtualTest(unittest.TestCase): + + def testIt(self): + + class D(C): + def f_abs(self): + return 3 + + class E(C): + def f(self): + return 10 + def name(self): + return 'E' + + d = D() + e = E() + + self.assertEqual(d.f(), 3) + self.assertEqual(call_f(d), 3) + self.assertEqual(e.f(), 10) + self.assertEqual(call_f(e), 10) + self.assertEqual(d.get_name(), 'C') + self.assertEqual(e.get_name(), 'E') + + + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/example_wrappertestUT.py b/pyste/tests/example_wrappertestUT.py new file mode 100644 index 00000000..ebffed2d --- /dev/null +++ b/pyste/tests/example_wrappertestUT.py @@ -0,0 +1,11 @@ +import unittest +from wrappertest import * + +class WrapperTest(unittest.TestCase): + + def testIt(self): + self.assertEqual(Range(10), range(10)) + self.assertEqual(C().Mul(10), [x*10 for x in range(10)]) + +if __name__ == '__main__': + unittest.main() diff --git a/pyste/tests/test_all.bat b/pyste/tests/test_all.bat new file mode 100644 index 00000000..89685f0d --- /dev/null +++ b/pyste/tests/test_all.bat @@ -0,0 +1,20 @@ +@echo off +call build_pyste_nt basic ../example/basic.pyste +call build_pyste_nt enums ../example/enums.pyste +call build_pyste_nt header_test ../example/header_test.pyste +call build_pyste_nt nested ../example/nested.pyste +call build_pyste_nt operators ../example/operators.pyste +call build_pyste_nt templates ../example/templates.pyste +call build_pyste_nt virtual ../example/virtual.pyste +call build_pyste_nt wrappertest ../example/wrappertest.pyste +call build_pyste_nt unions ../example/unions.pyste + + +runtests.py + +if errorlevel != 0 goto end + +rm *.dll +rm *.pyc + +:end