PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/dateformat - dateformat_helpers.cpp (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 30 39 76.9 %
Date: 2014-08-04 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | This source file is subject to version 3.01 of the PHP license,      |
       6             :    | that is bundled with this package in the file LICENSE, and is        |
       7             :    | available through the world-wide-web at the following url:           |
       8             :    | http://www.php.net/license/3_01.txt                                  |
       9             :    | If you did not receive a copy of the PHP license and are unable to   |
      10             :    | obtain it through the world-wide-web, please send a note to          |
      11             :    | license@php.net so we can mail you a copy immediately.               |
      12             :    +----------------------------------------------------------------------+
      13             :    | Authors: Gustavo Lopes <cataphract@php.net>                          |
      14             :    +----------------------------------------------------------------------+
      15             : */
      16             : 
      17             : #include "../intl_cppshims.h"
      18             : 
      19             : #include <unicode/calendar.h>
      20             : #include <unicode/gregocal.h>
      21             : 
      22             : #include "dateformat_helpers.h"
      23             : 
      24             : extern "C" {
      25             : #include "../php_intl.h"
      26             : #include <Zend/zend_operators.h>
      27             : #define USE_CALENDAR_POINTER 1
      28             : #include "../calendar/calendar_class.h"
      29             : }
      30             : 
      31         366 : int datefmt_process_calendar_arg(zval* calendar_zv,
      32             :                                                                  Locale const& locale,
      33             :                                                                  const char *func_name,
      34             :                                                                  intl_error *err,
      35             :                                                                  Calendar*& cal,
      36             :                                                                  long& cal_int_type,
      37             :                                                                  bool& calendar_owned TSRMLS_DC)
      38             : {
      39             :         char *msg;
      40         366 :         UErrorCode status = UErrorCode();
      41             : 
      42         532 :         if (calendar_zv == NULL || Z_TYPE_P(calendar_zv) == IS_NULL) {
      43             : 
      44             :                 // default requested
      45         166 :                 cal = new GregorianCalendar(locale, status);
      46         166 :                 calendar_owned = true;
      47             : 
      48         166 :                 cal_int_type = UCAL_GREGORIAN;
      49             : 
      50         200 :         } else if (Z_TYPE_P(calendar_zv) == IS_LONG) {
      51             : 
      52         193 :                 long v = Z_LVAL_P(calendar_zv);
      53         193 :                 if (v != (long)UCAL_TRADITIONAL && v != (long)UCAL_GREGORIAN) {
      54             :                         spprintf(&msg, 0, "%s: invalid value for calendar type; it must be "
      55             :                                         "one of IntlDateFormatter::TRADITIONAL (locale's default "
      56             :                                         "calendar) or IntlDateFormatter::GREGORIAN. "
      57             :                                         "Alternatively, it can be an IntlCalendar object",
      58           2 :                                         func_name);
      59           2 :                         intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, msg, 1 TSRMLS_CC);
      60           2 :                         efree(msg);
      61           2 :                         return FAILURE;
      62         191 :                 } else if (v == (long)UCAL_TRADITIONAL) {
      63           7 :                         cal = Calendar::createInstance(locale, status);
      64             :                 } else { //UCAL_GREGORIAN
      65         184 :                         cal = new GregorianCalendar(locale, status);
      66             :                 }
      67         191 :                 calendar_owned = true;
      68             : 
      69         191 :                 cal_int_type = Z_LVAL_P(calendar_zv);
      70             : 
      71           7 :         } else if (Z_TYPE_P(calendar_zv) == IS_OBJECT &&
      72             :                         instanceof_function_ex(Z_OBJCE_P(calendar_zv),
      73             :                         Calendar_ce_ptr, 0 TSRMLS_CC)) {
      74             : 
      75           6 :                 cal = calendar_fetch_native_calendar(calendar_zv TSRMLS_CC);
      76           6 :                 if (cal == NULL) {
      77             :                         spprintf(&msg, 0, "%s: Found unconstructed IntlCalendar object",
      78           0 :                                         func_name);
      79           0 :                         intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, msg, 1 TSRMLS_CC);
      80           0 :                         efree(msg);
      81           0 :                         return FAILURE;
      82             :                 }
      83           6 :                 calendar_owned = false;
      84             : 
      85           6 :                 cal_int_type = -1;
      86             : 
      87             :         } else {
      88             :                 spprintf(&msg, 0, "%s: Invalid calendar argument; should be an integer "
      89           1 :                                 "or an IntlCalendar instance", func_name);
      90           1 :                 intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, msg, 1 TSRMLS_CC);
      91           1 :                 efree(msg);
      92           1 :                 return FAILURE;
      93             :         }
      94             : 
      95         363 :         if (cal == NULL && !U_FAILURE(status)) {
      96           0 :                 status = U_MEMORY_ALLOCATION_ERROR;
      97             :         }
      98         363 :         if (U_FAILURE(status)) {
      99           0 :                 spprintf(&msg, 0, "%s: Failure instantiating calendar", func_name);
     100           0 :                 intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, msg, 1 TSRMLS_CC);
     101           0 :                 efree(msg);
     102           0 :                 return FAILURE;
     103             :         }
     104             : 
     105         363 :         return SUCCESS;
     106             : }

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:05 +0000 (28 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.