Java
=>
'DATA'
) ;
BEGIN {
plan(
tests
=> 102) ;
}
my
$t
= new types2() ;
{
my
$max
=
undef
;
my
$min
=
undef
;
$max
= 127 ;
$min
= -128 ;
ok(
$t
->_byte(
undef
) == 1) ;
ok(
$t
->_byte(0) == 1) ;
ok(
$t
->_byte(
$max
- 1) ==
$max
) ;
ok(
$t
->_byte(
"$min"
) ==
$min
+ 1) ;
eval
{
$t
->_byte(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_byte(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
ok(
$t
->_Byte(
undef
) == 0) ;
ok(
$t
->_Byte(0) == 0) ;
ok(
$t
->_Byte(
$max
) ==
$max
) ;
ok(
$t
->_Byte(
"$min"
) ==
$min
) ;
eval
{
$t
->_Byte(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_Byte(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
$max
= 32767 ;
$min
= -32768 ;
ok(
$t
->_short(
undef
) == 1) ;
ok(
$t
->_short(0) == 1) ;
ok(
$t
->_short(
$max
- 1) ==
$max
) ;
ok(
$t
->_short(
"$min"
) ==
$min
+ 1) ;
eval
{
$t
->_short(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_short(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
ok(
$t
->_Short(
undef
) == 0) ;
ok(
$t
->_Short(0) == 0) ;
ok(
$t
->_Short(
$max
) ==
$max
) ;
ok(
$t
->_Short(
"$min"
) ==
$min
) ;
eval
{
$t
->_Short(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_Short(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
$max
= 2147483647 ;
$min
= -2147483648 ;
ok(
$t
->_int(
undef
) == 1) ;
ok(
$t
->_int(0) == 1) ;
ok(
$t
->_int(
$max
- 1) ==
$max
) ;
ok(
$t
->_int(
"$min"
) ==
$min
+ 1) ;
eval
{
$t
->_int(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_int(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
ok(
$t
->_Integer(
undef
) == 0) ;
ok(
$t
->_Integer(0) == 0) ;
ok(
$t
->_Integer(
$max
) ==
$max
) ;
ok(
$t
->_Integer(
"$min"
) ==
$min
) ;
eval
{
$t
->_Integer(
$max
+ 1)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_Integer(
$min
- 1)} ; ok($@,
qr/out of range/
) ;
$max
= 3.4028235e38 ;
$min
= -3.4028235e38 ;
ok(
$t
->_float(
undef
) == 1) ;
ok(
$t
->_float(0) == 1) ;
ok(
$t
->_float(
$max
/ 2)) ;
ok(
$t
->_float(
$min
/ 2)) ;
ok(
$t
->_float(
$max
- 1)) ;
ok(
$t
->_float(
"$min"
)) ;
eval
{
$t
->_float(
$max
+
$max
)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_float(
$min
+
$min
)} ; ok($@,
qr/out of range/
) ;
ok(
$t
->_Float(
undef
) == 0) ;
ok(
$t
->_Float(0) == 0) ;
ok(
$t
->_Float(
$max
/ 2)) ;
ok(
$t
->_Float(
$min
/ 2)) ;
ok(
$t
->_Float(
$max
)) ;
ok(
$t
->_Float(
"$min"
)) ;
eval
{
$t
->_Float(
$max
+
$max
)} ; ok($@,
qr/out of range/
) ;
eval
{
$t
->_Float(
$min
+
$min
)} ; ok($@,
qr/out of range/
) ;
my
$val
= 123456 ;
ok(
$t
->_long(
undef
) == 1) ;
ok(
$t
->_long(0) == 1) ;
ok(
$t
->_long(
$val
- 1) ==
$val
) ;
ok(
$t
->_long(
"-$val"
) == -
$val
+ 1) ;
ok(
$t
->_Long(
undef
) == 0) ;
ok(
$t
->_Long(0) == 0) ;
ok(
$t
->_Long(
$val
) ==
$val
) ;
ok(
$t
->_Long(
"-$val"
) == -
$val
) ;
$val
= 123456.789 ;
ok(
$t
->_double(
undef
) == 1) ;
ok(
$t
->_double(0) == 1) ;
ok(
$t
->_double(
$val
- 1) ==
$val
) ;
ok(
$t
->_double(
"-$val"
) == -
$val
+ 1) ;
ok(
$t
->_Double(
undef
) == 0) ;
ok(
$t
->_Double(0) == 0) ;
ok(
$t
->_Double(
$val
) ==
$val
) ;
ok(
$t
->_Double(
"-$val"
) == -
$val
) ;
ok(
$t
->_Number(
undef
) == 0) ;
ok(
$t
->_Number(0) == 0) ;
ok(
$t
->_Number(
$val
) ==
$val
) ;
ok(
$t
->_Number(
"-$val"
) == -
$val
) ;
ok(!
$t
->_boolean(
undef
)) ;
ok(!
$t
->_boolean(0)) ;
ok(!
$t
->_boolean(
""
)) ;
ok(
$t
->_boolean(
"true"
)) ;
ok(
$t
->_boolean(1)) ;
ok(!
$t
->_Boolean(
undef
)) ;
ok(!
$t
->_Boolean(0)) ;
ok(!
$t
->_Boolean(
""
)) ;
ok(
$t
->_Boolean(
"true"
)) ;
ok(
$t
->_Boolean(1)) ;
ok(
$t
->_char(
undef
),
"\0"
) ;
ok(
$t
->_char(0),
"0"
) ;
ok(
$t
->_char(
"1"
),
'1'
) ;
eval
{
$t
->_char(
"10"
)} ; ok($@,
qr/Can't convert/
) ;
ok(
$t
->_Character(
undef
),
"\0"
) ;
ok(
$t
->_Character(0),
"0"
) ;
ok(
$t
->_Character(
"1"
),
'1'
) ;
eval
{
$t
->_Character(
"10"
)} ; ok($@,
qr/Can't convert/
) ;
ok(
$t
->_String(
undef
),
undef
) ;
ok(
$t
->_String(0),
"0"
) ;
ok(
$t
->_String(
"string"
),
'string'
) ;
my
$str
=
"\r\n&&&\r\n\ntre gfd gf$$ b F D&a;t% R f &p;vf\r\r"
;
ok(
$t
->_String(
$str
),
$str
) ;
ok(
$t
->_StringBuffer(
undef
),
undef
) ;
ok(
$t
->_StringBuffer(0),
"0"
) ;
ok(
$t
->_StringBuffer(
"stringbuffer"
),
'stringbuffer'
) ;
ok(
$t
->_Object(
undef
),
undef
) ;
ok(
$t
->_Object(0),
"0"
) ;
ok(
$t
->_Object(666) == 666) ;
ok(
$t
->_Object(
"object"
),
'object'
) ;
}
ok(
$t
->__get_private()->{proto}->ObjectCount(), 1) ;