@@ -1526,6 +1526,39 @@ test_hash(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
15261526}
15271527
15281528
1529+ #if PY_VERSION_HEX >= 0x03050000
1530+ #define TEST_PYTIME
1531+
1532+ static PyObject *
1533+ test_time (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (args ))
1534+ {
1535+ PyTime_t t ;
1536+ #define UNINITIALIZED_TIME ((PyTime_t)-483884113929936179)
1537+
1538+ t = UNINITIALIZED_TIME ;
1539+ assert (PyTime_Time (& t ) == 0 );
1540+ assert (t != UNINITIALIZED_TIME );
1541+
1542+ t = UNINITIALIZED_TIME ;
1543+ assert (PyTime_Monotonic (& t ) == 0 );
1544+ assert (t != UNINITIALIZED_TIME );
1545+
1546+ // Test multiple times since an implementation uses a cache
1547+ for (int i = 0 ; i < 5 ; i ++ ) {
1548+ t = UNINITIALIZED_TIME ;
1549+ assert (PyTime_PerfCounter (& t ) == 0 );
1550+ assert (t != UNINITIALIZED_TIME );
1551+ }
1552+
1553+ assert (PyTime_AsSecondsDouble (1 ) == 1e-9 );
1554+ assert (PyTime_AsSecondsDouble (1500 * 1000 * 1000 ) == 1.5 );
1555+ assert (PyTime_AsSecondsDouble (-500 * 1000 * 1000 ) == -0.5 );
1556+
1557+ Py_RETURN_NONE ;
1558+ }
1559+ #endif
1560+
1561+
15291562static struct PyMethodDef methods [] = {
15301563 {"test_object" , test_object , METH_NOARGS , _Py_NULL },
15311564 {"test_py_is" , test_py_is , METH_NOARGS , _Py_NULL },
@@ -1559,6 +1592,9 @@ static struct PyMethodDef methods[] = {
15591592 {"test_unicode" , test_unicode , METH_NOARGS , _Py_NULL },
15601593 {"test_list" , test_list , METH_NOARGS , _Py_NULL },
15611594 {"test_hash" , test_hash , METH_NOARGS , _Py_NULL },
1595+ #ifdef TEST_PYTIME
1596+ {"test_time" , test_time , METH_NOARGS , _Py_NULL },
1597+ #endif
15621598 {_Py_NULL , _Py_NULL , 0 , _Py_NULL }
15631599};
15641600
0 commit comments