1 #include <gtest/gtest.h>
30 const std::string testOutFile =
"./out.xml";
32 std::stringstream inSchema, inDocument;
33 inSchema <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:schema>\n<sphinx:field name=\"title\"/>\n<sphinx:field name=\"h\"/>\n</sphinx:schema>\n</sphinx:docset>";
35 inDocument <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"123\">\n"
36 <<
"<title><![CDATA[[- Information interchange - Representation of dates and times. A discussion of ISO 8601 has been written by Markus Kuhn. ISO 8601 describes a large number of date/time formats. For example it defines Basic Format, without punctuation, and Extended Format, with punctuation, and it allows elements to be omitted. This profile defines a restricted range of formats, all of which are valid ISO 8601 dates and times. The aim is to simplify the use of ISO 8601 in World Wide Web-related standards, and to avoid the need for the developers and users of these standards to obtain copies of ISO 8601 itself.]]></title>\n"
37 <<
"<h><![CDATA[[time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions. The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the \"T\" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>\n"
38 <<
"</sphinx:document>\n</sphinx:docset>";
42 std::fstream outSource(testOutFile.c_str(), std::fstream::out | std::fstream::trunc);
43 ASSERT_TRUE(outSource.is_open());
45 outSource << dataSource;
47 ASSERT_FALSE(dataSource.isError());
48 ASSERT_TRUE(dataSource.getErrorMsg().empty());
49 ASSERT_TRUE(
remove((testOutFile).c_str())==0);
50 printSuccess(
"Test create document storage");
53 std::string SphinxIndexTest::makeJson(
unsigned int type)
77 SphinxInputJsonMessageManage msgManage;
78 msgManage.setCommandString(
"Add index");
79 msgManage.setCommandOptionsString(
"--All --rotate");
80 msgManage.serialize(json);
83 std::cerr <<
"Unknown type of handler\n";
88 void SphinxIndexTest::testInputJsonSearch(
void)
90 std::string json = makeJson(0);
92 Poco::SharedPtr<SphinxInputJsonMessageSearch> msgSearch(
new SphinxInputJsonMessageSearch());
94 ASSERT_FALSE(msgSearch->
isError());
96 std::stringstream str(json);
98 std::stringstream out;
100 ASSERT_FALSE(msgSearch->isError());
105 ASSERT_TRUE(json==out.str());
107 Poco::SharedPtr<SphinxInputJsonMessage> handler(
new SphinxInputJsonMessage());
108 handler->setData(json);
111 handler->serialize(json);
112 ASSERT_FALSE(handler->isError());
113 handler->getData().clear();
114 handler->unserialize(json);
117 ASSERT_FALSE(handler->isError());
122 ASSERT_TRUE(json==out.str());
123 printSuccess(
"Test input json search");
126 void SphinxIndexTest::testInputJsonIndex(
void)
128 std::string json = makeJson(1);
130 Poco::SharedPtr<SphinxInputJsonMessageIndex> msgIndex(
new SphinxInputJsonMessageIndex());
133 std::stringstream str(json);
135 ASSERT_FALSE(msgIndex->isError());
136 std::stringstream out;
138 ASSERT_FALSE(msgIndex->isError());
143 ASSERT_TRUE(json==out.str());
145 SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtIndex);
146 handler.setData(json);
149 handler.serialize(json);
150 ASSERT_FALSE(handler.isError());
151 handler.getData().clear();
152 handler.unserialize(json);
155 ASSERT_FALSE(handler.isError());
160 ASSERT_TRUE(json==out.str());
161 printSuccess(
"Test input json index");
164 void SphinxIndexTest::testInputJsonManage(
void)
166 std::string json = makeJson(2);
168 Poco::SharedPtr<SphinxInputJsonMessageManage> msgManage(
new SphinxInputJsonMessageManage());
169 msgManage->unserialize(json);
171 std::stringstream str(json);
173 ASSERT_FALSE(msgManage->isError());
174 std::stringstream out;
176 ASSERT_FALSE(msgManage->isError());
181 ASSERT_TRUE(json==out.str());
183 SphinxInputJsonMessage handler(SphinxInputJsonMessage::MessageType::mtManage);
184 handler.setData(json);
187 handler.serialize(json);
188 ASSERT_FALSE(handler.isError());
189 handler.getData().clear();
190 handler.unserialize(json);
193 ASSERT_FALSE(handler.isError());
198 ASSERT_TRUE(json==out.str());
199 printSuccess(
"Test input json manage");
204 testInputJsonSearch();
205 testInputJsonIndex();
206 testInputJsonManage();
211 const std::string schemaContent =
212 "<?xml version=\"1.0\" encoding=\"utf-8\"?> \n\
213 <sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n\
215 <sphinx:field name=\"bodyn\"/>\n\
216 <sphinx:attr name=\"cdate\" type=\"timestamp\"/>\n\
220 const std::string documentContents [2] =
221 {
"<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n\
222 <sphinx:document id=\"1111\">\n\
223 <bodyn>Some body for test...</bodyn>\n\
224 <cdate>1232244134</cdate>\n\
225 </sphinx:document>\n\
227 <sphinx:document id=\"2222\">\n\
228 <bodyn>Next some body for test...</bodyn>\n\
229 <cdate>1232567575</cdate>\n\
230 </sphinx:document>\n\
233 "<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n\
234 <sphinx:document id=\"3333\">\n\
235 <bodyn>Some body for test...</bodyn>\n\
236 <cdate>1232244134</cdate>\n\
237 </sphinx:document>\n\
239 <sphinx:document id=\"4444\">\n\
240 <bodyn>Next some body for test...</bodyn>\n\
241 <cdate>1232567575</cdate>\n\
242 </sphinx:document>\n\
243 </sphinx:docset>\n"};
245 const std::string
nodeName =
"test_node";
252 const size_t jsonType = 16;
253 for (
size_t i=0;i<jsonType;++i)
257 msgIndex->setIndexName(indexName);
259 msgIndex->addParameters(
"params",
"111");
260 msgIndex->serialize(json);
265 std::stringstream str;
270 std::cout <<
"ret: '" << ret <<
"'\n";
273 std::cout <<
"ErrorMsg: '" << fObj.
getErrorMsg() <<
"'\n";
281 assert(!ouputJsonMessage.isError());
282 assert(ouputJsonMessage.getErrorCode()==0);
283 assert(ouputJsonMessage.getErrorMessage().empty());
288 ASSERT_FALSE(fObject.isError());
291 printSuccess(
"Test Indexer Process");