[PyObjC-svn] r1998 - in trunk/pyobjc/pyobjc-core: Lib/objc/test Modules/objc Modules/objc/test

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Sat May  3 14:57:32 2008
New Revision: 1998

Log:
* Add testcases for the OC_PythonNumber class
* Fix issues found by these tests

Stil to do: finish the implementation of -descriptionWithLocale:


Added:
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py   (contents, props changed)
   trunk/pyobjc/pyobjc-core/Modules/objc/test/pythonnumber.m
Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.m

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.m	Sat May  3 14:57:32 2008
@@ -259,7 +259,7 @@
 			result =  (long long)PyFloat_AsDouble(value);
 			PyObjC_GIL_RETURN(result);
 		} else if (PyLong_Check(value)) {
-			result =  PyLong_AsLongLong(value);
+			result =  PyLong_AsUnsignedLongLongMask(value);
 			PyObjC_GIL_RETURN(result);
 		}
 	PyObjC_END_WITH_GIL
@@ -281,7 +281,7 @@
 			result =  (unsigned long long)PyFloat_AsDouble(value);
 			PyObjC_GIL_RETURN(result);
 		} else if (PyLong_Check(value)) {
-			result =  PyLong_AsUnsignedLongLong(value);
+			result =  PyLong_AsUnsignedLongLongMask(value);
 			PyObjC_GIL_RETURN(result);
 		}
 	PyObjC_END_WITH_GIL
@@ -314,13 +314,19 @@
 		if (repr == NULL) {
 			PyObjC_GIL_FORWARD_EXC();
 		}
+
+		PyObject* uniVal = PyUnicode_FromEncodedObject(repr, "ascii", "strict");
+		Py_DECREF(repr);
+		if (PyErr_Occurred()) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
 	
-		result = PyObjC_PythonToId(repr);
+		result = PyObjC_PythonToId(uniVal);
+		Py_DECREF(uniVal);
 		if (PyErr_Occurred()) {
 			PyObjC_GIL_FORWARD_EXC();
 		}
 
-		Py_DECREF(repr);
 
 	PyObjC_END_WITH_GIL
 	return (NSString*)result;
@@ -392,6 +398,55 @@
 	}
 }
 
+- (NSComparisonResult)compare:(NSNumber *)aNumber
+{
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* other = PyObjC_IdToPython(aNumber);
+		if (other == NULL) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
+		int r = PyObject_Compare(value, other);
+		Py_DECREF(other);
+		if (PyErr_Occurred()) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
+		if (r < 0) {
+			PyObjC_GIL_RETURN(NSOrderedAscending);
+		} else if (r > 0) {
+			PyObjC_GIL_RETURN(NSOrderedDescending);
+		} else {
+			PyObjC_GIL_RETURN(NSOrderedSame);
+		}
+
+
+	PyObjC_END_WITH_GIL
+}
+
+-(BOOL)isEqualToNumber:(NSNumber*)aNumber
+{
+	PyObjC_BEGIN_WITH_GIL
+		PyObject* other = PyObjC_IdToPython(aNumber);
+		if (other == NULL) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
+		int r = PyObject_RichCompareBool(value, other, Py_EQ);
+		Py_DECREF(other);
+		if (r == -1) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
+		if (r) {
+			PyObjC_GIL_RETURN(YES);
+		} else {
+			PyObjC_GIL_RETURN(NO);
+		}
+
+	PyObjC_END_WITH_GIL
+}
+
 #if 1
 
 -(NSObject*)replacementObjectForArchiver:(NSObject*)archiver
@@ -448,5 +503,18 @@
 	return [OC_PythonNumber class];
 }
 
+-(id)copy
+{
+	return [self copyWithZone:0];
+}
+
+-(id)copyWithZone:(NSZone*)zone
+{
+	(void)zone;
+	[self retain];
+	return self;
+}
+
+
 #endif
 @end

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.