diff --git a/pyste/example/.cvsignore b/pyste/example/.cvsignore new file mode 100644 index 00000000..ce1da4c5 --- /dev/null +++ b/pyste/example/.cvsignore @@ -0,0 +1 @@ +*.cpp diff --git a/pyste/example/basic.h b/pyste/example/basic.h index 5a619e72..a618c192 100644 --- a/pyste/example/basic.h +++ b/pyste/example/basic.h @@ -1,3 +1,5 @@ +namespace basic { + struct C { virtual int f(int x = 10) @@ -19,3 +21,5 @@ int call_f(C& c, int x) { return c.f(x); } + +} diff --git a/pyste/example/basic.pyste b/pyste/example/basic.pyste index a6b4e17b..90978d19 100644 --- a/pyste/example/basic.pyste +++ b/pyste/example/basic.pyste @@ -1,2 +1,2 @@ -Class('C', 'basic.h') -Function('call_f', 'basic.h') +Class('basic::C', 'basic.h') +Function('basic::call_f', 'basic.h') diff --git a/pyste/example/enums.h b/pyste/example/enums.h index 440cefd2..398b66c0 100644 --- a/pyste/example/enums.h +++ b/pyste/example/enums.h @@ -1,4 +1,5 @@ -namespace test { +namespace enums { + enum color { red, blue }; struct X diff --git a/pyste/example/enums.pyste b/pyste/example/enums.pyste index dd9d7fbc..a6cc740a 100644 --- a/pyste/example/enums.pyste +++ b/pyste/example/enums.pyste @@ -1,7 +1,7 @@ -color = Enum('test::color', 'enums.h') +color = Enum('enums::color', 'enums.h') rename(color.red, 'Red') rename(color.blue, 'Blue') -X = Class('test::X', 'enums.h') +X = Class('enums::X', 'enums.h') rename(X.choices.bad, 'Bad') rename(X.choices.good, 'Good') rename(X.choices, 'Choices') diff --git a/pyste/example/header_test.h b/pyste/example/header_test.h index d3d60fcc..85cb5ee0 100644 --- a/pyste/example/header_test.h +++ b/pyste/example/header_test.h @@ -1,23 +1,26 @@ -#include #include #include +namespace header_test { + enum choice { red, blue }; -void print_choice(choice c) +std::string choice_str(choice c) { std::map choice_map; choice_map[red] = "red"; choice_map[blue] = "blue"; - std::cout << "You chose: " << choice_map[c] << std::endl; + return choice_map[c]; } struct C { choice c; - void print_() + std::string get() { - print_choice(c); + return choice_str(c); } }; + +} diff --git a/pyste/example/nested.h b/pyste/example/nested.h index 35804fbb..c4025dd3 100644 --- a/pyste/example/nested.h +++ b/pyste/example/nested.h @@ -1,4 +1,5 @@ - +namespace nested { + struct X { struct Y @@ -19,3 +20,5 @@ int X::staticXValue = 10; int X::Y::staticYValue = 20; typedef X Root; + +} diff --git a/pyste/example/nested.pyste b/pyste/example/nested.pyste index b6291385..48bb26b5 100644 --- a/pyste/example/nested.pyste +++ b/pyste/example/nested.pyste @@ -1 +1 @@ -Class('Root', 'nested.h') +Class('nested::Root', 'nested.h') diff --git a/pyste/example/operator.pyste b/pyste/example/operator.pyste deleted file mode 100644 index ffa5725c..00000000 --- a/pyste/example/operator.pyste +++ /dev/null @@ -1,12 +0,0 @@ -Include('iostream') -test = Wrapper('sum', -''' -const C sum(const C&, const C&) -{ - std::cout << "sum!" << std::endl; - return C(); -} -''' -) -C = Class('C', 'operator.h') -set_wrapper(C.operator['+'], test) diff --git a/pyste/example/operator.h b/pyste/example/operators.h similarity index 74% rename from pyste/example/operator.h rename to pyste/example/operators.h index 5c07549b..286401a0 100644 --- a/pyste/example/operator.h +++ b/pyste/example/operators.h @@ -1,5 +1,6 @@ #include +namespace operators { struct C { @@ -16,14 +17,15 @@ struct C { return value; } + double operator()() { - return x; + return C::x; } double operator()(double other) { - return x + other; + return C::x + other; } @@ -38,10 +40,4 @@ const C operator*(const C& lhs, const C& rhs) return c; } -std::ostream& operator <<( std::ostream& s, const C& c) -{ - std::cout << "here"; - s << "C instance: "; - return s; -} - +} 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/templates.h b/pyste/example/templates.h index de2afe44..6c68fb43 100644 --- a/pyste/example/templates.h +++ b/pyste/example/templates.h @@ -1,4 +1,5 @@ - +namespace templates { + template struct Point { @@ -6,3 +7,4 @@ struct Point Y y; }; +} diff --git a/pyste/example/templates.pyste b/pyste/example/templates.pyste index 30bef79e..ed22c714 100644 --- a/pyste/example/templates.pyste +++ b/pyste/example/templates.pyste @@ -1,8 +1,9 @@ -Point = Template('Point', 'templates.h') +Point = Template('templates::Point', 'templates.h') rename(Point.x, 'i') rename(Point.y, 'j') IPoint = Point('int double') -FPoint = Point('double int') +FPoint = Point('double int', 'FPoint') rename(IPoint, 'IPoint') -rename(IPoint.x, '_x_') +rename(IPoint.x, 'x') +rename(IPoint.y, 'y') 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/example/virtual.h b/pyste/example/virtual.h index e31183b4..17f70361 100644 --- a/pyste/example/virtual.h +++ b/pyste/example/virtual.h @@ -1,4 +1,5 @@ - +namespace virtual_ { + struct C { public: @@ -21,3 +22,4 @@ private: int call_f(C& c) { return c.f(); } +} diff --git a/pyste/example/virtual.pyste b/pyste/example/virtual.pyste index cd9b8669..3fa072f8 100644 --- a/pyste/example/virtual.pyste +++ b/pyste/example/virtual.pyste @@ -1 +1,2 @@ -Class('C', 'virtual.h') +Class('virtual_::C', 'virtual.h') +Function('virtual_::call_f', 'virtual.h') diff --git a/pyste/example/wrappertest.h b/pyste/example/wrappertest.h index a75cddcc..c5ef4f56 100644 --- a/pyste/example/wrappertest.h +++ b/pyste/example/wrappertest.h @@ -4,6 +4,8 @@ #include +namespace wrappertest { + std::vector Range(int count) { std::vector v; @@ -32,4 +34,6 @@ struct C } }; +} #endif + diff --git a/pyste/example/wrappertest.pyste b/pyste/example/wrappertest.pyste index 80c76cda..fd210c7e 100644 --- a/pyste/example/wrappertest.pyste +++ b/pyste/example/wrappertest.pyste @@ -1,15 +1,15 @@ Include('wrappertest_wrappers.h') -f = Function('Range', 'wrappertest.h') +f = Function('wrappertest::Range', 'wrappertest.h') set_wrapper(f, 'RangeWrapper') mul = Wrapper('MulWrapper', ''' -list MulWrapper(C& c, int value){ +list MulWrapper(wrappertest::C& c, int value){ return VectorToList(c.Mul(value)); } ''' ) -C = Class('C', 'wrappertest.h') +C = Class('wrappertest::C', 'wrappertest.h') set_wrapper(C.Mul, mul) diff --git a/pyste/example/wrappertest_wrappers.h b/pyste/example/wrappertest_wrappers.h index a45c3671..42e05d2c 100644 --- a/pyste/example/wrappertest_wrappers.h +++ b/pyste/example/wrappertest_wrappers.h @@ -20,7 +20,7 @@ list VectorToList(const std::vector & v) } list RangeWrapper(int count){ - return VectorToList(Range(count)); + return VectorToList(wrappertest::Range(count)); } #endif 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/runtests.py b/pyste/tests/runtests.py index f670e3d4..28ff57ce 100644 --- a/pyste/tests/runtests.py +++ b/pyste/tests/runtests.py @@ -11,4 +11,5 @@ if __name__ == '__main__': module = __import__(os.path.splitext(name)[0]) tests.append(loader.loadTestsFromModule(module)) runner = unittest.TextTestRunner() - runner.run(unittest.TestSuite(tests)) + result = runner.run(unittest.TestSuite(tests)) + sys.exit(not result.wasSuccessful()) 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