TEST_F(TextFinderFakeTimerTest, ScopeWithTimeouts)
{
    // Make a long string.
    String text(Vector<UChar>(100));
    text.fill('a');
    String searchPattern("abc");
    // Make 4 substrings "abc" in text.
    text.insert(searchPattern, 1);
    text.insert(searchPattern, 10);
    text.insert(searchPattern, 50);
    text.insert(searchPattern, 90);

    document().body()->setInnerHTML(text, ASSERT_NO_EXCEPTION);

    int identifier = 0;
    WebFindOptions findOptions; // Default.

    textFinder().resetMatchCount();

    // There will be only one iteration before timeout, because increment
    // of the TimeProxyPlatform timer is greater than timeout threshold.
    textFinder().scopeStringMatches(identifier, searchPattern, findOptions, true);
    while (textFinder().scopingInProgress())
        runPendingTasks();

    EXPECT_EQ(4, textFinder().totalMatchCount());
}
示例#2
0
void MainWidget::entryClicked( const QModelIndex &index )
{
   QString dirName( mpFileSysModel->filePath(index) );
   QRegExp re( ".*/([^/]*)/([^/]*)" );
   QDir dir( dirName );
   dirName.replace( re, "\\1 \\2" );
   mpLineEdit->setText( dirName );
   requestFromLine();
   QString searchPattern( Settings::value( Settings::FunkytownCoverFile ) );
   searchPattern.append( ".*" );
   QStringList entries( dir.entryList( QStringList( searchPattern ) ) );
   if( entries.size() > 0 )
   {
      mpImage->setImage( dir.absoluteFilePath( entries.at(0) ) );
      QImage i( mpImage->imageData() );
      message( tr("%1 x %2: %3").arg( QString::number(i.width()),
                                      QString::number(i.height()),
                                      dir.absoluteFilePath( entries.at(0) ) ) );
   }
   else
   {
      mpImage->setImage( QImage() );
   }
}
int main(int argc,char** argv){
    word i;
    text* T = callocx(sizeof(text),1);
    text* P = callocx(sizeof(text),1);
    cesa* CSA;
    cesa* CSA2;
    if(argc<4 || argc >5){
        fprintf(stderr,"%s","Error\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -create <inputText> <indexFile>\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -search <indexFile> <inputText> <patternFile>\n");
        exit(EXIT_FAILURE);
    }
    /**preprocess step**/
    initAllBitTables();

    if(strcmp(argv[1],"-create")==0){
        T->file = fopen(argv[2],"r");
        if(T->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        fseek(T->file,0,SEEK_END);
        T->length = ftell(T->file);
        rewind(T->file);
        T->textStart = 0;
        T->textEnd = T->length-1;
        CSA = computeCSA(T);
        computeLcp(CSA);
        saveIndex(CSA,argv[3]);
    }
    else if(strcmp(argv[1],"-search")==0){
        P->file = fopen(argv[4],"r");
        T->file = fopen(argv[3],"r");
        if(T->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        if(P->file == NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }

        fseek(T->file,0,SEEK_END);
        T->length = ftell(T->file);
        rewind(T->file);
        T->textStart = 0;
        T->textEnd = T->length-1;

        fseek(P->file,0,SEEK_END);
        P->length = ftell(P->file);
        rewind(P->file);
        CSA = loadIndex(argv[2]);
        CSA->P = P;
        CSA->T = T;
        searchPattern(CSA);
    }
    else{
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -create <inputText> <indexFile>\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -search <indexFile> <inputText> <patternFile>\n");
        exit(EXIT_FAILURE);
    }
    freeText(T);
    freeText(P);
    freeCSA(CSA);
    return(0);
}
int main(int argc,char** argv){
	sauchar_t* str;
	saidx_t* SA;
	saidx_t* SAI;
	word n;
	saidx_t* LCP;
	int h,j,k;
    int i;
    text* T = callocx(1,sizeof(text));
    text* P = callocx(1,sizeof(text));
    text* Index = callocx(1,sizeof(text));
    if(argc<4 || argc >5){
        fprintf(stderr,"%s","Error\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -create <inputText> <indexFile>\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -search <indexFile> <inputText> <patternFile>\n");
        exit(EXIT_FAILURE);
    }
    if(strcmp(argv[1],"-create")==0){
        T->file = fopen(argv[2],"r");
        Index->file = fopen(argv[3],"wb");

        if(T->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        if(Index->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }

        fseek(T->file,0,SEEK_END);
        T->length = ftell(T->file);
        rewind(T->file);

        str = callocx(sizeof(sauchar_t),T->length);
        SA = callocx(sizeof(saidx_t),T->length);
        SAI = callocx(sizeof(saidx_t),T->length);
        LCP = callocx(sizeof(saidx_t),T->length);
        fread(str,sizeof(sauchar_t),T->length,T->file);
        if(divsufsort(str,SA,T->length)){
            perror("suffix sort error");
            exit(EXIT_FAILURE);
        }

        for(i=0;i<T->length;i++){
            SAI[SA[i]] = i;
        }

        for(i=0;i<T->length;i++){
            h=0;
            if(SAI[i] !=  T->length -1){
                k = SA[SAI[i]+1];
                j=0;
                while(str[i+h]==str[k+h]) h++;
                LCP[SAI[i]] = h;
                if(h) h--;
            }
            else{
                LCP[SAI[i]] = 0;
            }
        }
        if(Index->file==NULL){
            perror("Error");
            exit(EXIT_FAILURE);
        }
        fwrite(&(T->length),sizeof(word),1,Index->file);
        fwrite(SA,sizeof(word),T->length,Index->file);
        fwrite(LCP,sizeof(word),T->length,Index->file);
        fclose(Index->file);
        free(SA);
        free(SAI);
        free (LCP);
        free(str);

    }
    else if(strcmp(argv[1],"-search")==0){
        P->file = fopen(argv[4],"r");
        T->file = fopen(argv[3],"r");
        Index->file = fopen(argv[2],"rb");
        if(T->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        if(P->file == NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        if(Index->file==NULL){
            perror("Error: ");
            exit(EXIT_FAILURE);
        }
        fseek(T->file,0,SEEK_END);
        T->length = ftell(T->file);
        rewind(T->file);
        T->textStart = 0;
        T->textEnd = T->length-1;
        fseek(P->file,0,SEEK_END);
        P->length = ftell(P->file);
        rewind(P->file);
        fread(&n,sizeof(word),1,Index->file);
        SA = callocx(sizeof(saidx_t),n);
        LCP = callocx(sizeof(saidx_t),n);
        fread(SA,sizeof(saidx_t),n,Index->file);
        fread(LCP,sizeof(saidx_t),n,Index->file);
        searchPattern(T,P,SA,LCP,n);
        free(SA);
        free(LCP);
    }
    else{
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -create <inputText> <indexFile>\n");
        fprintf(stderr,"%s%s%s","Usage = ",argv[0]," -search <inputText> <indexFile> <patternFile>\n");
        exit(EXIT_FAILURE);
    }
    freeText(T);
    freeText(P);
    freeText(Index);
    return(0);
}