1 /////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
5 /////////////////////////////////////////////////////////////////////////////
6
7 #ifndef BASETOKENSTREAMFIXTURE_H
8 #define BASETOKENSTREAMFIXTURE_H
9
10 #include "LuceneTestFixture.h"
11 #include "Attribute.h"
12
13 namespace Lucene {
14
DECLARE_SHARED_PTR(CheckClearAttributesAttribute)15 DECLARE_SHARED_PTR(CheckClearAttributesAttribute)
16
17 class CheckClearAttributesAttribute : public Attribute {
18 public:
19 CheckClearAttributesAttribute();
20 virtual ~CheckClearAttributesAttribute();
21
22 LUCENE_CLASS(CheckClearAttributesAttribute);
23
24 protected:
25 bool clearCalled;
26
27 public:
28 bool getAndResetClearCalled();
29
30 virtual void clear();
31 virtual bool equals(const LuceneObjectPtr& other);
32 virtual int32_t hashCode();
33 virtual void copyTo(const AttributePtr& target);
34 virtual LuceneObjectPtr clone(const LuceneObjectPtr& other = LuceneObjectPtr());
35 };
36
37 class BaseTokenStreamFixture : public LuceneTestFixture {
38 public:
39 virtual ~BaseTokenStreamFixture();
40
41 public:
42 // some helpers to test Analyzers and TokenStreams
43
44 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets,
45 Collection<String> types, Collection<int32_t> posIncrements, int32_t finalOffset = -1);
46 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output);
47 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<String> types);
48 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> posIncrements);
49 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets);
50 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets, int32_t finalOffset);
51 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets, Collection<int32_t> posIncrements);
52 static void checkTokenStreamContents(const TokenStreamPtr& ts, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets, Collection<int32_t> posIncrements, int32_t finalOffset);
53
54 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets,
55 Collection<int32_t> endOffsets, Collection<String> types, Collection<int32_t> posIncrements);
56 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output);
57 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<String> types);
58 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> posIncrements);
59 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets);
60 static void checkAnalyzesTo(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets, Collection<int32_t> posIncrements);
61
62 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets,
63 Collection<int32_t> endOffsets, Collection<String> types, Collection<int32_t> posIncrements);
64 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output);
65 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<String> types);
66 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> posIncrements);
67 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets);
68 static void checkAnalyzesToReuse(const AnalyzerPtr& analyzer, const String& input, Collection<String> output, Collection<int32_t> startOffsets, Collection<int32_t> endOffsets, Collection<int32_t> posIncrements);
69
70 static void checkOneTerm(const AnalyzerPtr& analyzer, const String& input, const String& expected);
71 static void checkOneTermReuse(const AnalyzerPtr& analyzer, const String& input, const String& expected);
72 };
73
74 }
75
76 #endif
77