Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bd335bfc
Commit
bd335bfc
authored
Dec 21, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional edge-case tests for test_long_and_overflow.
parent
ed02b3f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
16 deletions
+107
-16
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+107
-16
No files found.
Modules/_testcapimodule.c
View file @
bd335bfc
...
...
@@ -366,68 +366,158 @@ test_longlong_api(PyObject* self, PyObject *args)
static
PyObject
*
test_long_and_overflow
(
PyObject
*
self
)
{
PyObject
*
num
;
PyObject
*
num
,
*
one
,
*
temp
;
long
value
;
int
overflow
;
/* a number larger than LONG_MAX even on 64-bit platforms */
/* Test that overflow is set properly for a large value. */
/* num is a number larger than LONG_MAX even on 64-bit platforms */
num
=
PyLong_FromString
(
"FFFFFFFFFFFFFFFFFFFFFFFF"
,
NULL
,
16
);
if
(
num
==
NULL
)
return
NULL
;
/* Test that overflow is set properly for a large value. */
overflow
=
1234
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"return value was not set to -1"
);
if
(
overflow
!=
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not set to 1"
);
/* Same again, with num = LONG_MAX + 1 */
num
=
PyLong_FromLong
(
LONG_MAX
);
if
(
num
==
NULL
)
return
NULL
;
one
=
PyLong_FromLong
(
1L
);
if
(
one
==
NULL
)
{
Py_DECREF
(
num
);
return
NULL
;
}
temp
=
PyNumber_Add
(
num
,
one
);
Py_DECREF
(
one
);
Py_DECREF
(
num
);
num
=
temp
;
if
(
num
==
NULL
)
return
NULL
;
overflow
=
0
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"return value was not set to -1"
);
if
(
overflow
!=
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not set to 0"
);
Py_DECREF
(
num
);
"overflow was not set to 1"
);
/* a number smaller than LONG_MIN even on 64-bit platforms */
/* Test that overflow is set properly for a large negative value. */
/* num is a number smaller than LONG_MIN even on 64-bit platforms */
num
=
PyLong_FromString
(
"-FFFFFFFFFFFFFFFFFFFFFFFF"
,
NULL
,
16
);
if
(
num
==
NULL
)
return
NULL
;
/* Test that overflow is set properly for a large negative value. */
overflow
=
1234
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"return value was not set to -1"
);
if
(
overflow
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not set to -1"
);
/* Same again, with num = LONG_MIN - 1 */
num
=
PyLong_FromLong
(
LONG_MIN
);
if
(
num
==
NULL
)
return
NULL
;
one
=
PyLong_FromLong
(
1L
);
if
(
one
==
NULL
)
{
Py_DECREF
(
num
);
return
NULL
;
}
temp
=
PyNumber_Subtract
(
num
,
one
);
Py_DECREF
(
one
);
Py_DECREF
(
num
);
num
=
temp
;
if
(
num
==
NULL
)
return
NULL
;
overflow
=
0
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"return value was not set to -1"
);
if
(
overflow
!=
-
1
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not set to 0"
);
Py_DECREF
(
num
);
"overflow was not set to -1"
);
/* Test that overflow is cleared properly for small values. */
num
=
PyLong_FromString
(
"FF"
,
NULL
,
16
);
if
(
num
==
NULL
)
return
NULL
;
/* Test that overflow is cleared properly for a small value. */
overflow
=
1234
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
0xFF
)
return
raiseTestError
(
"test_long_and_overflow"
,
"expected return value 0xFF"
);
if
(
overflow
!=
0
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not cleared"
);
num
=
PyLong_FromString
(
"-FF"
,
NULL
,
16
);
if
(
num
==
NULL
)
return
NULL
;
overflow
=
0
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
-
0xFF
)
return
raiseTestError
(
"test_long_and_overflow"
,
"expected return value 0xFF"
);
if
(
overflow
!=
0
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was set incorrectly"
);
num
=
PyLong_FromLong
(
LONG_MAX
);
if
(
num
==
NULL
)
return
NULL
;
overflow
=
1234
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
LONG_MAX
)
return
raiseTestError
(
"test_long_and_overflow"
,
"expected return value LONG_MAX"
);
if
(
overflow
!=
0
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not cleared"
);
num
=
PyLong_FromLong
(
LONG_MIN
);
if
(
num
==
NULL
)
return
NULL
;
overflow
=
0
;
value
=
PyLong_AsLongAndOverflow
(
num
,
&
overflow
);
Py_DECREF
(
num
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
if
(
value
!=
LONG_MIN
)
return
raiseTestError
(
"test_long_and_overflow"
,
"expected return value LONG_MIN"
);
if
(
overflow
!=
0
)
return
raiseTestError
(
"test_long_and_overflow"
,
"overflow was not cleared"
);
Py_INCREF
(
Py_None
);
return
Py_None
;
...
...
@@ -1116,7 +1206,8 @@ static PyMethodDef TestMethods[] = {
{
"test_dict_iteration"
,
(
PyCFunction
)
test_dict_iteration
,
METH_NOARGS
},
{
"test_lazy_hash_inheritance"
,
(
PyCFunction
)
test_lazy_hash_inheritance
,
METH_NOARGS
},
{
"test_long_api"
,
(
PyCFunction
)
test_long_api
,
METH_NOARGS
},
{
"test_long_and_overflow"
,
(
PyCFunction
)
test_long_and_overflow
,
METH_NOARGS
},
{
"test_long_and_overflow"
,
(
PyCFunction
)
test_long_and_overflow
,
METH_NOARGS
},
{
"test_long_numbits"
,
(
PyCFunction
)
test_long_numbits
,
METH_NOARGS
},
{
"test_k_code"
,
(
PyCFunction
)
test_k_code
,
METH_NOARGS
},
{
"test_empty_argparse"
,
(
PyCFunction
)
test_empty_argparse
,
METH_NOARGS
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment