searchengine/oss/loc/analysisunittest/src/analysisunittest.cpp
changeset 24 65456528cac2
equal deleted inserted replaced
23:d4d56f5e7c55 24:65456528cac2
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <stdio.h>
       
    18 #include <wchar.h>
       
    19 #include <algorithm>
       
    20 #include <functional>
       
    21 #include <memory>
       
    22 
       
    23 #include "itk.h"
       
    24 
       
    25 #include <iostream>
       
    26 
       
    27 #include "thaianalysis.h"
       
    28 
       
    29 using namespace Itk;
       
    30 
       
    31 #define THAISTATEMACHINE_FILE "c:\\data\\analysisunittestcorpus\\thai\\thaidict.sm"
       
    32 
       
    33 Itk::TesterBase * CreateThaiAnalysisUnitTest();
       
    34 Itk::TesterBase * CreateEvaluationTest(); 
       
    35 Itk::TesterBase * CreateCjkAnalyzerUnitTest(); 
       
    36 Itk::TesterBase * CreateTinyAnalysisUnitTest(); 
       
    37 Itk::TesterBase * CreateNgramAnalyzerUnitTest();
       
    38 Itk::TesterBase * CreateKoreanAnalyzerUnitTest(); 
       
    39 Itk::TesterBase * CreatePrefixAnalyzerUnitTest();
       
    40 
       
    41 Itk::TesterBase * CreateTestHierarchy()
       
    42 {
       
    43     using namespace Itk;
       
    44 
       
    45     SuiteTester
       
    46         * all = new SuiteTester("all");
       
    47 
       
    48     all->add(CreateThaiAnalysisUnitTest());
       
    49     all->add(CreateEvaluationTest()); 
       
    50     all->add(CreateCjkAnalyzerUnitTest());  
       
    51     all->add(CreateTinyAnalysisUnitTest());  
       
    52     all->add(CreateNgramAnalyzerUnitTest());  
       
    53     all->add(CreateKoreanAnalyzerUnitTest());
       
    54 	all->add(CreatePrefixAnalyzerUnitTest());  
       
    55 
       
    56     return all;
       
    57 }
       
    58 
       
    59 int main(int          argc,
       
    60          const char * argv[])
       
    61 {
       
    62     using namespace std;
       
    63     
       
    64     analysis::InitThaiAnalysis(THAISTATEMACHINE_FILE);
       
    65 
       
    66     int
       
    67         rv = 0;
       
    68 
       
    69     auto_ptr<TesterBase>
       
    70         testCase(CreateTestHierarchy());
       
    71 
       
    72     bool
       
    73         help = false; 
       
    74     const char
       
    75         * focus = NULL;
       
    76 
       
    77     if (argc == 2)
       
    78         { if (strcmp(argv[1], "h") == 0)
       
    79                 {
       
    80                     help = true;
       
    81                 }
       
    82             else
       
    83                 {
       
    84                     focus = argv[1];
       
    85                 }
       
    86         }
       
    87     
       
    88     if (help)
       
    89         {
       
    90             cout << "Test hierarchy:" << endl;
       
    91             testCase->printHierarchy(cout);
       
    92         }
       
    93     else
       
    94         {
       
    95             TestRunConsole
       
    96                 ui(std::cout);
       
    97     
       
    98             TestMgr
       
    99                 testMgr(&ui,
       
   100                         "c:\\data\\analysisunittest\\");
       
   101      
       
   102             rv = testMgr.run(testCase.get(),
       
   103                             focus);
       
   104             
       
   105             testMgr.generateSummary(std::cout);
       
   106             
       
   107 			ofstream
       
   108 					ofs("c:\\data\\analysisunittest\\report.txt");
       
   109 			if (ofs)
       
   110 				{
       
   111 					testMgr.generateSummary(ofs);
       
   112 				}
       
   113         }
       
   114     
       
   115 
       
   116     int
       
   117     	c = getchar();
       
   118     
       
   119     analysis::ShutdownThaiAnalysis();
       
   120 
       
   121     return rv;
       
   122 }