Convert-Binary-C
view release on metacpan or search on metacpan
tests/201_config.t view on Meta::CPAN
{ in => 9, result => FAIL },
{ in => 10, result => FAIL },
{ in => 11, result => FAIL },
{ in => 12, result => SUCCEED },
{ in => 13, result => FAIL },
{ in => 14, result => FAIL },
{ in => 15, result => FAIL },
{ in => 16, result => SUCCEED },
{ in => 17, result => FAIL },
@refs
);
check_config( $_, @tests ) for qw( FloatSize
DoubleSize
LongDoubleSize );
@tests = (
{ in => -1, result => FAIL },
{ in => 0, result => SUCCEED },
{ in => 1, result => SUCCEED },
{ in => 2, result => SUCCEED },
{ in => 3, result => FAIL },
{ in => 4, result => SUCCEED },
{ in => 5, result => FAIL },
{ in => 6, result => FAIL },
{ in => 7, result => FAIL },
{ in => 8, result => SUCCEED },
{ in => 9, result => FAIL },
{ in => 10, result => FAIL },
{ in => 11, result => FAIL },
{ in => 12, result => FAIL },
{ in => 13, result => FAIL },
{ in => 14, result => FAIL },
{ in => 15, result => FAIL },
{ in => 16, result => SUCCEED },
{ in => 17, result => FAIL },
@refs
);
check_config( $_, @tests ) for qw( Alignment CompoundAlignment );
check_config( 'ByteOrder',
{ in => 'BigEndian', result => SUCCEED },
{ in => 'LittleEndian', result => SUCCEED },
{ in => 'NoEndian', result => FAIL },
@refs
);
check_config( 'EnumType',
{ in => 'Integer', result => SUCCEED },
{ in => 'String', result => SUCCEED },
{ in => 'Both', result => SUCCEED },
{ in => 'None', result => FAIL },
@refs
);
check_config_bool( $_ ) for qw( UnsignedBitfields
UnsignedChars
Warnings
HasCPPComments
HasMacroVAARGS );
check_option_strlist( $_ ) for qw( Include
Define
Assert
DisabledKeywords );
check_option_strlist_args( $_ ) for qw( Include
Define
Assert);
{
my @warn;
eval { require Tie::Hash::Indexed };
$@ and eval { require Tie::IxHash };
$@ and push @warn, qr/^Couldn't load a module for member ordering.*$thisfile/;
@tests = (
{ in => 0, out => 0, result => SUCCEED, warnings => [] },
{ in => 1, out => 1, result => SUCCEED, warnings => \@warn },
{ in => 4711, out => 1, result => SUCCEED, warnings => \@warn },
{ in => -42, out => 1, result => SUCCEED, warnings => \@warn },
@refs
);
check_config( 'OrderMembers', @tests );
}
#===================================================================
# check DisabledKeywords option
#===================================================================
eval {
$p = Convert::Binary::C->new;
$p->configure( DisabledKeywords => ['void', 'foo', 'const'] );
};
ok( $@, qr/Cannot disable unknown keyword 'foo'.*$thisfile/ );
eval {
$p = Convert::Binary::C->new;
$p->DisabledKeywords( 'void', 'foo', 'const' );
};
ok( $@, qr/DisabledKeywords cannot take more than one argument.*$thisfile/ );
eval {
$p = Convert::Binary::C->new;
$p->DisabledKeywords( ['auto', 'enum'] );
$p->DisabledKeywords( ['void', 'while', 'register'] );
};
ok( $@, qr/Cannot disable unknown keyword 'while'.*$thisfile/ );
$kw = $p->DisabledKeywords;
ok( "@$kw", "auto enum", 'DisabledKeywords did not preserve configuration' );
#===================================================================
# check KeywordMap option
#===================================================================
eval {
$p = Convert::Binary::C->new;
$p->configure( KeywordMap => 5 );
tests/201_config.t view on Meta::CPAN
#===================================================================
# check invalid configuration
#===================================================================
@tests = (
{ value => [1, 2, 3], result => FAIL, error => qr/Invalid number of arguments to configure.*$thisfile/ },
{ value => [[1], 2], result => FAIL, error => qr/Option name must be a string, not a reference.*$thisfile/ },
);
foreach $config ( @tests )
{
eval {
$p = Convert::Binary::C->new;
$p->configure( @{$config->{value}} );
};
ok( ($@ eq '' ? SUCCEED : FAIL), $config->{result},
"invalid configuration: " . join(', ', @{$config->{value}}) );
ok( $@, $config->{error} ) if exists $config->{error};
}
#===================================================================
# check invalid option
#===================================================================
eval {
$p = Convert::Binary::C->new;
$p->configure(
Something => 'xxx',
ByteOrder => 'BigEndian',
EnumSize => 0,
);
};
ok( $@, qr/Invalid option 'Something'.*$thisfile/ );
#===================================================================
# check invalid method
#===================================================================
eval {
$p = Convert::Binary::C->new;
$p->some_method( 1, 2, 3 );
};
ok( $@, qr/Invalid method some_method called.*$thisfile/ );
#===================================================================
# check configure returning the whole configuration
#===================================================================
%config = (
'KeywordMap' => {},
'DisabledKeywords' => [],
'UnsignedBitfields' => 0,
'UnsignedChars' => 0,
'CharSize' => 1,
'ShortSize' => 2,
'EnumType' => 'Integer',
'EnumSize' => 4,
'Include' => [ '/usr/include' ],
'DoubleSize' => 4,
'FloatSize' => 4,
'HasCPPComments' => 1,
'Alignment' => 1,
'CompoundAlignment' => 1,
'Define' => [ 'DEBUGGING', 'FOO=123' ],
'HasMacroVAARGS' => 1,
'LongSize' => 4,
'Warnings' => 0,
'ByteOrder' => 'LittleEndian',
'Assert' => [],
'IntSize' => 4,
'PointerSize' => 4,
'LongLongSize' => 8,
'LongDoubleSize' => 12,
'OrderMembers' => 0,
'Bitfields' => { Engine => 'Simple', BlockSize => 2 },
'StdCVersion' => undef,
'HostedC' => 0,
);
eval {
$p = Convert::Binary::C->new( %config );
$cfg = $p->configure;
};
ok( $@, '', "failed to retrieve configuration" );
ok( compare_config( \%config, $cfg ) );
#===================================================================
# check option chaining
#===================================================================
%newcfg = (
'KeywordMap' => {'__signed__' => 'signed', '__restrict' => undef},
'DisabledKeywords' => ['const', 'register'],
'UnsignedBitfields' => 1,
'UnsignedChars' => 1,
'CharSize' => 2,
'ShortSize' => 4,
'EnumType' => 'Both',
'EnumSize' => 0,
'Include' => [ '/usr/local/include', '/usr/include', '/include' ],
'DoubleSize' => 8,
'FloatSize' => 8,
'HasCPPComments' => 1,
'Alignment' => 2,
'CompoundAlignment' => 4,
'Define' => [ 'DEBUGGING', 'FOO=123', 'BAR=456' ],
'HasMacroVAARGS' => 1,
'LongSize' => 4,
'Warnings' => 1,
'ByteOrder' => 'BigEndian',
'Assert' => [],
'IntSize' => 4,
'PointerSize' => 2,
'LongLongSize' => 8,
'LongDoubleSize' => 12,
'OrderMembers' => 0,
'Bitfields' => { Engine => 'Simple', BlockSize => 4 },
'StdCVersion' => 199901,
'HostedC' => undef,
);
@warn = ();
eval {
local $SIG{__WARN__} = sub { push @warn, shift };
$p = Convert::Binary::C->new( %config );
$p->UnsignedChars( 1 )->configure( ShortSize => 4, EnumType => 'Both', EnumSize => 0 )
->Include( ['/usr/local/include'] )->DoubleSize( 8 )
->CompoundAlignment( 4 );
$p->FloatSize( 8 )->Include( qw( /usr/include /include ) )->DisabledKeywords( [qw( const register )] )
->Alignment( 2 )->Define( qw( BAR=456 ) )->configure( ByteOrder => 'BigEndian' );
$p->configure( PointerSize => 2 )->Warnings( 1 )->UnsignedBitfields( 1 )
->KeywordMap( {'__signed__' => 'signed', '__restrict' => undef} );
$p->CharSize(2);
$p->Bitfields( { BlockSize => 4 } );
$p->configure(StdCVersion => 199901);
$p->HostedC(undef);
$cfg = $p->configure;
};
ok( $@, '', "failed to configure object" );
if( @warn ) { print "# issued warnings:\n", map "# $_", @warn }
ok( scalar @warn, 0, "invalid number of warnings issued" );
ok( compare_config( \%newcfg, $cfg ) );
$debug and $result = checkrc( Convert::Binary::C::__DUMP__( $cfg ) );
skip( $RDBG, $result );
( run in 1.199 second using v1.01-cache-2.11-cpan-39bf76dae61 )