Changeset 2015

Show
Ignore:
Timestamp:
02/12/08 00:36:10 (3 months ago)
Author:
karpet
Message:

more tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/bindings/perl/3.xs

    r2014 r2015  
    2727        stash   = newHV(); 
    2828        RETVAL  = swish_init_swish3( &sp_handler, newRV_inc((SV*)stash) ); 
    29         RETVAL->ref_cnt++
     29        RETVAL->ref_cnt = 1
    3030         
    3131        sp_hv_store(stash, DATA_CLASS_KEY,      newSVpv(DATA_CLASS, 0)); 
     
    3737        //sp_describe_object(newRV_noinc((SV*)RETVAL->stash)); 
    3838 
    39         RETVAL->analyzer->ref_cnt++
     39        RETVAL->analyzer->ref_cnt = 1
    4040        RETVAL->analyzer->tokenizer = &sp_tokenize; 
    4141        analyzer_stash  = newHV(); 
    4242        RETVAL->analyzer->stash = newRV_inc((SV*)analyzer_stash); 
    4343         
     44        RETVAL->config->ref_cnt = 1; 
     45        RETVAL->parser->ref_cnt = 1; 
     46         
    4447        //SvREFCNT_inc(RETVAL); 
    4548         
     
    7275SV* 
    7376slurp(self, filename) 
    74     SV* self; 
    75     char* filename; 
     77    swish_3*    self; 
     78    char*       filename; 
    7679     
    7780    PREINIT: 
     
    265268void 
    266269DESTROY(self) 
    267     swish_3 *self; 
    268  
    269     CODE: 
    270          
    271         //if (SWISH_DEBUG) { 
     270    SV *self; 
     271 
     272    PREINIT: 
     273        swish_3 *s3; 
     274         
     275    CODE: 
     276        s3 = (swish_3*)sp_ptr_from_object(self); 
     277         
     278        if (SWISH_DEBUG) { 
    272279            warn("DESTROYing swish_3 object %s  [%d] [ref_cnt = %d]",  
    273                 SvPV(ST(0), PL_na), self, self->ref_cnt); 
    274         //
     280                SvPV(ST(0), PL_na), self, s3->ref_cnt); 
     281       
    275282         
    276283        // TODO free pointers when we figure out ref cnt 
    277         //swish_free_swish3( (swish_3*)sp_ptr_from_object( (SV*)self ) ); 
    278          
    279  
     284        swish_free_swish3( s3 ); 
     285         
     286 
     287int 
     288refcount(obj) 
     289    SV* obj; 
     290     
     291    CODE: 
     292        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     293     
     294    OUTPUT: 
     295        RETVAL 
     296         
    280297 
    281298########################################################################################## 
     
    345362         
    346363    CODE: 
    347         sc = swish_subconfig_hash(self, (xmlChar*)key); 
    348         RETVAL = sp_xml2_hash_to_perl_hash(sc); 
    349  
    350     OUTPUT: 
    351         RETVAL 
    352  
    353          
     364        sc      = swish_subconfig_hash(self, (xmlChar*)key); 
     365        RETVAL = sp_xml2_hash_to_perl_hash(sc); 
     366 
     367    OUTPUT: 
     368        RETVAL 
     369 
     370  
    354371 
    355372int 
     
    418435        } 
    419436         
     437int 
     438refcount(obj) 
     439    SV* obj; 
     440     
     441    CODE: 
     442        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     443     
     444    OUTPUT: 
     445        RETVAL 
     446         
    420447         
    421448# ******************************************************************************* 
     
    435462 
    436463    CODE: 
     464        //RETVAL = swish_init_analyzer((swish_Config*)sp_ptr_from_object( (SV*)config )); 
    437465        RETVAL = swish_init_analyzer(config); 
    438         RETVAL->ref_cnt++
     466        RETVAL->ref_cnt = 1
    439467        stash = newHV(); 
    440468        RETVAL->stash = newRV_inc((SV*)stash); 
     
    506534         
    507535    CODE: 
    508         CLASS = "SWISH::3::WordList"; 
     536        CLASS = WORDLIST_CLASS; 
     537         
     538        // TODO reimplement as hashref arg 
    509539                 
    510540        if (!SvUTF8(str)) 
     
    528558            if ( items > 5 ) 
    529559                context = (xmlChar*)SvPV(ST(5), PL_na); 
     560                 
     561            //warn ("word_pos %d  offset %d  metaname %s  context %s\n", word_pos, offset, metaname, context ); 
    530562                 
    531563        } 
     
    564596         
    565597    CODE: 
    566         CLASS = "SWISH::3::WordList"
     598        CLASS = WORDLIST_CLASS
    567599         
    568600        if (!SvUTF8(str)) 
     
    605637    OUTPUT: 
    606638        RETVAL 
     639 
     640int 
     641refcount(obj) 
     642    SV* obj; 
     643     
     644    CODE: 
     645        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     646     
     647    OUTPUT: 
     648        RETVAL 
     649         
    607650         
    608651# ******************************************************************************* 
     
    620663     
    621664    CODE: 
    622         CLASS = "SWISH::3::Word"
     665        CLASS = WORD_CLASS
    623666         
    624667        if (self->current == NULL) { 
     
    664707        } 
    665708         
     709int 
     710refcount(obj) 
     711    SV* obj; 
     712     
     713    CODE: 
     714        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     715     
     716    OUTPUT: 
     717        RETVAL 
     718         
    666719 
    667720# ******************************************************************************* 
     
    728781 
    729782 
     783int 
     784refcount(obj) 
     785    SV* obj; 
     786     
     787    CODE: 
     788        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     789     
     790    OUTPUT: 
     791        RETVAL 
     792         
    730793 
    731794# ******************************************************************************* 
     
    812875        RETVAL 
    813876 
     877int 
     878refcount(obj) 
     879    SV* obj; 
     880     
     881    CODE: 
     882        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     883     
     884    OUTPUT: 
     885        RETVAL 
     886         
    814887 
    815888# ******************************************************************************* 
    816889     
    817 MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::Data 
     890MODULE = SWISH::3               PACKAGE = SWISH::3::Data 
    818891 
    819892PROTOTYPES: enable 
     
    905978    OUTPUT: 
    906979        RETVAL 
    907          
     980 
     981 
    908982swish_WordList * 
    909983wordlist(self) 
     
    914988         
    915989    CODE: 
    916         CLASS = "SWISH::3::WordList"
     990        CLASS = WORDLIST_CLASS
    917991         
    918992# MUST increment refcnt 2x so that SWISH::3::Parser::WordList::DESTROY 
     
    9381012#        SvREFCNT_dec( self->user_data ); 
    9391013         
    940  
     1014int 
     1015refcount(obj) 
     1016    SV* obj; 
     1017     
     1018    CODE: 
     1019        RETVAL = SvREFCNT((SV*)SvRV(obj)); 
     1020     
     1021    OUTPUT: 
     1022        RETVAL 
     1023         
     1024 
  • libswish3/trunk/bindings/perl/lib/SWISH/3.pm

    r2014 r2015  
    77our $VERSION = '0.01'; 
    88 
    9 $ENV{SWISH3} = 1; # should be set by libswish3 in swish.c but doesn't seem to. 
     9#$ENV{SWISH3} = 1; # should be set by libswish3 in swish.c but doesn't seem to. 
    1010 
    1111use Carp; 
     
    1313use Devel::Peek; 
    1414 
    15 require XSLoader; 
     15use XSLoader; 
    1616XSLoader::load( __PACKAGE__, $VERSION ); 
     17use SWISH::3::Config; 
     18use SWISH::3::Constants; 
     19 
     20# convenience accessors 
     21*config   = \&get_config; 
     22*analyzer = \&get_analyzer; 
    1723 
    1824sub new { 
     
    3440    } 
    3541 
    36     if ( !$arg{handler} ) { 
    37         no strict 'refs'; 
    38         no warnings 'redefine'; 
    39         my $data_class = $self->get_data_class; 
    40         eval "use $data_class"; 
    41         if ($@) { 
    42             croak "can't load data_class $data_class:\n$@"; 
    43         } 
    44         $arg{handler} = \&{ $data_class . '::handler' }; 
    45     } 
     42    $arg{handler} ||= \&default_handler; 
    4643 
    4744    $self->set_handler( $arg{handler} ); 
     
    7875        Dump($self); 
    7976        Data::Dump::dump($self); 
     77    } 
     78} 
     79 
     80sub default_handler { 
     81    my $data = shift; 
     82 
     83    select(STDERR); 
     84 
     85    print '~' x 80, "\n"; 
     86 
     87    my $props = $data->config->properties; 
     88 
     89    print "Properties\n"; 
     90    for my $p ( keys %$props ) { 
     91        my $v    = $data->property($p); 
     92        my $type = $props->{$p}; 
     93 
     94        print "    <$p type='$type'>$v</$p>\n"; 
     95    } 
     96 
     97    print "Doc\n"; 
     98    for my $d ( SWISH_DOC_FIELDS() ) { 
     99 
     100        #printf("%15s: %s\n", $d, $data->doc->$d); 
     101    } 
     102 
     103    print "WordList\n"; 
     104    while ( my $swishword = $data->wordlist->next ) { 
     105        for my $w ( SWISH_WORD_FIELDS() ) { 
     106 
     107            printf( "%15s: %s\n", $w, $swishword->$w ); 
     108        } 
    80109    } 
    81110} 
  • libswish3/trunk/bindings/perl/macros.h

    r2014 r2015  
    88#define PARSER_CLASS        "SWISH::3::Parser" 
    99#define PARSER_CLASS_KEY    "sp_parser_class" 
    10 #define DATA_CLASS          "SWISH::3::Parser::Data" 
     10#define DATA_CLASS          "SWISH::3::Data" 
    1111#define DATA_CLASS_KEY      "sp_data_class" 
    1212#define TOKEN_CLASS         "SWISH::3::Token" 
    13  
     13#define WORDLIST_CLASS      "SWISH::3::WordList" 
     14#define WORD_CLASS          "SWISH::3::Word" 
     15#define SELF_KEY            "sp_self" 
    1416#define CONFIG_KEY          "sp_config" 
    1517#define ANALYZER_KEY        "sp_analyzer" 
  • libswish3/trunk/bindings/perl/t/01slurp.t

    r2014 r2015  
    77ok( my $buf = $s3->slurp("t/test.html"), "slurp file" ); 
    88 
    9 diag($buf); 
     9#diag( $s3->dump ); 
     10#diag( $s3->refcount ); 
    1011 
     12#diag($buf); 
     13 
  • libswish3/trunk/bindings/perl/t/10tokenize.t

    r2014 r2015  
    1 use Test::More tests => 8
     1use Test::More tests => 9
    22 
    33use_ok('SWISH::3'); 
    44use_ok('SWISH::3::Constants'); 
    55 
    6 ok( my $analyzer = SWISH::3->new()->get_analyzer, "new tokenizer" ); 
     6ok( my $s3 = SWISH::3->new, "new s3" ); 
     7ok( my $analyzer = $s3->analyzer, "new tokenizer" ); 
    78 
    89ok( my $wlist = $analyzer->tokenize( 
    910        "now is the time, ain't it? or when else might it be!", 
    10         13, 14, 'foo', 'bar' 
     11        5, 14, 'foo', 'bar' 
    1112    ), 
    1213    "wordlist" 
     
    1920    my $word = $swishword->word; 
    2021    if ( $word eq 'now' ) { 
    21         is( $swishword->position, 14, "now position" ); 
     22        is( $swishword->position, 6, "now position" ); 
    2223    } 
    2324    if ( $word eq 'time' ) { 
    24         is( $swishword->position, 17, "time position" ); 
     25        is( $swishword->position, 9, "time position" ); 
    2526    } 
    2627    if ( $word eq 'be' ) { 
    27         is( $swishword->position, 25, "be position" ); 
     28        is( $swishword->position, 17, "be position" ); 
    2829    } 
    2930 
  • libswish3/trunk/bindings/perl/xs_helpers.c

    r2014 r2015  
    442442     
    443443    SV* obj; 
    444     obj         = sp_ptr_to_object( TOKEN_CLASS, (IV)token ); 
     444    obj = sp_ptr_to_object( TOKEN_CLASS, (IV)token ); 
    445445     
    446446    PUSHMARK(SP); 
     
    456456{ 
    457457    dTHX; 
     458     
    458459    unsigned int wpos, offset, num_code_points; 
    459460    swish_Token     *s3_token; 
     
    477478    va_end(args); 
    478479     
     480    //warn("wpos %d  offset %d  meta %s  ctxt %s\n", wpos, offset, meta, ctxt); 
     481     
    479482    s3_token        = swish_xmalloc(sizeof(swish_Token)); 
    480483    mg              = NULL; 
     
    519522    s3_token->analyzer  = analyzer; 
    520523    s3_token->list      = list; 
     524    s3_token->offset    = offset; // gets incremented 
    521525 
    522526     
     
    549553             
    550554        tok_pts   = end - start;    // TODO what is this for?? 
     555        tok_bytes = end_ptr - start_ptr; 
    551556         
    552557        s3_token->start_ptr = start_ptr; 
    553         s3_token->tok_bytes = end_ptr - start_ptr
     558        s3_token->tok_bytes = tok_bytes
    554559        s3_token->start     = start; 
    555560        s3_token->end       = end; 
    556561        s3_token->wpos      = ++wpos; 
    557         s3_token->offset    = (tok_bytes + offset - 1); 
     562         
    558563                 
    559564        if (token_handler) { 
     
    563568        } 
    564569         
     570        /* increment for next iteration */ 
     571        s3_token->offset   += tok_bytes; 
    565572    } 
    566573