Skip to content

Commit 26d79d3

Browse files
committed
test Py_INCREF()
1 parent 525c2dd commit 26d79d3

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎capi_tests/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PYTHON_CFLAGS=-Wall -I $(CPYTHON_SRC) -I $(CPYTHON_SRC)/Include
44
PYTHON_LDFLAGS=-l $(LIBPYTHON) -L $(CPYTHON_SRC)
55
CFLAGS=$(shell pkg-config check --cflags) $(PYTHON_CFLAGS)
66
LDFLAGS=$(shell pkg-config check --libs) $(PYTHON_LDFLAGS)
7-
SOURCES=runtests.c test_tuple.c
7+
SOURCES=runtests.c test_object.c test_tuple.c
88

99
.PHONY: test_fullapi test_newcapi test_no_borrow
1010
.NOTPARALLEL: test_fullapi test_newcapi test_no_borrow

‎capi_tests/runtests.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <check.h>
33
#include <Python.h>
44

5+
void register_PyObject(Suite *s);
56
void register_PyTuple(Suite *s);
67

78
int main(void)
@@ -18,6 +19,7 @@ int main(void)
1819
#endif
1920

2021
Suite *s = suite_create("CAPI");
22+
register_PyObject(s);
2123
register_PyTuple(s);
2224
SRunner *sr = srunner_create(s);
2325

‎capi_tests/test_object.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Test PyObject API */
2+
3+
#include <stdlib.h>
4+
#include <check.h>
5+
#include <Python.h>
6+
7+
8+
START_TEST(test_Py_INCREF)
9+
{
10+
PyObject *obj = Py_None;
11+
Py_ssize_t refcnt = Py_REFCNT(obj);
12+
13+
Py_INCREF(obj);
14+
ck_assert_int_eq(Py_REFCNT(obj), refcnt + 1);
15+
16+
Py_DECREF(obj);
17+
}
18+
END_TEST
19+
20+
21+
START_TEST(test_Py_DECREF)
22+
{
23+
PyObject *obj = Py_None;
24+
Py_INCREF(obj);
25+
Py_ssize_t refcnt = Py_REFCNT(obj);
26+
27+
Py_DECREF(obj);
28+
ck_assert_int_eq(Py_REFCNT(obj), refcnt - 1);
29+
}
30+
END_TEST
31+
32+
33+
void register_PyObject(Suite *s)
34+
{
35+
TCase *testcase = tcase_create("PyObject");
36+
tcase_add_test(testcase, test_Py_INCREF);
37+
tcase_add_test(testcase, test_Py_DECREF);
38+
suite_add_tcase(s, testcase);
39+
}

0 commit comments

Comments
 (0)