Browse Source

pull-request/2456:

increase test coverage in calendar extension
    consistent warnings in calendar extension
pull/2461/head
Edgar R. Sandi 9 years ago
committed by Joe Watkins
parent
commit
ebdbebee29
No known key found for this signature in database GPG Key ID: F9BA0ADA31CBD89E
  1. 12
      ext/calendar/calendar.c
  2. 17
      ext/calendar/tests/cal_days_in_month_error1.phpt
  3. 13
      ext/calendar/tests/cal_from_jd_error1.phpt
  4. 2
      ext/calendar/tests/cal_info.phpt
  5. 13
      ext/calendar/tests/cal_to_jd_error1.phpt
  6. 6
      ext/calendar/tests/gregoriantojd.phpt
  7. 2
      ext/calendar/tests/jdtogregorian.phpt
  8. 10
      ext/calendar/tests/jdtojewish.phpt
  9. 2
      ext/calendar/tests/jdtojulian.phpt
  10. 14
      ext/calendar/tests/jdtounix_error1.phpt
  11. 4
      ext/calendar/tests/juliantojd.phpt
  12. 4
      ext/calendar/tests/unixtojd.phpt
  13. 24
      ext/calendar/tests/unixtojd_error1.phpt
  14. 16
      ext/date/tests/cal_days_in_month_invalid_calendar.phpt
  15. 16
      ext/date/tests/cal_days_in_month_invalid_date.phpt

12
ext/calendar/calendar.c

@ -313,7 +313,7 @@ PHP_FUNCTION(cal_info)
if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT ".", cal);
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT, cal);
RETURN_FALSE;
}
@ -335,7 +335,7 @@ PHP_FUNCTION(cal_days_in_month)
}
if (cal < 0 || cal >= CAL_NUM_CALS) {
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT ".", cal);
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT, cal);
RETURN_FALSE;
}
@ -344,7 +344,7 @@ PHP_FUNCTION(cal_days_in_month)
sdn_start = calendar->to_jd(year, month, 1);
if (sdn_start == 0) {
php_error_docref(NULL, E_WARNING, "invalid date.");
php_error_docref(NULL, E_WARNING, "invalid date");
RETURN_FALSE;
}
@ -381,7 +381,7 @@ PHP_FUNCTION(cal_to_jd)
}
if (cal < 0 || cal >= CAL_NUM_CALS) {
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT ".", cal);
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT, cal);
RETURN_FALSE;
}
@ -403,7 +403,7 @@ PHP_FUNCTION(cal_from_jd)
}
if (cal < 0 || cal >= CAL_NUM_CALS) {
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT "", cal);
php_error_docref(NULL, E_WARNING, "invalid calendar ID " ZEND_LONG_FMT, cal);
RETURN_FALSE;
}
calendar = &cal_conversion_table[cal];
@ -623,7 +623,7 @@ PHP_FUNCTION(jdtojewish)
RETURN_STRING(date);
} else {
if (year <= 0 || year > 9999) {
php_error_docref(NULL, E_WARNING, "Year out of range (0-9999).");
php_error_docref(NULL, E_WARNING, "Year out of range (0-9999)");
RETURN_FALSE;
}

17
ext/calendar/tests/cal_days_in_month_error1.phpt

@ -0,0 +1,17 @@
--TEST--
Test cal_days_in_month() function : error conditions
--CREDITS--
edgarsandi - <edgar.r.sandi@gmail.com>
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
var_dump(cal_days_in_month(-1, 4, 2017));
var_dump(cal_days_in_month(CAL_GREGORIAN,0, 2009));
?>
--EXPECTF--
Warning: cal_days_in_month(): invalid calendar ID -1 in %s on line %d
bool(false)
Warning: cal_days_in_month(): invalid date in %s on line %d
bool(false)

13
ext/calendar/tests/cal_from_jd_error1.phpt

@ -0,0 +1,13 @@
--TEST--
Test cal_from_jd() function : error conditions
--CREDITS--
edgarsandi - <edgar.r.sandi@gmail.com>
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
var_dump(cal_from_jd(1748326, -1));
?>
--EXPECTF--
Warning: cal_from_jd(): invalid calendar ID -1 in %s on line %d
bool(false)

2
ext/calendar/tests/cal_info.phpt

@ -213,4 +213,4 @@ Array
[calsymbol] => CAL_JULIAN
)
Warning: cal_info(): invalid calendar ID 99999. in %s on line %d
Warning: cal_info(): invalid calendar ID 99999 in %s on line %d

13
ext/calendar/tests/cal_to_jd_error1.phpt

@ -0,0 +1,13 @@
--TEST--
Test cal_to_jd() function : error conditions
--CREDITS--
edgarsandi - <edgar.r.sandi@gmail.com>
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
var_dump(cal_to_jd(-1, 8, 26, 74));
?>
--EXPECTF--
Warning: cal_to_jd(): invalid calendar ID -1 in %s on line %d
bool(false)

6
ext/calendar/tests/gregoriantojd.phpt

@ -9,10 +9,14 @@ echo gregoriantojd( 1, 1, 1582). "\n";
echo gregoriantojd(10, 5, 1582). "\n";
echo gregoriantojd( 1, 1, 1970). "\n";
echo gregoriantojd( 1, 1, 2999). "\n";
echo gregoriantojd( 1, 1, -4714). "\n";
echo gregoriantojd( 11, 24, -4714). "\n";
?>
--EXPECT--
0
2298874
2299151
2440588
2816423
2816423
0
0

2
ext/calendar/tests/jdtogregorian.phpt

@ -5,6 +5,7 @@ jdtogregorian()
--FILE--
<?php
echo jdtogregorian(0). "\n";
echo jdtogregorian(1). "\n";
echo jdtogregorian(2298874). "\n";
echo jdtogregorian(2299151). "\n";
echo jdtogregorian(2440588). "\n";
@ -12,6 +13,7 @@ echo jdtogregorian(2816423). "\n";
?>
--EXPECT--
0/0/0
11/25/-4714
1/1/1582
10/5/1582
1/1/1970

10
ext/calendar/tests/jdtojewish.phpt

@ -16,6 +16,11 @@ var_dump(jdtojewish(gregoriantojd(10,28,2002))."\r\n".
jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM)."\r\n".
jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM+CAL_JEWISH_ADD_ALAFIM_GERESH)."\r\n".
jdtojewish(gregoriantojd(3,10,2007))."\r\n");
echo jdtojewish(gregoriantojd(11,5,2002)) . "\n";
echo jdtojewish(gregoriantojd(11,29,2004)) . "\n";
echo jdtojewish(gregoriantojd(1,1,9998)) . "\n";
echo jdtojewish(gregoriantojd(1,1,9998),true) . "\n";
?>
--EXPECTF--
string(%d) "2/22/5763
@ -30,3 +35,8 @@ string(%d) "2/22/5763
á' çùåï ä' àìôéí úùñ"â
7/20/5767
"
2/30/5763
3/16/5765
3/8/13758
Warning: jdtojewish(): Year out of range (0-9999) in %s on line %d

2
ext/calendar/tests/jdtojulian.phpt

@ -5,6 +5,7 @@ jdtojulian()
--FILE--
<?php
echo jdtojulian(0). "\n";
echo jdtojulian(1). "\n";
echo jdtojulian(2298874). "\n";
echo jdtojulian(2299151). "\n";
echo jdtojulian(2440588). "\n";
@ -12,6 +13,7 @@ echo jdtojulian(2816423). "\n";
?>
--EXPECT--
0/0/0
1/2/-4713
12/22/1581
9/25/1582
12/19/1969

14
ext/calendar/tests/jdtounix_error1.phpt

@ -0,0 +1,14 @@
--TEST--
Test jdtounix() function : error conditions
--CREDITS--
edgarsandi - <edgar.r.sandi@gmail.com>
--INI--
date.timezone=UTC
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
var_dump(jdtounix(2440579)) . PHP_EOL;
?>
--EXPECTF--
bool(false)

4
ext/calendar/tests/juliantojd.phpt

@ -9,10 +9,12 @@ echo juliantojd( 1, 1, 1582). "\n";
echo juliantojd(10, 5, 1582). "\n";
echo juliantojd( 1, 1, 1970). "\n";
echo juliantojd( 1, 1, 2999). "\n";
echo juliantojd( 1, 1, -4713). "\n";
?>
--EXPECT--
0
2298884
2299161
2440601
2816443
2816443
0

4
ext/calendar/tests/unixtojd.phpt

@ -30,11 +30,13 @@ putenv('TZ=UTC');
// -this incorrect localtime is passed to the julian date conversion (GregorianToSDN) function which works (probably correctly)
// but returns -1 day from expected because its input is -1 from expected
echo unixtojd(). "\n";
echo unixtojd(40000). "\n";
echo unixtojd(1000000000). "\n";
echo unixtojd(1152459009). "\n";
?>
--EXPECT--
--EXPECTF--
%d
2440588
2452162
2453926

24
ext/calendar/tests/unixtojd_error1.phpt

@ -0,0 +1,24 @@
--TEST--
Test unixtojd() function : error conditions
--CREDITS--
edgarsandi - <edgar.r.sandi@gmail.com>
--SKIPIF--
<?php include 'skipif.inc'; ?>
--INI--
date.timezone=UTC
--FILE--
<?php
putenv('TZ=UTC');
var_dump(unixtojd(-1)) . PHP_EOL;
var_dump(unixtojd(false)) . PHP_EOL;
var_dump(unixtojd(null)) . PHP_EOL;
var_dump(unixtojd(time())) . PHP_EOL;
var_dump(unixtojd(PHP_INT_MAX)) . PHP_EOL;
?>
--EXPECTF--
bool(false)
int(%d)
int(%d)
int(%d)
bool(false)

16
ext/date/tests/cal_days_in_month_invalid_calendar.phpt

@ -1,16 +0,0 @@
--TEST--
cal_days_in_month: test invalid parameter
--CREDITS--
Havard Eide <nucleuz@gmail.com>
#PHPTestFest2009 Norway 2009-06-09 \o/
--SKIPIF--
<?php if (!extension_loaded("calendar")) { echo "skip extension not available"; } ?>
--INI--
date.timezone=UTC
--FILE--
<?php
echo cal_days_in_month(99,0, 2009);
?>
--EXPECTF--
Warning: cal_days_in_month(): invalid calendar ID 99. in %s on line %d

16
ext/date/tests/cal_days_in_month_invalid_date.phpt

@ -1,16 +0,0 @@
--TEST--
cal_days_in_month: test invalid parameter
--CREDITS--
Havard Eide <nucleuz@gmail.com>
#PHPTestFest2009 Norway 2009-06-09 \o/
--SKIPIF--
<?php if (!extension_loaded("calendar")) { echo "skip extension not available"; } ?>
--INI--
date.timezone=UTC
--FILE--
<?php
echo cal_days_in_month(CAL_GREGORIAN,0, 2009);
?>
--EXPECTF--
Warning: cal_days_in_month(): invalid date. in %s on line %d
Loading…
Cancel
Save