1--TEST--
2numfmt_get/set_symbol() icu >= 4.8
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5<?php if(version_compare(INTL_ICU_VERSION, '4.8') < 0) print 'skip'; ?>
6<?php if (PHP_INT_SIZE != 8) die('skip 64-bit only'); ?>
7--FILE--
8<?php
9
10/*
11 * Get/set symbol.
12 */
13
14
15function ut_main()
16{
17	$longstr = str_repeat("blah", 10);
18    $symbols = array(
19        'DECIMAL_SEPARATOR_SYMBOL' => array( NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, '_._', 12345.123456, NumberFormatter::DECIMAL ),
20        'GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '_,_', 12345.123456, NumberFormatter::DECIMAL ),
21        'PATTERN_SEPARATOR_SYMBOL' => array( NumberFormatter::PATTERN_SEPARATOR_SYMBOL, '_;_', 12345.123456, NumberFormatter::DECIMAL ),
22        'PERCENT_SYMBOL' => array( NumberFormatter::PERCENT_SYMBOL, '_%_', 12345.123456, NumberFormatter::PERCENT ),
23        'ZERO_DIGIT_SYMBOL' => array( NumberFormatter::ZERO_DIGIT_SYMBOL, '_ZD_', 12345.123456, NumberFormatter::DECIMAL ),
24        'DIGIT_SYMBOL' => array( NumberFormatter::DIGIT_SYMBOL, '_DS_', 12345.123456, NumberFormatter::DECIMAL ),
25        'MINUS_SIGN_SYMBOL' => array( NumberFormatter::MINUS_SIGN_SYMBOL, '_-_', -12345.123456, NumberFormatter::DECIMAL ),
26        'PLUS_SIGN_SYMBOL' => array( NumberFormatter::PLUS_SIGN_SYMBOL, '_+_', 12345.123456, NumberFormatter::SCIENTIFIC ),
27        'CURRENCY_SYMBOL' => array( NumberFormatter::CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ),
28        'INTL_CURRENCY_SYMBOL' => array( NumberFormatter::INTL_CURRENCY_SYMBOL, '_$_', 12345.123456, NumberFormatter::CURRENCY ),
29        'MONETARY_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_SEPARATOR_SYMBOL, '_MS_', 12345.123456, NumberFormatter::CURRENCY ),
30        'EXPONENTIAL_SYMBOL' => array( NumberFormatter::EXPONENTIAL_SYMBOL, '_E_', 12345.123456, NumberFormatter::SCIENTIFIC ),
31        'PERMILL_SYMBOL' => array( NumberFormatter::PERMILL_SYMBOL, '_PS_', 12345.123456, NumberFormatter::DECIMAL ),
32        'PAD_ESCAPE_SYMBOL' => array( NumberFormatter::PAD_ESCAPE_SYMBOL, '_PE_', 12345.123456, NumberFormatter::DECIMAL ),
33        'INFINITY_SYMBOL' => array( NumberFormatter::INFINITY_SYMBOL, '_IS_', 12345.123456, NumberFormatter::DECIMAL ),
34        'NAN_SYMBOL' => array( NumberFormatter::NAN_SYMBOL, '_N_', 12345.123456, NumberFormatter::DECIMAL ),
35        'SIGNIFICANT_DIGIT_SYMBOL' => array( NumberFormatter::SIGNIFICANT_DIGIT_SYMBOL, '_SD_', 12345.123456, NumberFormatter::DECIMAL ),
36        'MONETARY_GROUPING_SEPARATOR_SYMBOL' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, '_MG_', 12345.123456, NumberFormatter::CURRENCY ),
37	'MONETARY_GROUPING_SEPARATOR_SYMBOL-2' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, "&nbsp;", 12345.123456, NumberFormatter::CURRENCY ),
38	'MONETARY_GROUPING_SEPARATOR_SYMBOL-3' => array( NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $longstr, 12345.123456, NumberFormatter::CURRENCY ),
39    );
40
41    $res_str = '';
42
43    foreach( $symbols as $symb_name => $data )
44    {
45        list( $symb, $new_val, $number, $attr ) = $data;
46
47        $fmt = ut_nfmt_create( 'en_US', $attr);
48
49        $res_str .= "\nSymbol '$symb_name'\n";
50
51        // Get original symbol value.
52        $orig_val = ut_nfmt_get_symbol( $fmt, $symb );
53        $res_str .= "Default symbol: [$orig_val]\n";
54
55        // Set a new symbol value.
56        $res_val = ut_nfmt_set_symbol( $fmt, $symb, $new_val );
57        if( !$res_val )
58            $res_str .= "set_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
59
60        // Get the symbol value back.
61        $new_val_check = ut_nfmt_get_symbol( $fmt, $symb );
62        if( !$new_val_check )
63            $res_str .= "get_symbol() error: " . ut_nfmt_get_error_message( $fmt ) . "\n";
64
65        $res_str .= "New symbol: [$new_val_check]\n";
66
67        // Check if the new value has been set.
68        if( $new_val_check !== $new_val )
69            $res_str .= "ERROR: New $symb_name symbol value has not been set correctly.\n";
70
71        // Format the number using the new value.
72        $s = ut_nfmt_format( $fmt, $number );
73        $res_str .= "A number formatted with the new symbol: $s\n";
74
75        // Restore attribute's symbol.
76        ut_nfmt_set_symbol( $fmt, $symb, $orig_val );
77    }
78    $badvals = array(2147483648, -2147483648, -1, 4294901761);
79    foreach($badvals as $badval) {
80	    if(ut_nfmt_get_symbol( $fmt, 2147483648 ))  {
81		$res_str .= "Bad value $badval should return false!\n";
82	    }
83    }
84    return $res_str;
85}
86
87include_once( 'ut_common.inc' );
88ut_run();
89
90?>
91--EXPECTF--
92Symbol 'DECIMAL_SEPARATOR_SYMBOL'
93Default symbol: [.]
94New symbol: [_._]
95A number formatted with the new symbol: 12,345_._123
96
97Symbol 'GROUPING_SEPARATOR_SYMBOL'
98Default symbol: [,]
99New symbol: [_,_]
100A number formatted with the new symbol: 12_,_345.123
101
102Symbol 'PATTERN_SEPARATOR_SYMBOL'
103Default symbol: [;]
104New symbol: [_;_]
105A number formatted with the new symbol: 12,345.123
106
107Symbol 'PERCENT_SYMBOL'
108Default symbol: [%]
109New symbol: [_%_]
110A number formatted with the new symbol: 1,234,512_%_
111
112Symbol 'ZERO_DIGIT_SYMBOL'
113Default symbol: [0]
114New symbol: [_ZD_]
115A number formatted with the new symbol: 12,345.123
116
117Symbol 'DIGIT_SYMBOL'
118Default symbol: [#]
119New symbol: [_DS_]
120A number formatted with the new symbol: 12,345.123
121
122Symbol 'MINUS_SIGN_SYMBOL'
123Default symbol: [-]
124New symbol: [_-_]
125A number formatted with the new symbol: _-_12,345.123
126
127Symbol 'PLUS_SIGN_SYMBOL'
128Default symbol: [+]
129New symbol: [_+_]
130A number formatted with the new symbol: 1.2345123456E4
131
132Symbol 'CURRENCY_SYMBOL'
133Default symbol: [$]
134New symbol: [_$_]
135A number formatted with the new symbol: _$_%A12,345.12
136
137Symbol 'INTL_CURRENCY_SYMBOL'
138Default symbol: [USD]
139New symbol: [_$_]
140A number formatted with the new symbol: $12,345.12
141
142Symbol 'MONETARY_SEPARATOR_SYMBOL'
143Default symbol: [.]
144New symbol: [_MS_]
145A number formatted with the new symbol: $12,345_MS_12
146
147Symbol 'EXPONENTIAL_SYMBOL'
148Default symbol: [E]
149New symbol: [_E_]
150A number formatted with the new symbol: 1.2345123456_E_4
151
152Symbol 'PERMILL_SYMBOL'
153Default symbol: [‰]
154New symbol: [_PS_]
155A number formatted with the new symbol: 12,345.123
156
157Symbol 'PAD_ESCAPE_SYMBOL'
158Default symbol: [*]
159New symbol: [_PE_]
160A number formatted with the new symbol: 12,345.123
161
162Symbol 'INFINITY_SYMBOL'
163Default symbol: [∞]
164New symbol: [_IS_]
165A number formatted with the new symbol: 12,345.123
166
167Symbol 'NAN_SYMBOL'
168Default symbol: [NaN]
169New symbol: [_N_]
170A number formatted with the new symbol: 12,345.123
171
172Symbol 'SIGNIFICANT_DIGIT_SYMBOL'
173Default symbol: [@]
174New symbol: [_SD_]
175A number formatted with the new symbol: 12,345.123
176
177Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL'
178Default symbol: [,]
179New symbol: [_MG_]
180A number formatted with the new symbol: $12_MG_345.12
181
182Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-2'
183Default symbol: [,]
184New symbol: [&nbsp;]
185A number formatted with the new symbol: $12&nbsp;345.12
186
187Symbol 'MONETARY_GROUPING_SEPARATOR_SYMBOL-3'
188Default symbol: [,]
189New symbol: [blahblahblahblahblahblahblahblahblahblah]
190A number formatted with the new symbol: $12blahblahblahblahblahblahblahblahblahblah345.12
191