add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / payloads / TokenOffsetPayloadTokenFilterTest.java
1 package org.apache.lucene.analysis.payloads;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
20 import org.apache.lucene.analysis.MockTokenizer;
21 import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
22 import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
23 import org.apache.lucene.index.Payload;
24
25 import java.io.IOException;
26 import java.io.StringReader;
27
28 public class TokenOffsetPayloadTokenFilterTest extends BaseTokenStreamTestCase {
29
30   public void test() throws IOException {
31     String test = "The quick red fox jumped over the lazy brown dogs";
32
33     TokenOffsetPayloadTokenFilter nptf = new TokenOffsetPayloadTokenFilter(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false));
34     int count = 0;
35     PayloadAttribute payloadAtt = nptf.getAttribute(PayloadAttribute.class);
36     OffsetAttribute offsetAtt = nptf.getAttribute(OffsetAttribute.class);
37     nptf.reset();
38     while (nptf.incrementToken()) {
39       Payload pay = payloadAtt.getPayload();
40       assertTrue("pay is null and it shouldn't be", pay != null);
41       byte [] data = pay.getData();
42       int start = PayloadHelper.decodeInt(data, 0);
43       assertTrue(start + " does not equal: " + offsetAtt.startOffset(), start == offsetAtt.startOffset());
44       int end = PayloadHelper.decodeInt(data, 4);
45       assertTrue(end + " does not equal: " + offsetAtt.endOffset(), end == offsetAtt.endOffset());
46       count++;
47     }
48     assertTrue(count + " does not equal: " + 10, count == 10);
49
50   }
51
52
53 }