KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > derby > SearchUtilTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.derby;
21
22 import junit.framework.*;
23
24 /**
25  *
26  * @author pj97932
27  */

28 public class SearchUtilTest extends TestCase {
29
30     public SearchUtilTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34     /**
35      * Test of checkForString method, of class org.netbeans.modules.derby.SearchUtil.
36      */

37     public void testCheckForString() {
38         String JavaDoc searchedFor;
39         int searchStart;
40         char[] buf;
41         int bufLen;
42
43         searchedFor = "12345";
44         searchStart = 0;
45         buf = new char[] {'a', 'b', '1', '2', '3', 'x', 'x'};
46         bufLen = 5;
47         assertEquals(3, SearchUtil.checkForString(searchedFor, searchStart, buf, bufLen));
48         
49         searchedFor = "12345";
50         searchStart = 2;
51         buf = new char[] {'3', '4', '5', 'a', 'b', 'x'};
52         bufLen = 5;
53         assertEquals(SearchUtil.FOUND, SearchUtil.checkForString(searchedFor, searchStart, buf, bufLen));
54         
55         searchedFor = "12345";
56         searchStart = 0;
57         buf = new char[] {'3', '4', '5', 'a', 'b', 'x'};
58         bufLen = 5;
59         assertEquals(0, SearchUtil.checkForString(searchedFor, searchStart, buf, bufLen));
60         
61         searchedFor = "12345";
62         searchStart = 0;
63         buf = new char[] {'a', 'b', 'c', '1', '2', 'x'};
64         bufLen = 5;
65         assertEquals(2, SearchUtil.checkForString(searchedFor, searchStart, buf, bufLen));
66         
67     }
68
69     /**
70      * Test of checkPosition method, of class org.netbeans.modules.derby.SearchUtil.
71      */

72     public void testCheckPosition() {
73         String JavaDoc searchedFor = "12345";
74         int searchStart = 0;
75         char[] buf = new char[] {'a', 'b', '1', '2', '3', 'x', 'x'};
76         int bufLen = 5;
77         int bufFrom = 2;
78         assertEquals(3, SearchUtil.checkPosition(searchedFor, searchStart, buf, bufLen, bufFrom));
79         
80     }
81     
82 }
83
Popular Tags