📄 testdata.java
字号:
String skip = null;
eventList.test(f);
rslt.append(eventListName(f,null));
rslt.append(" $ " + testInfo(f) + " {");
if ( eventList.testResult.getClass() != LookingForRDF.class)
for (int i=0;i<characters.length;i++) {
if (skip != null && characters[i].startsWith(skip))
continue;
skip = null;
addEvents(characters[i]);
rslt.append( " " + characters[i]+ " $ ");
boolean testV = eventList.test(f);
rslt.append( testInfo(f) + " ;");
eventList.size = sz;
if ( !testV ) {
skip = characters[i];
continue;
}
}
rslt.append(" }");
data.add(rslt.toString());
inCharacterize = false;
}
private String eventListName(Class f, Class f2) {
StringBuffer rslt = new StringBuffer();
rslt.append(stateName(f, f2));
for (int i=0;i<eventList.size;i++) {
rslt.append(' ');
rslt.append(eventList.events[i].oneChar);
}
return rslt.toString();
}
private String stateName(Class f, Class f2) {
return f==f2?"*":(String)state2ShortName.get(f);
}
private void addEvents(String string) {
String all[] = string.split(" ");
for (int i=0;i<all.length;i++){
eventList.add((Event)short2Event.get(all[i]));
}
}
private String testInfo(Class f) {
return
eventList.testFailure ? (eventList.testException ? "!" : "?") :
(stateName(eventList.testResult.getClass(),f) + " " +
xmlHandler.info() + " " + testFrame.info());
}
static Class tryClasses[] = { FrameI.class, AbsXMLLiteral.class,
HasSubjectFrameI.class, WantsObjectFrameI.class };
static FrameI create(Class cl) throws InstantiationException, IllegalAccessException, InvocationTargetException {
FrameI frame = null;
Object args[] = (Object[]) state2Args.get(cl);
Class types[] = new Class[args.length];
for (int i = 1; i < args.length; i++) {
types[i] = args[i].getClass();
if (types[i]==XMLContext.class)
types[i] = AbsXMLContext.class;
}
if (cl == InnerXMLLiteral.class)
types[2] = Map.class;
for (int j = 0; j < tryClasses.length; j++) {
types[0] = tryClasses[j];
try {
frame = (FrameI) cl.getConstructor(types).newInstance(args);
break;
} catch (NoSuchMethodException e) {
continue;
}
}
return frame;
}
void expand(Class f) {
if (AbsXMLLiteral.class.isAssignableFrom(f))
return;
if (randomPurgeXMLAttrs())
return;
localCount++;
globalCount++;
if (localCount % 20000 == 0)
stats(f);
if (!eventList.test(f)) {
if (!shorterTestFails(f))
data.add(eventListName(f,null)+" $ " + testInfo(f));
return;
}
characterize(f);
if (eventList.size >= (AbsXMLLiteral.class.isAssignableFrom(f) ? 3 :
eventList.testResult instanceof LookingForRDF ? 2
: 8))
return;
for (int i = 0; i < allEvents.length; i++) {
if (allEvents[i].isAttribute()) {
Event e = eventList.last();
if (!(e.isElement() || (e.isAttribute() && e.hashCode() < allEvents[i]
.hashCode())))
continue;
} else if (true) {
continue;
}
eventList.add(allEvents[i]);
expand(f);
eventList.pop();
}
}
private Random dice = new Random(23);
private boolean randomPurgeXMLAttrs() {
int weight = 0;
eventList.rewind();
while (eventList.hasNext()) {
Event e = eventList.next();
if ( e==xmlSpace)
weight += 2;
else if ( e.isAttribute() && ((AttrEvent)e).q.uri.equals(Names.xmlns) )
weight ++;
}
while (weight-- >0)
if (dice.nextBoolean())
return true;
return false;
}
private boolean shorterTestFails(Class f) {
if (eventList.size <= 2)
return false;
for (int i=1;i<eventList.size-1;i++){
EventList copy = eventList.copy();
copy.delete(i);
if (!copy.test(f))
return true;
}
return false;
}
Set data = new TreeSet(new Comparator(){
public int compare(Object arg1, Object arg2) {
StringBuffer b1 = new StringBuffer((String)arg1).reverse();
StringBuffer b2 = new StringBuffer((String)arg2).reverse();
return b1.toString().compareTo(b2.toString());
}}
);
void stats(Class f) {
if (false)
System.out.println(state2ShortName.get(f) + ":" + state2Name.get(f)
+ ":" + getSimpleName(f) + " " + localCount + "/"
+ globalCount);
}
void test1() throws IOException {
Iterator it = state2Name.keySet().iterator();
while (it.hasNext()) {
Class f = (Class) it.next();
// System.out.println(state2ShortName.get(f) + ":" + state2Name.get(f)
// + ":" + f.getSimpleName());
localCount = 0;
for (int i = 0; i < allEvents.length; i++) {
if (allEvents[i].isElement()) {
eventList.clear();
eventList.add(allEvents[i]);
expand(f);
}
}
stats(f);
}
FileWriter fw = new FileWriter(dataFile);
it = data.iterator();
while (it.hasNext()) {
fw.write((String)it.next());
fw.write('\n');
}
fw.close();
}
static public void main(String args[]) throws IOException {
long start = System.currentTimeMillis();
new TestData().test1();
System.out.println((System.currentTimeMillis()-start) + " ms");
}
public static String stateLongName(String sh) {
return (String)state2Name.get(shortName2State.get(sh));
}
public static Class toState(String sh) {
return (Class)shortName2State.get(sh);
}
}
/*
* (c) Copyright 2005, 2006, 2007 Hewlett-Packard Development Company, LP All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. The name of the author may not
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -