Skip to content

Commit a7b1ea3

Browse files
committed
sync with new tests from 7.0 for ICU 55_1 and 56_1 compat
1 parent 6bcf4b4 commit a7b1ea3

10 files changed

+636
-0
lines changed

ext/intl/tests/bug71020.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #71020 (Use after free in Collator::sortWithSortKeys)
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$var_3=new Collator("Whatever");
9+
for($x=0;$x<0xbb;$x++)
10+
$myarray[substr(md5(microtime()),rand(0,26),9) . strval($x)]= substr(md5(microtime()),rand(0,26),9) . strval($x);
11+
$var_3->sortWithSortKeys($myarray);
12+
?>
13+
okey
14+
--EXPECT--
15+
okey
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--TEST--
2+
collator_get_sort_key() icu >= 55.1
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
<?php if (version_compare(INTL_ICU_VERSION, '56.1') >= 0) die('skip for ICU < 56.1'); ?>
6+
<?php if (version_compare(INTL_ICU_VERSION, '55.1') < 0) die('skip for ICU >= 55.1'); ?>
7+
--FILE--
8+
<?php
9+
10+
/*
11+
* Get sort keys using various locales
12+
*/
13+
function sort_arrays( $locale, $data )
14+
{
15+
$res_str = '';
16+
17+
$coll = ut_coll_create( $locale );
18+
19+
foreach($data as $value) {
20+
$res_val = ut_coll_get_sort_key( $coll, $value );
21+
$res_str .= "source: ".$value."\n".
22+
"key: ".bin2hex($res_val)."\n";
23+
}
24+
25+
return $res_str;
26+
}
27+
28+
29+
function ut_main()
30+
{
31+
$res_str = '';
32+
33+
// Regular strings keys
34+
$test_params = array(
35+
'abc', 'abd', 'aaa',
36+
'аа', 'а', 'z',
37+
'', null , '3',
38+
'y' , 'i' , 'k'
39+
);
40+
41+
$res_str .= sort_arrays( 'en_US', $test_params );
42+
43+
// Sort a non-ASCII array using ru_RU locale.
44+
$test_params = array(
45+
'абг', 'абв', 'жжж', 'эюя'
46+
);
47+
48+
$res_str .= sort_arrays( 'ru_RU', $test_params );
49+
50+
// Sort an array using Lithuanian locale.
51+
$res_str .= sort_arrays( 'lt_LT', $test_params );
52+
53+
return $res_str . "\n";
54+
}
55+
56+
include_once( 'ut_common.inc' );
57+
ut_run();
58+
?>
59+
--EXPECT--
60+
source: abc
61+
key: 292b2d01070107
62+
source: abd
63+
key: 292b2f01070107
64+
source: aaa
65+
key: 29292901070107
66+
source: аа
67+
key: 60060601060106
68+
source: а
69+
key: 600601050105
70+
source: z
71+
key: 5b01050105
72+
source:
73+
key: 0101
74+
source:
75+
key: 0101
76+
source: 3
77+
key: 1801050105
78+
source: y
79+
key: 5901050105
80+
source: i
81+
key: 3901050105
82+
source: k
83+
key: 3d01050105
84+
source: абг
85+
key: 26060c1001070107
86+
source: абв
87+
key: 26060c0e01070107
88+
source: жжж
89+
key: 2626262601070107
90+
source: эюя
91+
key: 26b4b6ba01070107
92+
source: абг
93+
key: 60060c1001070107
94+
source: абв
95+
key: 60060c0e01070107
96+
source: жжж
97+
key: 6026262601070107
98+
source: эюя
99+
key: 60b4b6ba01070107
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--TEST--
2+
collator_get_sort_key() icu >= 56.1
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
<?php if (version_compare(INTL_ICU_VERSION, '56.1') < 0) die('skip for ICU >= 56.1'); ?>
6+
--FILE--
7+
<?php
8+
9+
/*
10+
* Get sort keys using various locales
11+
*/
12+
function sort_arrays( $locale, $data )
13+
{
14+
$res_str = '';
15+
16+
$coll = ut_coll_create( $locale );
17+
18+
foreach($data as $value) {
19+
$res_val = ut_coll_get_sort_key( $coll, $value );
20+
$res_str .= "source: ".$value."\n".
21+
"key: ".bin2hex($res_val)."\n";
22+
}
23+
24+
return $res_str;
25+
}
26+
27+
28+
function ut_main()
29+
{
30+
$res_str = '';
31+
32+
// Regular strings keys
33+
$test_params = array(
34+
'abc', 'abd', 'aaa',
35+
'аа', 'а', 'z',
36+
'', null , '3',
37+
'y' , 'i' , 'k'
38+
);
39+
40+
$res_str .= sort_arrays( 'en_US', $test_params );
41+
42+
// Sort a non-ASCII array using ru_RU locale.
43+
$test_params = array(
44+
'абг', 'абв', 'жжж', 'эюя'
45+
);
46+
47+
$res_str .= sort_arrays( 'ru_RU', $test_params );
48+
49+
// Sort an array using Lithuanian locale.
50+
$res_str .= sort_arrays( 'lt_LT', $test_params );
51+
52+
return $res_str . "\n";
53+
}
54+
55+
include_once( 'ut_common.inc' );
56+
ut_run();
57+
?>
58+
--EXPECT--
59+
source: abc
60+
key: 292b2d01070107
61+
source: abd
62+
key: 292b2f01070107
63+
source: aaa
64+
key: 29292901070107
65+
source: аа
66+
key: 60060601060106
67+
source: а
68+
key: 600601050105
69+
source: z
70+
key: 5b01050105
71+
source:
72+
key: 0101
73+
source:
74+
key: 0101
75+
source: 3
76+
key: 1801050105
77+
source: y
78+
key: 5901050105
79+
source: i
80+
key: 3901050105
81+
source: k
82+
key: 3d01050105
83+
source: абг
84+
key: 26060c1001070107
85+
source: абв
86+
key: 26060c0e01070107
87+
source: жжж
88+
key: 262c2c2c01070107
89+
source: эюя
90+
key: 26eef0f401070107
91+
source: абг
92+
key: 60060c1001070107
93+
source: абв
94+
key: 60060c0e01070107
95+
source: жжж
96+
key: 602c2c2c01070107
97+
source: эюя
98+
key: 60eef0f401070107
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
IntlDateFormatter::formatObject(): IntlCalendar tests
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
6+
<?php if (version_compare(INTL_ICU_VERSION, '55.1') < 0) die('skip for ICU >= 55.1'); ?>
7+
--FILE--
8+
<?php
9+
ini_set("intl.error_level", E_WARNING);
10+
ini_set("intl.default_locale", "pt_PT");
11+
ini_set("date.timezone", "Europe/Lisbon");
12+
13+
$cal = IntlCalendar::fromDateTime('2012-01-01 00:00:00'); //Europe/Lisbon
14+
echo IntlDateFormatter::formatObject($cal), "\n";
15+
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
16+
echo IntlDateFormatter::formatObject($cal, null, "en-US"), "\n";
17+
echo IntlDateFormatter::formatObject($cal, array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL), "en-US"), "\n";
18+
echo IntlDateFormatter::formatObject($cal, 'E y-MM-d HH,mm,ss.SSS v', "en-US"), "\n";
19+
20+
$cal = IntlCalendar::fromDateTime('2012-01-01 05:00:00+03:00');
21+
echo datefmt_format_object($cal, IntlDateFormatter::FULL), "\n";
22+
23+
$cal = IntlCalendar::createInstance(null,'en-US@calendar=islamic-civil');
24+
$cal->setTime(strtotime('2012-01-01 00:00:00')*1000.);
25+
echo IntlDateFormatter::formatObject($cal), "\n";
26+
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL, "en-US"), "\n";
27+
28+
?>
29+
==DONE==
30+
31+
--EXPECTF--
32+
01/01/2012, 00:00:00
33+
domingo, 1 de janeiro de 2012 às 00:00:00 Hora padrão %Sda Europa Ocidental
34+
Jan 1, 2012, 12:00:00 AM
35+
1/1/12, 12:00:00 AM Western European Standard %STime
36+
Sun 2012-01-1 00,00,00.000 Portugal Time
37+
domingo, 1 de janeiro de 2012 às 05:00:00 GMT+03:00
38+
06/02/1433, 00:00:00
39+
Sunday, Safar 6, 1433 at 12:00:00 AM Western European Standard Time
40+
==DONE==
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
IntlDateFormatter::formatObject(): DateTime tests
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
6+
<?php if (version_compare(INTL_ICU_VERSION, '55.1') < 0) die('skip for ICU >= 55.1'); ?>
7+
--FILE--
8+
<?php
9+
ini_set("intl.error_level", E_WARNING);
10+
ini_set("intl.default_locale", "pt_PT");
11+
ini_set("date.timezone", "Europe/Lisbon");
12+
13+
$dt = new DateTime('2012-01-01 00:00:00'); //Europe/Lisbon
14+
echo IntlDateFormatter::formatObject($dt), "\n";
15+
echo IntlDateFormatter::formatObject($dt, IntlDateFormatter::FULL), "\n";
16+
echo IntlDateFormatter::formatObject($dt, null, "en-US"), "\n";
17+
echo IntlDateFormatter::formatObject($dt, array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL), "en-US"), "\n";
18+
echo IntlDateFormatter::formatObject($dt, 'E y-MM-d HH,mm,ss.SSS v', "en-US"), "\n";
19+
20+
$dt = new DateTime('2012-01-01 05:00:00+03:00');
21+
echo IntlDateFormatter::formatObject($dt, IntlDateFormatter::FULL), "\n";
22+
23+
?>
24+
==DONE==
25+
26+
--EXPECTF--
27+
01/01/2012, 00:00:00
28+
domingo, 1 de janeiro de 2012 às 00:00:00 Hora padrão %Sda Europa Ocidental
29+
Jan 1, 2012, 12:00:00 AM
30+
1/1/12, 12:00:00 AM Western European Standard %STime
31+
Sun 2012-01-1 00,00,00.000 Portugal Time
32+
domingo, 1 de janeiro de 2012 às 05:00:00 GMT+03:00
33+
==DONE==
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
IntlDateFormatter: get/setTimeZone()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
6+
<?php if (version_compare(INTL_ICU_VERSION, '55.1') < 0) die('skip for ICU >= 55.1'); ?>
7+
--FILE--
8+
<?php
9+
ini_set("intl.error_level", E_WARNING);
10+
ini_set("intl.default_locale", "pt_PT");
11+
ini_set("date.timezone", 'Atlantic/Azores');
12+
13+
$ts = strtotime('2012-01-01 00:00:00 UTC');
14+
15+
function d(IntlDateFormatter $df) {
16+
global $ts;
17+
echo $df->format($ts), "\n";
18+
var_dump(
19+
$df->getTimeZoneID(),
20+
$df->getTimeZone()->getID());
21+
echo "\n";
22+
}
23+
24+
$df = new IntlDateFormatter('pt_PT', 0, 0, 'Europe/Minsk');
25+
d($df);
26+
27+
$df->setTimeZone(NULL);
28+
d($df);
29+
30+
$df->setTimeZone('Europe/Madrid');
31+
d($df);
32+
33+
$df->setTimeZone(IntlTimeZone::createTimeZone('Europe/Paris'));
34+
d($df);
35+
36+
$df->setTimeZone(new DateTimeZone('Europe/Amsterdam'));
37+
d($df);
38+
39+
?>
40+
==DONE==
41+
--EXPECTF--
42+
domingo, 1 de janeiro de 2012 às 03:00:00 Hor%s do Extremo Leste da Europa
43+
string(12) "Europe/Minsk"
44+
string(12) "Europe/Minsk"
45+
46+
sábado, 31 de dezembro de 2011 às 23:00:00 Hor%s padrão %Sdos Açores
47+
string(15) "Atlantic/Azores"
48+
string(15) "Atlantic/Azores"
49+
50+
domingo, 1 de janeiro de 2012 às 01:00:00 Hor%s padrão %Sda Europa Central
51+
string(13) "Europe/Madrid"
52+
string(13) "Europe/Madrid"
53+
54+
domingo, 1 de janeiro de 2012 às 01:00:00 Hor%s padrão %Sda Europa Central
55+
string(12) "Europe/Paris"
56+
string(12) "Europe/Paris"
57+
58+
domingo, 1 de janeiro de 2012 às 01:00:00 Hor%s padrão %Sda Europa Central
59+
string(16) "Europe/Amsterdam"
60+
string(16) "Europe/Amsterdam"
61+
62+
==DONE==

0 commit comments

Comments
 (0)