You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by di...@apache.org on 2009/03/12 01:23:34 UTC
svn commit: r752702 [8/8] - in /incubator/etch/trunk/binding-python: ./
compiler/ compiler/src/main/java/etch/ compiler/src/main/java/etch/bindings/
compiler/src/main/java/etch/bindings/python/
compiler/src/main/java/etch/bindings/python/compiler/ comp...
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_long.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_long.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_long.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,20 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_object.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,65 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+from etch.util.Types import *
+from etch.msg.Validator import *
+from etch.support.Validator_short import *
+from etch.transport.fmt.TypeCode import *
+
+class Test_EtchSupportValidator_short(unittest.TestCase):
+
+ def _test_validator(self):
+ _test = self._test
+
+ # TODO - resolve casting issues in validator tests
+ # TODO - resolve arrays
+ _test(0, "short[0]", TypeCode.SHORT1, Short, Short(Byte.MAX_VALUE), "1")
+ _test(0, "short[0]", TypeCode.SHORT1, Short, Short(Byte.MIN_VALUE), "2" )
+ _test(0, "short[0]", TypeCode.SHORT2, Short, Short(Short.MAX_VALUE), "3" )
+ _test(0, "short[0]", TypeCode.SHORT2, Short, Short(Short.MIN_VALUE), "4" )
+ _test(0, "short[0]", TypeCode.SHORT2, Short, Short(Byte.MAX_VALUE), "5" )
+ _test(0, "short[0]", TypeCode.SHORT2, Short, Short(Byte.MIN_VALUE), "abc" )
+ _test(1, "short[1]", TypeCode.ARRAY, [Short], [], 1)
+ _test(2, "short[2]", TypeCode.ARRAY, [[Short]], [[]], [] )
+ _test(3, "short[3]", TypeCode.ARRAY, [[[Short]]], [[[]]], [[]] )
+ _test(4, "short[4]", TypeCode.ARRAY, [[[[Short]]]], [[[[]]]], [[[]]] )
+ _test(5, "short[5]", TypeCode.ARRAY, [[[[[Short]]]]], [[[[[]]]]], [[[[]]]] )
+
+ def test_getNeg1(self):
+ self.assertRaises(IllegalArgumentException, Validator_short.get, -1)
+
+ def test_getNeg2(self):
+ self.assertRaises(IllegalArgumentException, Validator_short.get(0).elementValidator)
+
+ def test_getMaxPlusOne(self):
+ self.assertRaises(IllegalArgumentException, Validator_short.get, Validator.MAX_NDIMS + 1)
+
+ def _test(self, n, s, tc, clss, good, bad):
+ v = Validator_short.get(n)
+ self.assertEqual(n, v.getNDims())
+ self.assertEqual(clss, v.getExpectedClass())
+ self.assertEqual(s, repr(v))
+ self.assertEqual(True, v.validate(good))
+ self.assertEqual(False, v.validate(bad))
+ self.assertEqual(tc, v.checkValue(good))
+ self.assertEqual(None, v.checkValue(bad))
+ if n > 0:
+ self.assertEqual(n-1, v.elementValidator().getNDims())
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_short.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,21 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_string.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,21 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidator_void.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,142 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+from etch.util.Types import *
+from etch.msg.Validator import *
+from etch.support.Validator_boolean import *
+from etch.support.Validator_int import *
+from etch.support.Validator_short import *
+from etch.support.Validator_byte import *
+from etch.support.Validator_string import *
+from etch.transport.fmt.TypeCode import *
+
+class Test_EtchSupportValidators(unittest.TestCase):
+
+ def test_boolean(self):
+ _test = self._test
+
+ # Check list
+ _test(Validator_boolean.get(2), 2, [TypeCode.BOOLEAN_FALSE, TypeCode.BOOLS, TypeCode.ARRAY], [[False, False], [False, False]])
+ _test(Validator_boolean.get(2), 2, [TypeCode.BOOLEAN_TRUE, TypeCode.BOOLS, TypeCode.ARRAY], [[True, True], [True,True]])
+
+ # Check tuple
+ _test(Validator_boolean.get(2), 2, [TypeCode.BOOLEAN_FALSE, TypeCode.BOOLS, TypeCode.ARRAY], ((False, False), (False, False)))
+ _test(Validator_boolean.get(2), 2, [TypeCode.BOOLEAN_TRUE, TypeCode.BOOLS, TypeCode.ARRAY], ((True, True), (True,True)))
+
+ def test_byte(self):
+ _test = self._test
+
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[-1,-1],[1,1]])
+
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[Byte(0),Byte(0)],[Byte(0),Byte(0)]])
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[Byte(1),Byte(1)],[Byte(1),Byte(1)]])
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[Byte(-1),Byte(-1)],[Byte(1),Byte(1)]])
+
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[Byte.MAX_VALUE, Byte.MAX_VALUE],[Byte.MAX_VALUE,Byte.MAX_VALUE]])
+ _test(Validator_byte.get(2), 2, [TypeCode.BYTE, TypeCode.BYTES, TypeCode.ARRAY], [[Byte.MIN_VALUE, Byte.MIN_VALUE],[Byte.MIN_VALUE,Byte.MIN_VALUE]])
+
+ def test_short(self):
+ _test = self._test
+
+ _test(Validator_short.get(2), 2, [TypeCode.BYTE, TypeCode.SHORTS, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_short.get(2), 2, [TypeCode.BYTE, TypeCode.SHORTS, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_short.get(2), 2, [TypeCode.BYTE, TypeCode.SHORTS, TypeCode.ARRAY], [[-1,-1],[-1,-1]])
+
+ _test(Validator_short.get(2), 2, [TypeCode.BYTE, TypeCode.SHORTS, TypeCode.ARRAY], [[Byte.MAX_VALUE, Byte.MAX_VALUE],[Byte.MAX_VALUE, Byte.MAX_VALUE]])
+ _test(Validator_short.get(2), 2, [TypeCode.BYTE, TypeCode.SHORTS, TypeCode.ARRAY], [[Byte.MIN_VALUE, Byte.MIN_VALUE],[Byte.MIN_VALUE, Byte.MIN_VALUE]])
+
+ _test(Validator_short.get(2), 2, [TypeCode.SHORT, TypeCode.SHORTS, TypeCode.ARRAY], [[Short.MAX_VALUE, Short.MAX_VALUE],[Short.MAX_VALUE, Short.MAX_VALUE]])
+ _test(Validator_short.get(2), 2, [TypeCode.SHORT, TypeCode.SHORTS, TypeCode.ARRAY], [[Short.MIN_VALUE, Short.MIN_VALUE],[Short.MIN_VALUE, Short.MIN_VALUE]])
+
+ def test_int(self):
+ _test = self._test
+
+ _test(Validator_int.get(2), 2, [TypeCode.BYTE, TypeCode.INTS, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_int.get(2), 2, [TypeCode.BYTE, TypeCode.INTS, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_int.get(2), 2, [TypeCode.BYTE, TypeCode.INTS, TypeCode.ARRAY], [[-1,-1],[-1,-1]])
+
+ _test(Validator_int.get(2), 2, [TypeCode.BYTE, TypeCode.INTS, TypeCode.ARRAY], [[Byte.MAX_VALUE, Byte.MAX_VALUE],[Byte.MAX_VALUE, Byte.MAX_VALUE]])
+ _test(Validator_int.get(2), 2, [TypeCode.BYTE, TypeCode.INTS, TypeCode.ARRAY], [[Byte.MIN_VALUE, Byte.MIN_VALUE],[Byte.MIN_VALUE, Byte.MIN_VALUE]])
+
+ _test(Validator_int.get(2), 2, [TypeCode.SHORT, TypeCode.INTS, TypeCode.ARRAY], [[Short.MAX_VALUE, Short.MAX_VALUE],[Short.MAX_VALUE, Short.MAX_VALUE]])
+ _test(Validator_int.get(2), 2, [TypeCode.SHORT, TypeCode.INTS, TypeCode.ARRAY], [[Short.MIN_VALUE, Short.MIN_VALUE],[Short.MIN_VALUE, Short.MIN_VALUE]])
+
+ _test(Validator_int.get(2), 2, [TypeCode.INT, TypeCode.INTS, TypeCode.ARRAY], [[Integer.MAX_VALUE, Integer.MAX_VALUE],[Integer.MAX_VALUE, Integer.MAX_VALUE]])
+ _test(Validator_int.get(2), 2, [TypeCode.INT, TypeCode.INTS, TypeCode.ARRAY], [[Integer.MIN_VALUE, Integer.MIN_VALUE],[Integer.MIN_VALUE, Integer.MIN_VALUE]])
+
+ def test_long(self):
+ _test = self._test
+
+ _test(Validator_long.get(2), 2, [TypeCode.BYTE, TypeCode.LONGS, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_long.get(2), 2, [TypeCode.BYTE, TypeCode.LONGS, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_long.get(2), 2, [TypeCode.BYTE, TypeCode.LONGS, TypeCode.ARRAY], [[-1,-1],[-1,-1]])
+
+ _test(Validator_long.get(2), 2, [TypeCode.BYTE, TypeCode.LONGS, TypeCode.ARRAY], [[Byte.MAX_VALUE, Byte.MAX_VALUE],[Byte.MAX_VALUE, Byte.MAX_VALUE]])
+ _test(Validator_long.get(2), 2, [TypeCode.BYTE, TypeCode.LONGS, TypeCode.ARRAY], [[Byte.MIN_VALUE, Byte.MIN_VALUE],[Byte.MIN_VALUE, Byte.MIN_VALUE]])
+
+ _test(Validator_long.get(2), 2, [TypeCode.SHORT, TypeCode.LONGS, TypeCode.ARRAY], [[Short.MAX_VALUE, Short.MAX_VALUE],[Short.MAX_VALUE, Short.MAX_VALUE]])
+ _test(Validator_long.get(2), 2, [TypeCode.SHORT, TypeCode.LONGS, TypeCode.ARRAY], [[Short.MIN_VALUE, Short.MIN_VALUE],[Short.MIN_VALUE, Short.MIN_VALUE]])
+
+ _test(Validator_long.get(2), 2, [TypeCode.INT, TypeCode.LONGS, TypeCode.ARRAY], [[Integer.MAX_VALUE, Integer.MAX_VALUE],[Integer.MAX_VALUE, Integer.MAX_VALUE]])
+ _test(Validator_long.get(2), 2, [TypeCode.INT, TypeCode.LONGS, TypeCode.ARRAY], [[Integer.MIN_VALUE, Integer.MIN_VALUE],[Integer.MIN_VALUE, Integer.MIN_VALUE]])
+
+ _test(Validator_long.get(2), 2, [TypeCode.INT, TypeCode.LONGS, TypeCode.ARRAY], [[Long.MAX_VALUE, Long.MAX_VALUE],[Long.MAX_VALUE, Long.MAX_VALUE]])
+ _test(Validator_long.get(2), 2, [TypeCode.INT, TypeCode.LONGS, TypeCode.ARRAY], [[Long.MIN_VALUE, Long.MIN_VALUE],[Long.MIN_VALUE, Long.MIN_VALUE]])
+
+ def test_float(self):
+ _test = self._test
+
+ _test(Validator_float.get(2), 2, [TypeCode.FLOAT, TypeCode.FLOATS, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_float.get(2), 2, [TypeCode.FLOAT, TypeCode.FLOATS, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_float.get(2), 2, [TypeCode.FLOAT, TypeCode.FLOATS, TypeCode.ARRAY], [[-1,-1],[-1,-1]])
+ _test(Validator_float.get(2), 2, [TypeCode.FLOAT, TypeCode.FLOATS, TypeCode.ARRAY], [[Float.MAX_VALUE, Float.MAX_VALUE],[Float.MAX_VALUE, Float.MAX_VALUE]])
+ _test(Validator_float.get(2), 2, [TypeCode.FLOAT, TypeCode.FLOATS, TypeCode.ARRAY], [[Float.MIN_VALUE, Float.MIN_VALUE],[Float.MIN_VALUE, Float.MIN_VALUE]])
+
+ def test_double(self):
+ _test = self._test
+
+ _test(Validator_double.get(2), 2, [TypeCode.DOUBLE, TypeCode.DOUBLES, TypeCode.ARRAY], [[0,0],[0,0]])
+ _test(Validator_double.get(2), 2, [TypeCode.DOUBLE, TypeCode.DOUBLES, TypeCode.ARRAY], [[1,1],[1,1]])
+ _test(Validator_double.get(2), 2, [TypeCode.DOUBLE, TypeCode.DOUBLES, TypeCode.ARRAY], [[-1,-1],[-1,-1]])
+ _test(Validator_double.get(2), 2, [TypeCode.DOUBLE, TypeCode.DOUBLES, TypeCode.ARRAY], [[Double.MAX_VALUE, Double.MAX_VALUE],[Double.MAX_VALUE, Double.MAX_VALUE]])
+ _test(Validator_double.get(2), 2, [TypeCode.DOUBLE, TypeCode.DOUBLES, TypeCode.ARRAY], [[Double.MIN_VALUE, Double.MIN_VALUE],[Double.MIN_VALUE, Double.MIN_VALUE]])
+
+ def test_string(self):
+ _test = self._test
+
+ _test(Validator_string.get(2), 2, [TypeCode.EMPTY_STRING, TypeCode.ARRAY, TypeCode.ARRAY], [["",""],["",""]])
+ _test(Validator_string.get(2), 2, [TypeCode.STRING, TypeCode.ARRAY, TypeCode.ARRAY], [["abc","abc"], ["abc","abc"]])
+
+ def test_custom(self):
+ _test = self._test
+
+ _test(Validator_custom.get( Date, 2), 2, [TypeCode.CUSTOM, TypeCode.ARRAY, TypeCode.ARRAY], [[Date(), Date()], [Date(),Date()]])
+
+
+ def _test(self, v, n, tcs, o):
+ self.assertEqual(True, v.validate(o))
+ self.assertEqual(tcs[n], v.checkValue(o))
+
+ if n > 0:
+ for k in o:
+ self._test(v.elementValidator(), n-1, tcs, k)
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/TestValidators.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/support/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,39 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+from etch.util.Types import *
+from etch.msg.Type import *
+
+# TODO - finish this
+
+class Test_EtchTransportArrayValue(unittest.TestCase):
+
+ def test_constructor1(self):
+ av = ArrayValue(0)
+ self.assertEqual(0, av.typeCode())
+ self.assertEqual(None, av.customStructType())
+ self.assertEqual(0, av.dim())
+
+ def test_constructor2(self):
+ t1 = Type("t1")
+ av = ArrayValue(0, 1, t1, 2)
+ self.assertEqual(1, av.typeCode())
+ self.assertEqual(t1, av.customStructType())
+ self.assertEqual(2, av.dim())
+
+if __name__ == '__main__':
+ unittest.main()
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestArrayValue.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,21 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMailboxManager.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,22 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
+
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestMessagizer.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,21 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+
+if __name__ == '__main__':
+ unittest.main()
+
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/TestPlainMailbox.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,394 @@
+"""
+tests.transport.fmt.binary.TestBinaryTaggedDataInOut
+
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+import time
+
+from etch.transport.fmt.binary.BinaryTaggedDataOutput import BinaryTaggedDataOutput
+from etch.support.DefaultValueFactory import DefaultValueFactory
+from etch.support.TypeMap import TypeMap
+from etch.support.Class2TypeMap import Class2TypeMap
+from etch.msg.Type import Type
+from etch.util.Types import *
+from etch.util.PacketSource import PacketSource
+
+class TestBinaryTaggedDataInOut(unittest.TestCase):
+ DOUBLE_MIN_NORMAL = "0x1.0p-1022"
+ FLOAT_MIN_NORMAL = "0x1.0p-126f"
+
+ def setUp(self):
+ print "\n"
+ print "TestBinaryTaggedDataInOut.setUp"
+ self.__vf = ValueFactoryFake()
+ self.__mt_foo = self.__vf.getType("foo")
+ self.__mf_x = Field("x")
+
+ def test_check_value(self):
+ btdo = BinaryTaggedDataOutput ( None, None )
+
+ # positive small bytes
+ self.assertEquals(0,btdo.checkValue(Byte(0)))
+ self.assertEquals(1,btdo.checkValue(Byte(1)))
+ self.assertEquals(31,btdo.checkValue(Byte(31)))
+
+ # positive small shorts
+ self.assertEquals(32,btdo.checkValue(Short(0)))
+ self.assertEquals(33,btdo.checkValue(Short(1)))
+ self.assertEquals(63,btdo.checkValue(Short(31)))
+
+ # positive small ints
+ self.assertEquals(64, btdo.checkValue(0))
+ self.assertEquals(65, btdo.checkValue(1))
+ self.assertEquals(95, btdo.checkValue(31))
+
+ # positive small longs
+ self.assertEquals(96, btdo.checkValue(0L))
+ self.assertEquals(97, btdo.checkValue(1L))
+ self.assertEquals(127, btdo.checkValue(31L))
+
+ # negative small bytes
+ self.assertEquals(-128, btdo.checkValue(Byte(-1)))
+ self.assertEquals(-127, btdo.checkValue(Byte(-2)))
+ self.assertEquals(-113, btdo.checkValue(Byte(-16)))
+
+ # negative small shorts
+ self.assertEquals(-112, btdo.checkValue(Short(-1)))
+ self.assertEquals(-111, btdo.checkValue(Short(-2)))
+ self.assertEquals(-97, btdo.checkValue(Short(-16)))
+
+ # negative small ints
+ self.assertEquals(-96, btdo.checkValue(-1))
+ self.assertEquals(-79, btdo.checkValue(-2))
+ self.assertEquals(-65, btdo.checkValue(-16))
+
+ # negative small longs
+ self.assertEquals(-80, btdo.checkValue(-1L))
+ self.assertEquals(-79, btdo.checkValue(-2L))
+ self.assertEquals(-65, btdo.checkValue(-16L))
+
+ # null value
+ self.assertEquals(-1, btdo.checkValue(None))
+
+ # boolean values
+ self.assertEquals(-2, btdo.checkValues(False))
+ self.assertEquals(-3, btdo.checkValues(True))
+
+ # normal bytes
+ self.assertEquals(-4, btdo.checkValue(Byte(-45)))
+ self.assertEquals(-4, btdo.checkValue(Byte(45)))
+
+ # normal shorts
+ self.assertEquals(-5, btdo.checkValue(Short(-45)))
+ self.assertEquals(-5, btdo.checkValue(Short(45)))
+
+ self.assertEquals(-6, btdo.checkValue(Short(-4545)))
+ self.assertEquals(-6, btdo.checkValue(Short(4545)))
+
+ # normal ints
+ self.assertEquals(-7, btdo.checkValues(-45))
+ self.assertEquals(-7, btdo.checkValue(45))
+
+ self.assertEquals(-8, btdo.checkValue(-4545))
+ self.assertEquals(-8, btdo.checkValue(4545))
+
+ self.assertEquals(-9, btdo.checkValue(-45454545))
+ self.assertEquals(-9, btdo.checkValue(45454545))
+
+ # normal longs
+ self.assertEquals(-10, btdo.checkValues(-45L))
+ self.assertEquals(-10, btdo.checkValue(45L))
+
+ self.assertEquals(-11, btdo.checkValue(-4545L))
+ self.assertEquals(-11, btdo.checkValue(4545L))
+
+ self.assertEquals(-12, btdo.checkValue(-45454545L))
+ self.assertEquals(-12, btdo.checkValue(45454545L))
+
+ self.assertEquals(-12, btdo.checkValue(-4545454545454545L))
+ self.assertEquals(-12, btdo.checkValue(4545454545454545L))
+
+ # float
+ self.assertEquals(-14, btdo.checkValue(Float(3.14159)))
+
+ # double
+ self.assertEquals(-15, btdo.checkValue(3.14159))
+
+ # byte array
+ self.assertEquals(-16, btdo.checkValue(ByteArray(0)))
+ self.assertEquals(-16, btdo.checkValue(ByteArray(1)))
+
+ # empty string
+ self.assertEquals(-17, btdo.checkValue(""))
+ self.assertEquals(-17, btdo.checkValue(''))
+ self.assertEquals(-17, btdo.checkValue(u''))
+ self.assertEquals(-17, btdo.checkValue(""""""))
+
+ # short string
+ self.assertEquals(-18, btdo.checkValue("a"))
+ self.assertEquals(-18, btdo.checkValue('a'))
+
+ # non-empty string
+ self.assertEquals(-18, btdo.checkValue("abc"))
+ self.assertEquals(-18, btdo.checkValue('abc'))
+ self.assertEquals(-18, btdo.checkValue(u"abc"))
+
+ # struct
+ self.assertEquals(-19, btdo.checkValue(StructValue(Type("foo"))))
+
+ # custom
+ self.assertEquals(-21, btdo.checkValue(Date()))
+
+ # none
+ self.assertEquals(-22, btdo.checkValue(BinaryTaggedData.NONE))
+
+ def xxtest_boolean(self):
+ self._testx( ((False, True), (True, False)), Validator_boolean.get(2) )
+
+ def xxtest_byte(self):
+ self._testx( ((Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE), (23,)), Validator_byte.get(2) )
+
+ def xxtest_short(self):
+ self._testx( ((Short.MIN_VALUE, Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE, Short.MAX_VALUE), (23,)), Validator_short.get(2) )
+
+ def xxtest_int(self):
+ self._testx( ((Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE), (23,)), Validator_int.get(2))
+
+ def xxtest_long(self):
+ self._testx( ((Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, -1, 0, 1, Byte.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE), (23,)), Validator_long(2))
+
+ def xxtest_float(self):
+ self._testx( ((-1, 0, 1, Float.MIN_VALUE, TestBinaryTaggedDataInOut.FLOAT_MIN_NORMAL, Float.MAX_VALUE, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, -0.0, 1.1, 3.141592653589793238462643383279), (23,)), Validator_float.get(2))
+
+ def xxtest_double(self):
+ self._testx( ((-1, 0, 1, Double.MIN_VALUE, TestBinaryTaggedDataInOut.DOUBLE_MIN_NORMAL, Double.MAX_VALUE, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, -0.0, 1.1, 3.141592653589793238462643383279), (23,)), Validator_double.get(2))
+
+ def xxtest_string(self):
+ self._testx( (('', "", 'a', "a", 'ab', "ab", 'abc', "abc"), (23,)), Validator_string.get(2))
+
+ def __add_setup(self):
+ add = self.__vf.getType("add")
+
+ x = Field("x")
+ add.putValidator(x, Validator_int.get(0))
+
+ y = Field("y")
+ add.putValidator(y, Validator_int.get(0))
+
+ _mf__messageId = DefaultValueFactory._mf__messageId
+ add.putValidator(_mf__messageId, Validator_long.get(0))
+
+ msgid = 0x0123456789abcdefL
+
+ return (add,x,y,_mf__messageId, msgid)
+
+ def xxtest_add(self):
+ (add,x,y,_mf__messageId,msgid) = self.__add_setup()
+
+ msg = Message(add, self.__vf)
+ msg.put(x, 1)
+ msg.put(y, 2)
+ msg.put(_mf__messageId, msgid)
+
+ msg = Message(add, self.__vf)
+ msg.put(x, 1000000000)
+ msg.put(y, 2000000000)
+ msg.put( _mf__messageId, msgid)
+
+ def xxtest_add_in(self):
+ (add,x,y,_mf__messageId,msgid) = self.__add_setup()
+
+ buf = ByteArray([
+ 1, # version
+ -9, # INT4
+ 39, -23, -73, -100, # add
+ -9, # INT4
+ 99, 6, -76, 104,
+ -13, # LONG8
+ 1, 35, 69, 103, -119, -85, -51, -17,
+ -9, # INT4
+ 21, 10, 44, -76, # y
+ 66, # INT4=2
+ -9, # INT4
+ 21, 10, 44, -77, # x
+ 65, # INT4=1
+ -22, # NONE
+ ])
+ msg = self.bytes2msg(buf)
+ msg.checkType(add)
+
+ self.assertEquals(3, msg.size())
+ self.assertEquals(1, msg.get(x))
+ self.assertEquals(2, msg.get(y))
+ self.assertEquals(msgid, msg.get(_mf__messageId))
+
+ buf = ByteArray([])
+ msg = self.bytes2msg(buf)
+ msg.checkType(add)
+ self.assertEquals(3, msg.size())
+ self.assertEquals(1000000000, msg.get(x))
+ self.assertEquals(2000000000, msg.get(y))
+ self.assertEquals(msgid, msg.get(_mf__messageId))
+
+ def xxtest_add_perf(self):
+ (add,x,y,_mf__messageId,msgid) = self.__add_setup()
+
+ msg = Message(add, self.__vf)
+ msg.put(x, 123456789)
+ msg.put(y, 876543210)
+ msg.put(_mf__messageId, msgid)
+
+ m = Messagizer(None, self.__vf)
+ ps = MyPacketSource()
+ m.setSource(ps)
+ m.messagex(None, msg)
+
+ n = 900973
+ for i in range(0,3):
+ testPerf("test_add_perf", i, m, msg, n)
+
+ def xxtest_sum_perf(self):
+ sum = self.__vf.getType("sum")
+
+ values = Field("values")
+ sum.putValidator(values, Validator_int.get(1))
+
+ _mf__messageId = DefaultValueFactory._mf__messageId
+ sum.putValidator(_mf__messageId, Validator_long.get(0))
+
+ msgid = 0x0123456789abcdefL
+
+ arr = [None, None]
+ for i in range(0,len(arr)):
+ arr[i] = 123456789
+
+ msg = Message(sum, self.__vf)
+ msg.put(values, arr)
+ msg.put(_mf__messageId, msgid)
+
+ m = Messagizer(None, self.__vf)
+ ps = MyPacketSource()
+ m.setSource(ps)
+ m.messagex(None, msg)
+
+ n = 509520
+ for i in range(0,3):
+ testPerf("test_sum_perf", i, m, msg, n)
+
+ @staticmethod
+ def xxtestPerf(name, iter, m, msg, n):
+ t0 = time.time()
+
+ for i in range(0,n):
+ m.messagex(None, msg)
+
+ t1 = time.time()
+ t = (t1-t0)
+ r = n / t
+ Log.report(name, "iteration", iter, "time", t, "count", n, "rate", r)
+
+ def msg2bytes(self, msg):
+ buf = FlexBuffer()
+ btdo = BinaryTaggedDataOutput(buf, self.__vf)
+ btdo.writeMessage(msg)
+ buf.setIndex(0)
+ return buf.getAvailBytes()
+
+ def bytes2msg(self, buf):
+ return BinaryTaggedDataInput.readMessage(self.__vf, FlexBuffer(buf))
+
+ def _testx(self, x, v):
+ if isinstance(x, ([],())):
+ for i in x:
+ self._testx(i,v.elementValidator())
+ y = self._test(x, v)
+ self.localAssertEquals(x,y)
+
+ def _test(self, x, v):
+ mt_foo = self.__mt_foo
+ mf_x = self.__mf_x
+ vf = self.__vf
+
+ mt_foo.clearValidator(mf_x)
+ mt_foo.putValidator(mf_x, v)
+
+ msg = Message(mt_foo, vf)
+ msg.put(mf_x, x)
+
+ bufx = self.msg2bytes(msg)
+ msg2 = self.bytes2msg(bufx)
+
+ msg2.checkType(mt_foo)
+ self.assertEquals(1, msg2.size())
+ msg.containsKey(mf_x)
+ return msg2.get(mf_x)
+
+ def localAssertEquals(self, a, b):
+ if not a or not b:
+ self.assertEquals(a,b)
+ return
+
+ if a.__class__ == b.__class__:
+ if isinstance(a, types.ArrayType) and isinstance(b, types.ArrayType):
+ self.localAssertArrayEquals(a,b)
+ else:
+ self.assertEquals(a,b)
+ else:
+ self.assertEquals(a,b)
+
+ def localAssertArrayEquals(self, a, b):
+ an = len(a)
+ bn = len(b)
+
+ self.localAssertEquals(an, bn)
+
+ for i in range(0,an):
+ self.localAssertEquals(a[i], b[i])
+
+class ValueFactoryFake(DefaultValueFactory):
+ typs = TypeMap()
+ class2type = Class2TypeMap()
+ DefaultValueFactory.init(typs, class2type)
+
+ def __init__(self):
+ super(ValueFactoryFake,self).__init__(self.typs, self.class2type)
+
+class MyPacketSource(PacketSource):
+
+ def headerSize(self):
+ return 0
+
+ def packet(self, recipient, buf):
+ pass
+
+ def getHandler(self):
+ return None
+
+ def setHandler(self, handler):
+ pass
+
+ def transportControl(self, control, value):
+ pass
+
+ def transportNotify(self, event):
+ pass
+
+ def transportQuery(self, query):
+ return None
+
+if __name__=='__main__':
+ unittest.main()
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/TestBinaryTaggedDataInOut.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/binary/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/transport/fmt/xml/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,841 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+from etch.util.Types import *
+from etch.util.Exceptions import *
+from etch.util.FlexBuffer import *
+
+class Test_EtchUtilFlexBuffer(unittest.TestCase):
+
+ def setUp(self):
+ self.buf = FlexBuffer()
+
+ def _checkBuf(self, length, index, avail):
+ self.assertEqual(length, self.buf.length(), "Length")
+ self.assertEqual(index, self.buf.index(), "Index")
+ self.assertEqual(avail, self.buf.avail(), "Avail")
+
+ def test_initial1(self):
+ self._checkBuf(0, 0, 0)
+
+ def test_initial2(self):
+ self.buf = FlexBuffer(ByteArray(5))
+ self._checkBuf(5, 0, 5)
+
+ def test_initial3(self):
+ self.buf = FlexBuffer(ByteArray(5), 2)
+ self._checkBuf(2, 0, 2)
+
+ def test_initial4(self):
+ self.buf = FlexBuffer(ByteArray(5), 1, 3)
+ self._checkBuf(4, 1, 3)
+
+ def test_setLength0(self):
+ self.buf.setLength(0)
+ self._checkBuf(0, 0, 0)
+
+ def test_setLength1(self):
+ self.buf.setLength(1)
+ self._checkBuf(1, 0, 1)
+
+ def test_setLength2(self):
+ self.buf.setLength(2)
+ self._checkBuf(2, 0, 2)
+
+ def test_setLength3(self):
+ self.buf.setLength(2)
+ self.buf.setLength(0)
+ self._checkBuf(0, 0, 0)
+
+ def test_setLength4(self):
+ self.assertRaises(IllegalArgumentException, self.buf.setLength, -1)
+
+ def test_setIndex0(self):
+ self.buf.setIndex(0)
+ self._checkBuf(0, 0, 0)
+
+ def test_setIndex1(self):
+ self.assertRaises(IllegalArgumentException, self.buf.setIndex, 1)
+
+ def test_setIndex2(self):
+ self.assertRaises(IllegalArgumentException, self.buf.setIndex, -1)
+
+ def test_setIndex3(self):
+ self.buf.setLength(5)
+ self.buf.setIndex(1)
+ self._checkBuf(5, 1, 4)
+
+ def test_setIndex4(self):
+ self.buf.setLength(5)
+ self.buf.setIndex(4)
+ self._checkBuf(5, 4, 1)
+
+ def test_setIndex5(self):
+ self.buf.setLength(5)
+ self.buf.setIndex(5)
+ self._checkBuf(5, 5, 0)
+
+ def test_setIndex5(self):
+ self.buf.setLength(5)
+ self.buf.setIndex(5)
+ self.buf.setLength(0)
+ self._checkBuf(0, 0, 0)
+
+ def test_setIndex7(self):
+ self.buf.setLength(5)
+ self.buf.setIndex(5)
+ self.buf.setLength(2)
+ self._checkBuf(2, 2, 0)
+
+ def test_reset(self):
+ self.buf.setLength(2)
+ self.buf.setIndex(1)
+ self.buf.reset()
+ self._checkBuf(0, 0, 0)
+
+ def test_put1a(self):
+ self.buf.put(1)
+ self._checkBuf(1, 1, 0)
+
+ def test_put1b(self):
+ self.buf.put(1)
+ self.buf.put(2)
+ self._checkBuf(2, 2, 0)
+
+ def _testPutBytes(self, bufLength):
+ self.buf.put(1)
+ if bufLength >= 0:
+ self.buf.put(ByteArray(bufLength))
+ else:
+ self.buf.put(None)
+ self._checkBuf(bufLength+1, bufLength+1, 0)
+
+ def test_put2a(self):
+ self.assertRaises(NullPointerException, self._testPutBytes, -1)
+
+ def test_put2b(self):
+ self._testPutBytes(0)
+
+ def test_put2c(self):
+ self._testPutBytes(1)
+
+ def test_put2d(self):
+ self._testPutBytes(2)
+
+ #// ------------------------------------------------------
+ #// cases for put( byte[] buf, int off, int len ):
+ #// buf.length, off, len // failure reason
+ #// --- group 3:
+ #// null, 0, 0 // fail (buf is null)
+ #// null, 0, 1 // fail (buf is null)
+ #// null, 1, 0 // fail (buf is null)
+ #// --- group 4:
+ #// 0, 0, 0
+ #// 0, 0, 1 // fail (off+len > buf.length)
+ #// 0, 1, 0 // fail (off > buf.length)
+ #// --- group 5:
+ #// 1, 0, 0
+ #// 1, 0, 1
+ #// 1, 0, 2 // fail (off+len > buf.length)
+ #// 1, 1, 0
+ #// 1, 1, 1 // fail (off+len > buf.length)
+ #// 1, 1, 2 // fail (off+len > buf.length)
+ #// 1, 2, 0 // fail (off > buf.length)
+ #// 1, 2, 1 // fail (off > buf.length)
+ #// 1, 2, 2 // fail (off > buf.length)
+ #// --- group 6:
+ #// 2, 0, 0
+ #// 2, 0, 1
+ #// 2, 0, 2
+ #// 2, 1, 0
+ #// 2, 1, 1
+ #// 2, 1, 2 // fail (off+len > buf.length)
+ #// 2, 2, 0
+ #// 2, 2, 1 // fail (off+len > buf.length)
+ #// 2, 2, 2 // fail (off+len > buf.length)
+
+ def _testPutBytesOffLen(self, bufLength, offset, length):
+ self.buf.put(1)
+ if bufLength >= 0:
+ self.buf.put(ByteArray(bufLength), offset, length)
+ else:
+ self.buf.put(None, offset, length)
+ self._checkBuf(length+1, length+1, 0)
+
+ def test_put3a(self):
+ self.assertRaises(NullPointerException, self._testPutBytesOffLen, -1, 0, 0)
+
+ def test_put3b(self):
+ self.assertRaises(NullPointerException, self._testPutBytesOffLen, -1, 0, 0)
+
+ def test_put3c(self):
+ self.assertRaises(NullPointerException, self._testPutBytesOffLen, -1, 1, 0)
+
+ def test_put4a(self):
+ self._testPutBytesOffLen(0, 0, 0)
+
+ def test_put4b(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 0, 0, 1)
+
+ def test_put4c(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 0, 1, 0)
+
+ def test_put5a(self):
+ self._testPutBytesOffLen(1, 0, 0)
+
+ def test_put5b(self):
+ self._testPutBytesOffLen(1, 0, 1)
+
+ def test_put5c(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 0, 2)
+
+ def test_put5d(self):
+ self._testPutBytesOffLen(1, 1, 0)
+
+ def test_put5e(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 1, 1)
+
+ def test_put5f(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 1, 2)
+
+ def test_put5g(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 2, 0)
+
+ def test_put5h(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 2, 1)
+
+ def test_put5i(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 1, 2, 2)
+
+ def test_put6a(self):
+ self._testPutBytesOffLen(2, 0, 0)
+
+ def test_put6b(self):
+ self._testPutBytesOffLen(2, 0, 1)
+
+ def test_put6c(self):
+ self._testPutBytesOffLen(2, 0, 2)
+
+ def test_put6d(self):
+ self._testPutBytesOffLen(2, 1, 0)
+
+ def test_put6e(self):
+ self._testPutBytesOffLen(2, 1, 1)
+
+ def test_put6f(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 2, 1, 2)
+
+ def test_put6g(self):
+ self._testPutBytesOffLen(2, 2, 0)
+
+ def test_put6h(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 2, 2, 1)
+
+ def test_put6i(self):
+ self.assertRaises(IllegalArgumentException, self._testPutBytesOffLen, 2, 2, 2)
+
+ #// ------------------------------------------------------
+ #// cases for put(int), get():
+ #// put 0, get 0. // already tested above
+ #// put 0, get 1. // fails with EOFException
+ #// put 1, get 0.
+ #// put 1, get 1.
+ #// put 1, get 2. // fails with EOFException
+ #// put 2, get 0.
+ #// put 2, get 1.
+ #// put 2, get 2.
+ #// put 2, get 3. // fails with EOFException
+ #// put 10000, get 10000.
+
+ #// just like above, putting byte array instead
+ #// just like above, getting byte array instead.
+ #// just like above, putting and getting byte array.
+
+ def _testPutGet(self, nPuts, nGets):
+ for i in range(0, nPuts):
+ self.buf.put(i)
+
+ self.buf.setIndex(0)
+ for i in range(0, nGets):
+ self.assertEqual(Byte(i), Byte(self.buf.get()))
+
+ self._checkBuf(nPuts, nGets, nPuts-nGets)
+
+ def _testPutBytesGet(self, nPuts, nGets):
+ buffer = ByteArray(nPuts)
+ for i in range(0, nPuts):
+ buffer[i] = Byte(i)
+
+ self.buf.put(buffer)
+ self.buf.setIndex(0)
+
+ for i in range(0, nGets):
+ self.assertEquals(Byte(i), Byte(self.buf.get()))
+
+ self._checkBuf(nPuts, nGets, nPuts - nGets)
+
+ def _testPutGetBytes(self, nPuts, nGets):
+ for i in range(0, nPuts):
+ #print "%s" % repr(i)
+ self.buf.put(i)
+
+ self.buf.setIndex(0)
+
+ buffer = ByteArray(nGets)
+ n = self.buf.get(buffer)
+ self.assertEquals(min(nPuts, nGets), n)
+
+ for i in range(0, n):
+ self.assertEquals(Byte(i), buffer[i])
+
+ self._checkBuf(nPuts, n, nPuts-n)
+
+ def _testPutBytesGetBytes(self, nPuts, nGets):
+ buffer = ByteArray(nPuts)
+ for i in range(0, nPuts):
+ buffer[i] = Byte(i)
+
+ self.buf.put(buffer)
+ self.buf.setIndex(0)
+
+ buffer = ByteArray(nGets)
+ n = self.buf.get(buffer)
+ self.assertEquals(min(nPuts, nGets), n)
+
+ for i in range(0, n):
+ self.assertEquals(Byte(i), buffer[i])
+
+ self._checkBuf(nPuts, n, nPuts-n)
+
+ def test_get1a(self):
+ self.assertRaises(EOFException, self._testPutGet, 0, 1)
+
+ def test_get1b(self):
+ self._testPutGet(1, 0)
+
+ def test_get1c(self):
+ self._testPutGet(1, 1)
+
+ def test_get1d(self):
+ self.assertRaises(EOFException, self._testPutGet, 1, 2)
+
+ def test_get1e(self):
+ self._testPutGet(2, 0)
+
+ def test_get1f(self):
+ self._testPutGet(2, 1)
+
+ def test_get1g(self):
+ self._testPutGet(2, 2)
+
+ def test_get1h(self):
+ self.assertRaises(EOFException, self._testPutGet, 2, 3)
+
+ def test_get1i(self):
+ self._testPutGet(10000, 9995)
+
+ def test_get1j(self):
+ self._testPutGet(10000, 10000)
+
+ def test_get1k(self):
+ self._testPutGet(100000, 100000)
+
+ def test_get2a(self):
+ self.assertRaises(EOFException, self._testPutBytesGet, 0, 1)
+
+ def test_get2b(self):
+ self._testPutBytesGet(1, 0)
+
+ def test_get2d(self):
+ self.assertRaises(EOFException, self._testPutBytesGet, 1, 2)
+
+ def test_get2e(self):
+ self._testPutBytesGet(2, 0)
+
+ def test_get2f(self):
+ self._testPutBytesGet(2, 1)
+
+ def test_get2g(self):
+ self._testPutBytesGet(2, 2)
+
+ def test_get2h(self):
+ self.assertRaises(EOFException, self._testPutBytesGet, 2, 3)
+
+ def test_get2i(self):
+ self._testPutBytesGet(10000, 9995)
+
+ def test_get2j(self):
+ self._testPutBytesGet(10000, 10000)
+
+ def test_get2k(self):
+ self._testPutBytesGet(100000, 100000)
+
+ def test_get3a(self):
+ self.assertRaises(EOFException, self._testPutBytesGet, 0, 1)
+
+ def test_get3b(self):
+ self._testPutGetBytes(1, 0)
+
+ def test_get3c(self):
+ self._testPutGetBytes(1, 1)
+
+ def test_get3d(self):
+ self._testPutGetBytes(1, 2)
+
+ def test_get3e(self):
+ self._testPutGetBytes(2, 0)
+
+ def test_get3f(self):
+ self._testPutGetBytes(2, 1)
+
+ def test_get3g(self):
+ self._testPutGetBytes(2, 2)
+
+ def test_get3h(self):
+ self._testPutGetBytes(2, 3)
+
+ def test_get3i(self):
+ self._testPutGetBytes(10000, 9995)
+
+ def test_get3j(self):
+ self._testPutGetBytes(10000, 10000)
+
+ def test_get3k(self):
+ self._testPutGetBytes(100000, 100000)
+
+ def test_get4a(self):
+ self.assertRaises(EOFException, self._testPutBytesGetBytes, 0, 1)
+
+ def test_get4b(self):
+ self._testPutBytesGetBytes(1, 0)
+
+ def test_get4c(self):
+ self._testPutBytesGetBytes(1, 1)
+
+ def test_get4d(self):
+ self._testPutBytesGetBytes(1, 2)
+
+ def test_get4e(self):
+ self._testPutBytesGetBytes(2, 0)
+
+ def test_get4f(self):
+ self._testPutBytesGetBytes(2, 1)
+
+ def test_get4g(self):
+ self._testPutBytesGetBytes(2, 2)
+
+ def test_get4h(self):
+ self._testPutBytesGetBytes(2, 3)
+
+ def test_get4i(self):
+ self._testPutBytesGetBytes(10000, 9995)
+
+ def test_get4j(self):
+ self._testPutBytesGetBytes(10000, 10000)
+
+ def test_get4k(self):
+ self._testPutBytesGetBytes(100000, 100000)
+
+ def test_get5a(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3]))
+ self.assertEquals(1, self.buf.get())
+ self.assertEquals(2, self.buf.get())
+ self.assertEquals(3, self.buf.get())
+ self._checkBuf(3, 3, 0)
+
+ def test_get5b(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3]), 2)
+ self.assertEquals(1, self.buf.get())
+ self.assertEquals(2, self.buf.get())
+ self._checkBuf(2, 2, 0)
+
+ def test_get5c(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3,4,5]),1,2)
+ self.assertEquals(2, self.buf.get())
+ self.assertEquals(3, self.buf.get())
+ self._checkBuf(3, 3, 0)
+
+ def test_get6(self):
+ self.buf = FlexBuffer(ByteArray([5,6,7,8]))
+ buffer = ByteArray([11,12,13,14,15])
+ self.buf.get(buffer, 1, 3)
+
+ self.assertEquals(11, buffer[0])
+ self.assertEquals(5, buffer[1])
+ self.assertEquals(6, buffer[2])
+ self.assertEquals(7, buffer[3])
+ self.assertEquals(15, buffer[4])
+
+ def test_compact(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3,4,5]), 1, 3)
+ self.buf.compact()
+ self._checkBuf(3, 0, 3)
+ self.assertEquals(2, self.buf.get())
+ self.assertEquals(3, self.buf.get())
+ self.assertEquals(4, self.buf.get())
+
+ def test_getByte1(self):
+ self.buf = FlexBuffer(ByteArray([127, 1, 0, -1, -128]))
+ self.assertEquals(127, self.buf.getByte())
+ self.assertEquals(1, self.buf.getByte())
+ self.assertEquals(0, self.buf.getByte())
+ self.assertEquals(-1, self.buf.getByte())
+ self.assertEquals(-128, self.buf.getByte())
+ self._checkBuf(5, 5, 0)
+
+ def test_getByte2(self):
+ self.assertRaises(EOFException, self.buf.getByte)
+
+ def test_getShort1(self):
+ self.buf = FlexBuffer(ByteArray([1,2,-1,-2]))
+ self.assertEquals(Short(0x0102), self.buf.getShort())
+ self.assertEquals(Short(0xfffe), self.buf.getShort())
+ self._checkBuf(4, 4, 0)
+
+ def test_getShort2(self):
+ self.assertRaises(EOFException, self.buf.getShort)
+
+ def test_getInt1(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3,4,-1,-2,-3,-4]))
+ self.assertEquals(Integer(0x01020304), self.buf.getInt())
+ self.assertEquals(Integer(0xfffefdfc), self.buf.getInt())
+ self._checkBuf(8, 8, 0)
+
+ def test_getInt2(self):
+ self.assertRaises(EOFException, self.buf.getInt)
+
+ def test_getLong1(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3,4,5,6,7,8,-1,-2,-3,-4,-5,-6,-7,-8]))
+ self.assertEquals(Long(0x0102030405060708), self.buf.getLong())
+ self.assertEquals(Long(0xfffefdfcfbfaf9f8), self.buf.getLong())
+ self._checkBuf(16, 16, 0)
+
+ def test_getLong2(self):
+ self.assertRaises(EOFException, self.buf.getLong)
+
+ def test_getFloat1(self):
+
+ self.buf = FlexBuffer(ByteArray([
+ 0, 0, 0, 0, 63, -128, 0, 0, 83, -113, 48, -37, 100, -98, -112, -120,
+ 117, -120, 20, 25, -65, -128, 0, 0, -45, -113, 48, -37, -28, -98, -112, -120,
+ -11, -120, 20, 25, 50, 83, 79, -7, 34, 44, -87, 90, 17, -38, -85, 115,
+ -78, 83, 79, -7, -94, 44, -87, 90, -111, -38, -85, 115]))
+
+ self.assertEquals( 0.0, self.buf.getFloat() )
+ self.assertEquals( 1.0, self.buf.getFloat() )
+ self.assertEquals( 123e10, self.buf.getFloat() )
+ self.assertEquals( 234e20, self.buf.getFloat() )
+ self.assertEquals( 345e30, self.buf.getFloat() )
+ self.assertEquals( -1.0, self.buf.getFloat() )
+ self.assertEquals( -123e10, self.buf.getFloat() )
+ self.assertEquals( -234e20, self.buf.getFloat() )
+ self.assertEquals( -345e30, self.buf.getFloat() )
+ self.assertEquals( 123e-10, self.buf.getFloat() )
+ self.assertEquals( 234e-20, self.buf.getFloat() )
+ self.assertEquals( 345e-30, self.buf.getFloat() )
+ self.assertEquals( -123e-10, self.buf.getFloat() )
+ self.assertEquals( -234e-20, self.buf.getFloat() )
+ self.assertEquals( -345e-30, self.buf.getFloat() )
+
+ self._checkBuf(15*4, 15*4, 0)
+
+ def test_getFloat2(self):
+ self.assertRaises(EOFException, self.buf.getFloat)
+
+ def test_getDouble1(self):
+ # TODO - double conversions appear to be off compared to Java
+ self.buf = FlexBuffer(ByteArray([
+ 0, 0, 0, 0, 0, 0, 0, 0
+ , 63, -16, 0, 0, 0, 0, 0, 0
+ , 66, 113, -26, 27, 104, -64, 0, 0
+ , 85, 48, -73, 88, 68, 89, -6, -80
+ , 105, -4, 43, 112, 122, -31, 67, -116
+ , -65, -16, 0, 0, 0, 0, 0, 0
+ , -62, 113, -26, 27, 104, -64, 0, 0
+ , -43, 48, -73, 88, 68, 89, -6, -80
+ , -23, -4, 43, 112, 122, -31, 67, -116
+ , 62, 74, 105, -1, 27, 85, 80, 81
+ , 43, -87, -105, 64, -36, -23, -48, -66
+ , 22, -16, -127, 73, 111, 91, -75, -29
+ , -66, 74, 105, -1, 27, 85, 80, 81
+ , -85, -87, -105, 64, -36, -23, -48, -66
+ , -106, -16, -127, 73, 111, 91, -75, -29
+ ]))
+
+ self.assertEquals( 0.0, self.buf.getDouble())
+ self.assertEquals( 1.0, self.buf.getDouble())
+ self.assertEquals( 123e10, self.buf.getDouble())
+ self.assertEquals( 234e100, self.buf.getDouble())
+ self.assertEquals( 345e200, self.buf.getDouble())
+ self.assertEquals( -1.0, self.buf.getDouble())
+ self.assertEquals( -123e10, self.buf.getDouble())
+ self.assertEquals( -234e100, self.buf.getDouble())
+ self.assertEquals( -345e200, self.buf.getDouble())
+ self.assertEquals( 123e-10, self.buf.getDouble())
+ self.assertEquals( 234e-100, self.buf.getDouble())
+ self.assertEquals( 345e-200, self.buf.getDouble())
+ self.assertEquals( -123e-10, self.buf.getDouble())
+ self.assertEquals( -234e-100, self.buf.getDouble())
+ self.assertEquals( -345e-200, self.buf.getDouble())
+
+ self._checkBuf(15*8, 15*8, 0)
+
+ def test_getDouble2(self):
+ self.assertRaises(EOFException, self.buf.getDouble)
+
+ def test_getFully1(self):
+ self.buf = FlexBuffer(ByteArray([1,2,3,4,5,6]))
+ b = ByteArray(3)
+ self.buf.getFully(b)
+ self.assertEquals(1, b[0])
+ self.assertEquals(2, b[1])
+ self.assertEquals(3, b[2])
+ self.buf.getFully(b)
+ self.assertEquals(4, b[0])
+ self.assertEquals(5, b[1])
+ self.assertEquals(6, b[2])
+ self._checkBuf(6, 6, 0)
+
+ def test_getFully2(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ b = ByteArray(3)
+ #self.buf = self.buf.getFully(b)
+ self.assertRaises(EOFException, self.buf.getFully, b)
+
+ # // ------------------------------------------------------
+ # // cases for FlexBuffer put( FlexBuffer ):
+ # // put, put FlexBuffer with valid buffer
+ # // put, put Flexbuffer to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putFlexBuffer1(self):
+ buf0 = FlexBuffer(ByteArray([1,2]))
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.put(buf0)
+ self._checkBuf(buf0.length(), buf0.length(), 0)
+
+ def test_putFlexBuffer2(self):
+ buf0 = FlexBuffer(ByteArray([1,2]))
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ # TODO - Confirm this is the correct test
+ self.assertRaises(IOException, self.buf.put, buf0)
+ #self._checkBuf(max + buf0.length(), max + buf0.length(), 0)
+
+ #// ------------------------------------------------------
+ #// cases for FlexBuffer put( FlexBuffer, int ):
+ #// put, put FlexBuffer with length larger than available bytes, fails with IllegalArgumentException
+ #// put, put FlexBuffer with valid length value
+ #// put, put Flexbuffer to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putFlexBuffer3(self):
+ buf0 = FlexBuffer(ByteArray([1,2]))
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.setIndex(0)
+ # TODO - confirm this is the correct test
+ self.assertRaises(IllegalArgumentException, self.buf.put, buf0, 3)
+ #self._checkBuf(3,3,0)
+
+ def test_putFlexBuffer4(self):
+ buf0 = FlexBuffer(ByteArray([1,2]))
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.put(buf0, 1)
+ self._checkBuf(1,1,0)
+
+ def test_putFlexBuffer5(self):
+ buf0 = FlexBuffer(ByteArray([1,2]))
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ self.assertRaises(IOException, self.buf.put, buf0, 1)
+ #self._checkBuf(max+1, max+1, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putByte( byte ):
+ #// putByte, put byte value and expect getByte to return matched value.
+ #// putByte to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putByte1(self):
+ self.buf = FlexBuffer(ByteArray())
+ self.buf.putByte(0x01)
+ self._checkBuf(1, 1, 0)
+ self.buf.setIndex(0)
+ self.assertEquals(0x01, self.buf.getByte())
+ self._checkBuf(1, 1, 0)
+
+ def test_putByte2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ self.assertRaises(IOException, self.buf.putByte, 0x01)
+ #self._checkBuf(max+1, max+1, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putDouble( double ):
+ #// putDouble, put Double and expect getDouble to return matched value.
+ #// putDouble to a Flexbuffer approaching max length, fails with IOException.
+ def test_putDouble1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.putDouble(Double.MAX_VALUE)
+ self._checkBuf(8,8,0)
+ self.buf.setIndex(0)
+ self.assertEquals(Double.MAX_VALUE, self.buf.getDouble())
+ self._checkBuf(8,8,0)
+
+ def test_putDouble2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ self.assertRaises(IOException, self.buf.putDouble, Double.MIN_VALUE)
+ #self._checkBuf(max+8, max+8, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putFloat( float ):
+ #// putFloat, put Float and expect getFloat to return matched value.
+ #// putFloat to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putFloat1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.putFloat(Float.MAX_VALUE)
+ self._checkBuf(4, 4, 0)
+ self.buf.setIndex(0)
+ self.assertEquals(Float.MAX_VALUE, self.buf.getFloat())
+ self._checkBuf(4, 4, 0)
+
+ def test_putFloat2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ # TODO - confirm this is the correct test
+ self.assertRaises(IOException, self.buf.putFloat, Float.MIN_VALUE)
+ #self._checkBuf(max+4, max+4, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putInt( int ):
+ #// putInt, put Int and expect getInt to return matched value.
+ #// putInt to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putInt1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.putInt(Integer.MAX_VALUE)
+ self._checkBuf(4, 4, 0)
+ self.buf.setIndex(0)
+ self.assertEquals(Integer.MAX_VALUE, self.buf.getInt())
+ self._checkBuf(4 ,4, 0)
+
+ def test_putInt2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ # TODO - validate test
+ self.assertRaises(IOException, self.buf.putInt, Integer.MIN_VALUE)
+ #self._checkBuf(max+4, max+4, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putLong( long ):
+ #// putLong, put Long and expect getLong to return matched value.
+ #// putShort to a Flexbuffer approaching max length, fails with IOException.
+ def test_putLong1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.putLong(Long.MAX_VALUE)
+ self._checkBuf(8, 8, 0)
+ self.buf.setIndex(0)
+ self.assertEquals(Long.MAX_VALUE, self.buf.getLong())
+ self._checkBuf(8, 8, 0)
+
+ def test_putLong2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ # TODO - confirm this is the correct test
+ self.assertRaises(IOException, self.buf.putLong, Long.MIN_VALUE)
+ #self._checkBuf(max+8, max+8, 0)
+
+ #// ------------------------------------------------------
+ #// cases for void putShort( short ):
+ #// putShort, put short and expect getShort to return matched value.
+ #// putShort to a Flexbuffer approaching max length, fails with IOException.
+
+ def test_putShort1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.buf.putShort(Short.MAX_VALUE)
+ self._checkBuf(2, 2, 0)
+ self.buf.setIndex(0)
+ self.assertEquals(Short.MAX_VALUE, self.buf.getShort())
+ self._checkBuf(2, 2, 0)
+
+ def test_putShort2(self):
+ max = 4*1024*1024
+ self.buf = FlexBuffer(ByteArray(max))
+ self.buf.setIndex(max)
+ # TODO - confirm this correct test
+ self.assertRaises(IOException, self.buf.putShort, 1)
+ #self._checkBuf(max+2, max+2, 0)
+
+ #// ------------------------------------------------------
+ #// cases for FlexBuffer skip( int, boolean ):
+ #// skip length < 0, put = false. // fails with illegal argument
+ #// skip length > buffer length, put = false. // fails with EOFException
+ #// skip length = 0, put = false.
+ #// skip length = buffer length, put = false.
+ #// skip length < buffer length, put = false.
+ #// skip length > buffer length, put = true.
+ #// skip length < buffer length, put = true.
+ #// skip length = max buffer length, put = true. // fails with IOException
+
+ def test_skip1(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.assertRaises(IllegalArgumentException, self.buf.skip, -1, False)
+
+ def test_skip2(self):
+ self.buf = FlexBuffer(ByteArray([]))
+ self.assertRaises(EOFException, self.buf.skip, 2, False)
+
+ def test_skip3(self):
+ self.buf = FlexBuffer(ByteArray([1, 2]))
+ self.buf.skip(2, False)
+ self._checkBuf(2, 2, 0)
+
+ def test_skip4(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ self.buf.skip(2, False)
+ self._checkBuf(2, 2, 0)
+
+ def test_skip5(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ self.buf.skip(1, False)
+ self._checkBuf(2, 1, 1)
+
+ def test_skip6(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ self.buf.skip(1, True)
+ self._checkBuf(2, 1, 1)
+
+ def test_skip7(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ self.buf.skip(5, True)
+ self._checkBuf(5, 5, 0)
+
+ def test_skip8(self):
+ self.buf = FlexBuffer(ByteArray([1,2]))
+ max = 4*1024*1024
+ # TODO - confirm this is the correct test
+ self.assertRaises(IOException, self.buf.skip, max+1, True)
+ #self._checkBuf(max+1, max+1, 0)
+
+if __name__ == '__main__':
+ unittest.main()
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestFlexBuffer.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,78 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
+import unittest
+from etch.util.Types import *
+from etch.msg.IdName import IdName
+
+class Test_EtchUtilTypes(unittest.TestCase):
+
+ def setUp(self):
+ print " "
+
+
+ def test_byte_sizes(self):
+ a = Byte(0)
+
+ # +/- 128 boundary
+ self.assertEquals( 127, a+127)
+ self.assertEquals(-128, a+128)
+ self.assertEquals(-127, a+129)
+
+ self.assertEquals(-127, a-127)
+ self.assertEquals(-128, a-128)
+ self.assertEquals( 127, a-129)
+
+ # +/- 256 boundary
+ self.assertEquals(-1, a+255)
+ self.assertEquals( 0, a+256)
+ self.assertEquals( 1, a+257)
+
+ self.assertEquals( 1, a-255)
+ self.assertEquals( 0, a-256)
+ self.assertEquals(-1, a-257)
+
+ # +/- 384 boundary
+ self.assertEquals( 127, a+383)
+ self.assertEquals(-128, a+384)
+ self.assertEquals(-127, a+385)
+
+ self.assertEquals(-127, a-383)
+ self.assertEquals(-128, a-384)
+ self.assertEquals( 127, a-385)
+
+ # +/- 512 boundary
+ self.assertEquals(-1, a+511)
+ self.assertEquals( 0, a+512)
+ self.assertEquals( 1, a+513)
+
+ self.assertEquals( 1, a-511)
+ self.assertEquals( 0, a-512)
+ self.assertEquals(-1, a-513)
+
+ def test_computehash(self):
+ test_keys = (
+ ('_mt__Etch_RuntimeException', 1071849665),
+ ('foo', 711657441 ),
+ ('bar', 677693038 ),
+ ('ZZZZZZZZZZZZZZZZZZZZ', -1181680379),
+ )
+ for t in test_keys:
+ print " IdName.hash('%s') -> %d" % (t[0], t[1])
+ self.assertEquals(t[1], IdName.hash(t[0]))
+
+if __name__ == '__main__':
+ unittest.main()
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/TestTypes.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py?rev=752702&view=auto
==============================================================================
--- incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py (added)
+++ incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py Thu Mar 12 00:23:28 2009
@@ -0,0 +1,16 @@
+"""
+# Copyright 2007-2008 Cisco Systems Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy
+# of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""
\ No newline at end of file
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/etch/trunk/binding-python/runtime/src/test/python/tests/util/__init__.py
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"