LCOV - code coverage report
Current view: top level - Modules - berval.c (source / functions) Hit Total Coverage
Test: python-ldap LCOV report Lines: 12 14 85.7 %
Date: 2017-12-08 13:03:20 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* See https://www.python-ldap.org/ for details. */
       2             : 
       3             : #include "common.h"
       4             : #include "berval.h"
       5             : 
       6             : /*
       7             :  * Copies out the data from a berval, and returns it as a new Python object,
       8             :  * Returns None if the berval pointer is NULL.
       9             :  *
      10             :  * Note that this function is not the exact inverse of LDAPberval_from_object
      11             :  * with regards to the NULL/None conversion.
      12             :  *
      13             :  * Returns a new Python object on success, or NULL on failure.
      14             :  */
      15             : PyObject *
      16         916 : LDAPberval_to_object(const struct berval *bv)
      17             : {
      18         916 :     PyObject *ret = NULL;
      19             : 
      20         916 :     if (!bv) {
      21           2 :         ret = Py_None;
      22           2 :         Py_INCREF(ret);
      23             :     }
      24             :     else {
      25         914 :         ret = PyBytes_FromStringAndSize(bv->bv_val, bv->bv_len);
      26             :     }
      27             : 
      28         916 :     return ret;
      29             : }
      30             : 
      31             : /*
      32             :  * Same as LDAPberval_to_object, but returns a Unicode PyObject.
      33             :  * Use when the value is known to be text (for instance a distinguishedName).
      34             :  *
      35             :  * Returns a new Python object on success, or NULL on failure.
      36             :  */
      37             : PyObject *
      38         156 : LDAPberval_to_unicode_object(const struct berval *bv)
      39             : {
      40         156 :     PyObject *ret = NULL;
      41             : 
      42         156 :     if (!bv) {
      43           0 :         ret = Py_None;
      44           0 :         Py_INCREF(ret);
      45             :     }
      46             :     else {
      47         156 :         ret = PyUnicode_FromStringAndSize(bv->bv_val, bv->bv_len);
      48             :     }
      49             : 
      50         156 :     return ret;
      51             : }

Generated by: LCOV version 1.12