KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > html > lexer > JspLexerRandomTest


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.lib.html.lexer;
21
22 import junit.framework.TestCase;
23 import org.netbeans.api.html.lexer.HTMLTokenId;
24 import org.netbeans.lib.lexer.test.FixedTextDescriptor;
25 import org.netbeans.lib.lexer.test.LexerTestUtilities;
26 import org.netbeans.lib.lexer.test.RandomCharDescriptor;
27 import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
28 import org.netbeans.lib.lexer.test.RandomTextProvider;
29 import org.netbeans.lib.lexer.test.TestRandomModify;
30
31 /**
32  * Jsp Lexer random test
33  *
34  * @author Miloslav.Metelka@Sun.COM
35  * @author Marek.Fukala@Sun.COM
36  */

37 public class JspLexerRandomTest extends TestCase {
38     
39     public JspLexerRandomTest(String JavaDoc testName) {
40         super(testName);
41     }
42     
43     protected void setUp() throws java.lang.Exception JavaDoc {
44         // Set-up testing environment
45
LexerTestUtilities.setTesting(true);
46     }
47
48     protected void tearDown() throws java.lang.Exception JavaDoc {
49     }
50
51     public void testRandom() throws Exception JavaDoc {
52         test(0);
53     }
54     
55     private void test(long seed) throws Exception JavaDoc {
56         TestRandomModify randomModify = new TestRandomModify(seed);
57         randomModify.setLanguage(HTMLTokenId.language());
58         
59         //randomModify.setDebugOperation(true);
60
//randomModify.setDebugDocumentText(true);
61
//randomModify.setDebugHierarchy(true);
62

63         // Explicit inserts/removals checks
64
randomModify.insertText(0, "<a>");
65         randomModify.insertText(2, " "); //mfukala - IMO it will be broken even here
66
randomModify.removeText(2, 1);
67         
68         randomModify.clearDocument();
69
70         //mfukala - temp. test
71
randomModify.insertText(0, "<body>");
72         randomModify.insertText(5, " "); // error: '>' is text here
73
randomModify.insertText(6, "bgcolor='red'"); //error: attr name and value are lexed incorrectly
74
randomModify.clearDocument();
75         
76         // Begin really randomized testing
77
FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] {
78             FixedTextDescriptor.create("/>", 0.2),
79         };
80         
81         RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
82             RandomCharDescriptor.letter(0.2),
83             RandomCharDescriptor.space(0.2),
84             RandomCharDescriptor.lf(0.05),
85             RandomCharDescriptor.chars(new char[] { '<', '>', '=' }, 0.3),
86         };
87
88         RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts);
89         
90         randomModify.test(
91             new RandomModifyDescriptor[] {
92                 new RandomModifyDescriptor(200, regularTextProvider,
93                         0.4, 0.2, 0.2,
94                         0.1, 0.1,
95                         0.0, 0.0), // snapshots create/destroy
96
new RandomModifyDescriptor(200, regularTextProvider,
97                         0.2, 0.2, 0.1,
98                         0.4, 0.3,
99                         0.0, 0.0), // snapshots create/destroy
100
}
101         );
102     }
103     
104 }
105
Popular Tags