com php-src: pull-request/2456: increase test coverage in calendar extension consistent warnings in calendar extension: ext/calendar/calendar.c ext/calendar/tests/cal_days_in_mo nth_error1.phpt ext/calendar/tests/cal_from_jd_er ror1.phpt ext/calendar/tests/cal_info.phpt ext/cale ndar/tests/cal_to_jd_error1.phpt ext/calendar/tests /gregoriantojd.phpt ext/calendar/tests/jdtogregorian.phpt ext/calendar/tests/jdtojewish.phpt ext/calendar/tests/jd

[email protected] (Joe Watkins)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    ebdbebee298a86ddddf922e2e817f101fdea4edb
Author:    Edgar R. Sandi <[email protected]>         Sat, 1 Apr 2017 01:26:09 -0300
Committer: Joe Watkins <[email protected]>      Sat, 8 Apr 2017 11:37:10 +0100
Parents:   345cf5ea6c167579fe61f2215c84c87cfd1e4e5d
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=ebdbebee298a86ddddf922e2e817f101fdea4edb

Log:
pull-request/2456:
    increase test coverage in calendar extension
    consistent warnings in calendar extension

Changed paths:
  M  ext/calendar/calendar.c
  A  ext/calendar/tests/cal_days_in_month_error1.phpt
  A  ext/calendar/tests/cal_from_jd_error1.phpt
  M  ext/calendar/tests/cal_info.phpt
  A  ext/calendar/tests/cal_to_jd_error1.phpt
  M  ext/calendar/tests/gregoriantojd.phpt
  M  ext/calendar/tests/jdtogregorian.phpt
  M  ext/calendar/tests/jdtojewish.phpt
  M  ext/calendar/tests/jdtojulian.phpt
  A  ext/calendar/tests/jdtounix_error1.phpt
  M  ext/calendar/tests/juliantojd.phpt
  M  ext/calendar/tests/unixtojd.phpt
  A  ext/calendar/tests/unixtojd_error1.phpt
  D  ext/date/tests/cal_days_in_month_invalid_calendar.phpt
  D  ext/date/tests/cal_days_in_month_invalid_date.phpt
diff_ebdbebee298a86ddddf922e2e817f101fdea4edb.txt (text/plain, 10.2 KB)
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index c00507d..d6df68c 100644
--- a/ext/calendar/calendar.c
+++ b/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;
 		}
 
diff --git a/ext/calendar/tests/cal_days_in_month_error1.phpt b/ext/calendar/tests/cal_days_in_month_error1.phpt
new file mode 100644
index 0000000..c413a81
--- /dev/null
+++ b/ext/calendar/tests/cal_days_in_month_error1.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test cal_days_in_month() function : error conditions
+--CREDITS--
+edgarsandi - <[email protected]>
+--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)
\ No newline at end of file
diff --git a/ext/calendar/tests/cal_from_jd_error1.phpt b/ext/calendar/tests/cal_from_jd_error1.phpt
new file mode 100644
index 0000000..1d2cf39
--- /dev/null
+++ b/ext/calendar/tests/cal_from_jd_error1.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test cal_from_jd() function : error conditions
+--CREDITS--
+edgarsandi - <[email protected]>
+--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)
\ No newline at end of file
diff --git a/ext/calendar/tests/cal_info.phpt b/ext/calendar/tests/cal_info.phpt
index 7edb4ce..68f31c1 100644
--- a/ext/calendar/tests/cal_info.phpt
+++ b/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
diff --git a/ext/calendar/tests/cal_to_jd_error1.phpt b/ext/calendar/tests/cal_to_jd_error1.phpt
new file mode 100644
index 0000000..9bee065
--- /dev/null
+++ b/ext/calendar/tests/cal_to_jd_error1.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test cal_to_jd() function : error conditions
+--CREDITS--
+edgarsandi - <[email protected]>
+--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)
\ No newline at end of file
diff --git a/ext/calendar/tests/gregoriantojd.phpt b/ext/calendar/tests/gregoriantojd.phpt
index ec3628e..1a3d0f1 100644
--- a/ext/calendar/tests/gregoriantojd.phpt
+++ b/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
\ No newline at end of file
+2816423
+0
+0
\ No newline at end of file
diff --git a/ext/calendar/tests/jdtogregorian.phpt b/ext/calendar/tests/jdtogregorian.phpt
index 6b1956f..b882d5f 100644
--- a/ext/calendar/tests/jdtogregorian.phpt
+++ b/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
diff --git a/ext/calendar/tests/jdtojewish.phpt b/ext/calendar/tests/jdtojewish.phpt
index bc0ecbd..78efd2a 100644
--- a/ext/calendar/tests/jdtojewish.phpt
+++ b/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
\ No newline at end of file
diff --git a/ext/calendar/tests/jdtojulian.phpt b/ext/calendar/tests/jdtojulian.phpt
index 6c87aa7..2f8f4aa 100644
--- a/ext/calendar/tests/jdtojulian.phpt
+++ b/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
diff --git a/ext/calendar/tests/jdtounix_error1.phpt b/ext/calendar/tests/jdtounix_error1.phpt
new file mode 100644
index 0000000..2d54cf2
--- /dev/null
+++ b/ext/calendar/tests/jdtounix_error1.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test jdtounix() function : error conditions
+--CREDITS--
+edgarsandi - <[email protected]>
+--INI--
+date.timezone=UTC
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+var_dump(jdtounix(2440579)) . PHP_EOL;
+?>
+--EXPECTF--
+bool(false)
\ No newline at end of file
diff --git a/ext/calendar/tests/juliantojd.phpt b/ext/calendar/tests/juliantojd.phpt
index 9563e04..c9ba395 100644
--- a/ext/calendar/tests/juliantojd.phpt
+++ b/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
\ No newline at end of file
+2816443
+0
\ No newline at end of file
diff --git a/ext/calendar/tests/unixtojd.phpt b/ext/calendar/tests/unixtojd.phpt
index 6183cae..01b3773 100644
--- a/ext/calendar/tests/unixtojd.phpt
+++ b/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
diff --git a/ext/calendar/tests/unixtojd_error1.phpt b/ext/calendar/tests/unixtojd_error1.phpt
new file mode 100644
index 0000000..b19bcd6
--- /dev/null
+++ b/ext/calendar/tests/unixtojd_error1.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test unixtojd() function : error conditions
+--CREDITS--
+edgarsandi - <[email protected]>
+--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)
\ No newline at end of file
diff --git a/ext/date/tests/cal_days_in_month_invalid_calendar.phpt b/ext/date/tests/cal_days_in_month_invalid_calendar.phpt
deleted file mode 100644
index 3550b91..0000000
--- a/ext/date/tests/cal_days_in_month_invalid_calendar.phpt
+++ /dev/null
@@ -1,16 +0,0 @@
---TEST--
-cal_days_in_month: test invalid parameter
---CREDITS--
-Havard Eide <[email protected]>
-#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
-
diff --git a/ext/date/tests/cal_days_in_month_invalid_date.phpt b/ext/date/tests/cal_days_in_month_invalid_date.phpt
deleted file mode 100644
index 0315270..0000000
--- a/ext/date/tests/cal_days_in_month_invalid_date.phpt
+++ /dev/null
@@ -1,16 +0,0 @@
---TEST--
-cal_days_in_month: test invalid parameter
---CREDITS--
-Havard Eide <[email protected]>
-#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
-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.