|
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 |
|
18 |
|
19 #include <wchar.h> |
|
20 #include <stddef.h> |
|
21 #include <iostream> |
|
22 #include "itk.h" |
|
23 |
|
24 #include "config.h" |
|
25 #include "testutils.h" |
|
26 |
|
27 #include "std_log_result.h" |
|
28 |
|
29 #include "cpixexc.h" |
|
30 #include "cpixhits.h" |
|
31 #include "cpixidxdb.h" |
|
32 |
|
33 |
|
34 #include "..\..\..\cpix\src\cpixerror.cpp" |
|
35 #include "..\..\..\cpix\src\cpixanalyzer.cpp" |
|
36 #include "..\..\..\cpix\src\fileparser\fileparser.cpp" |
|
37 #include "..\..\..\cpix\src\fileparser\pdffileparser.cpp" |
|
38 #include "..\..\..\cpix\src\qrytypes\cluceneqrytype.cpp" |
|
39 |
|
40 const cpix_LangCode cpix_LANG_JA = { "ja" }; |
|
41 void TestAnalyzer(Itk::TestMgr *) |
|
42 { |
|
43 const cpix_LangCode **C_Lang = cpix_supportedLanguages(); |
|
44 const wchar_t* toWchar = cpix_ToWideLangCode(cpix_LANG_EN); |
|
45 cpix_Result result; |
|
46 cpix_Analyzer * c_analyzer = cpix_CreateSnowballAnalyzer(&result,cpix_LANG_JA); |
|
47 } |
|
48 void TestSetError(Itk::TestMgr *) |
|
49 { |
|
50 struct ErrorInfo serrorinfo; |
|
51 serrorinfo.setInfo(ET_CPIX_EXC); |
|
52 serrorinfo.setInfo(ET_CPIX_EXC, ""); |
|
53 cpix_Error *err1 = CreateError(ET_OS_EXC, L""); |
|
54 cpix_Error *err2 = CreateError(ET_CPIX_EXC, ""); |
|
55 cpix_Error_report(NULL,L"",0); |
|
56 } |
|
57 |
|
58 void TestCpixExc(Itk::TestMgr * ) |
|
59 { |
|
60 char *xml_file = (char*)__FUNCTION__; |
|
61 assert_failed = 0; |
|
62 CpixExc *exc1 = new CpixExc(/*(const wchar_t *)NULL*/L"", "misc.cpp", __LINE__); |
|
63 CpixExc *exc2 = new CpixExc("", "misc.cpp", __LINE__); |
|
64 CpixExc exc3 = *exc1; |
|
65 exc3 = *exc2; |
|
66 exc2->file(); |
|
67 exc2->line(); |
|
68 exc2->wWhat(); |
|
69 free(exc1); |
|
70 free(exc2); |
|
71 testResultXml(xml_file); |
|
72 } |
|
73 |
|
74 void TestHitDocumentList(Itk::TestMgr * ) |
|
75 { |
|
76 Cpix::HitDocumentList *hitdoclist = new Cpix::HitDocumentList; |
|
77 hitdoclist->remove(0); |
|
78 free(hitdoclist); |
|
79 } |
|
80 |
|
81 void TestTermCreateDestroy(Itk::TestMgr * ) |
|
82 { |
|
83 cpix_Result result; |
|
84 cpix_Term *term = cpix_Term_create(&result, CONTENTS_FIELD, L"Hello"); |
|
85 cpix_Term_destroy(term); |
|
86 } |
|
87 |
|
88 void TestPdfFileParser(Itk::TestMgr * ) |
|
89 { |
|
90 bool isParse1 = Cpix::isFileAllowedToParse(L""); |
|
91 bool isParse2 = Cpix::isFileAllowedToParse(L"c:\\data\\cpixunittestcorpus\\pdf\\ctutor"); |
|
92 // getPDFExcerpt is unnamed namespace so cant call ... |
|
93 // std::wstring line; |
|
94 // int result = getPDFExcerpt(L"c:\\data\\cpixunittestcorpus\\pdf\\ctutor\\empty.pdf", &line); |
|
95 |
|
96 char *buffer = "Hello this is test for find string"; |
|
97 |
|
98 Cpix::FindStringInBuffer(buffer, "find", strlen(buffer)); |
|
99 |
|
100 Cpix::FindStringInBuffer(buffer, "no", strlen(buffer)); |
|
101 |
|
102 Cpix::seen2("find", "If its for find"); |
|
103 |
|
104 Cpix::ExtractNumber("hello calculate 123 ", strlen("hello calculate 123 ")); |
|
105 |
|
106 //Cpix::convertPDFToText("c:\\data\\cpixunittestcorpus\\pdf\\ctutor.pdf"); |
|
107 |
|
108 |
|
109 } |
|
110 void TestLuceneQryType(Itk::TestMgr * ) |
|
111 { |
|
112 cpix_Result result; |
|
113 |
|
114 cpix_Analyzer* analyzer = cpix_CreateSimpleAnalyzer(&result); |
|
115 if ( cpix_Failed( &result) ) |
|
116 { |
|
117 ITK_PANIC("Analyzer could not be created"); |
|
118 assert_failed = 1; |
|
119 } |
|
120 cpix_QueryParser |
|
121 * queryParser = cpix_QueryParser_create(&result, |
|
122 LCPIX_DEFAULT_FIELD, |
|
123 analyzer ); |
|
124 if (queryParser == NULL) |
|
125 { |
|
126 cpix_Analyzer_destroy( analyzer ); |
|
127 ITK_PANIC("Could not create query parser"); |
|
128 } |
|
129 Cpix::LuceneQryType *QryType = new Cpix::LuceneQryType(); |
|
130 std::list<std::wstring> list (2, L"no argumnet"); |
|
131 //QryType->setUp(queryParser,list,L"Find this"); |
|
132 |
|
133 } |
|
134 |
|
135 |
|
136 Itk::TesterBase * CreateMiscTests() |
|
137 { |
|
138 |
|
139 using namespace Itk; |
|
140 |
|
141 SuiteTester |
|
142 * misc = new SuiteTester("misc"); |
|
143 |
|
144 misc->add("testanalyzer",&TestAnalyzer,"testanalyzer"); |
|
145 |
|
146 misc->add("SetError",&TestSetError,"SetError"); |
|
147 |
|
148 misc->add("CpixExc", &TestCpixExc, "CpixExc"); |
|
149 |
|
150 misc->add("doclist", &TestHitDocumentList, "doclist"); |
|
151 |
|
152 misc->add("termCD", &TestTermCreateDestroy, "termCD"); |
|
153 |
|
154 misc->add("pdfparser", &TestPdfFileParser, "pdfparser"); |
|
155 |
|
156 misc->add("lucenetype", &TestLuceneQryType, "lucenetype"); |
|
157 |
|
158 return misc; |
|
159 } |