]> granicus.if.org Git - php/commitdiff
pull-request/2456:
authorEdgar R. Sandi <edgar.r.sandi@gmail.com>
Sat, 1 Apr 2017 04:26:09 +0000 (01:26 -0300)
committerJoe Watkins <krakjoe@php.net>
Sat, 8 Apr 2017 10:37:10 +0000 (11:37 +0100)
    increase test coverage in calendar extension
    consistent warnings in calendar extension

15 files changed:
ext/calendar/calendar.c
ext/calendar/tests/cal_days_in_month_error1.phpt [new file with mode: 0644]
ext/calendar/tests/cal_from_jd_error1.phpt [new file with mode: 0644]
ext/calendar/tests/cal_info.phpt
ext/calendar/tests/cal_to_jd_error1.phpt [new file with mode: 0644]
ext/calendar/tests/gregoriantojd.phpt
ext/calendar/tests/jdtogregorian.phpt
ext/calendar/tests/jdtojewish.phpt
ext/calendar/tests/jdtojulian.phpt
ext/calendar/tests/jdtounix_error1.phpt [new file with mode: 0644]
ext/calendar/tests/juliantojd.phpt
ext/calendar/tests/unixtojd.phpt
ext/calendar/tests/unixtojd_error1.phpt [new file with mode: 0644]
ext/date/tests/cal_days_in_month_invalid_calendar.phpt [deleted file]
ext/date/tests/cal_days_in_month_invalid_date.phpt [deleted file]

index c00507d86aa4ea3ee0c0f30a402de77b731d3ae7..d6df68cebbf061b355b64dfdbe1cbd7f9920d41b 100644 (file)
@@ -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 (file)
index 0000000..c413a81
--- /dev/null
@@ -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)
\ 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 (file)
index 0000000..1d2cf39
--- /dev/null
@@ -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)
\ No newline at end of file
index 7edb4ce67ca7906049ab09d26c91dc97fe32023a..68f31c16dad1f7595b7719b762b671112bcbaa32 100644 (file)
@@ -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 (file)
index 0000000..9bee065
--- /dev/null
@@ -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)
\ No newline at end of file
index ec3628e899631fcaaa9481857fce27b41cb424fa..1a3d0f17124cc155b5ff5cb867e3e85577497139 100644 (file)
@@ -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
index 6b1956f477a674946c35971bd2942b3efec9ac8f..b882d5f08d7f9802ca46614679f514527ea87142 100644 (file)
@@ -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
index bc0ecbdd88ec27ed21cda590697c96b24c446159..78efd2a3e4499e7ba107536b019ce7153194141e 100644 (file)
@@ -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
index 6c87aa7e54a5e55b2164aa5c065f664d19cb5f79..2f8f4aa937a82e08ebb5f2e3daa0a1264e4330d5 100644 (file)
@@ -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 (file)
index 0000000..2d54cf2
--- /dev/null
@@ -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)
\ No newline at end of file
index 9563e041a16e245db791956f6c22969c849e82a5..c9ba3955d0aaffe01de1f224457bfe4daf0de690 100644 (file)
@@ -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
index 6183cae9eef98034f285163aa4ba0f73abdc5601..01b3773007e9eb237fca99593898ece5f4d11dd0 100644 (file)
@@ -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 (file)
index 0000000..b19bcd6
--- /dev/null
@@ -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)
\ 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 (file)
index 3550b91..0000000
+++ /dev/null
@@ -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
-
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 (file)
index 0315270..0000000
+++ /dev/null
@@ -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
-