alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.test.web.editor.completion;

import java.io.File;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.*;
import org.netbeans.junit.*;
import org.netbeans.junit.diff.LineDiff;

/**
 *
 * @author  Marek Fukala
 */
public class CompletionTest extends NbTestCase {
    
    public static void main(String[] args) {
        System.out.println("starting editor tests");
        junit.textui.TestRunner.run(suite());
    }
    
    public static Test suite() {
        NbTestSuite suite = new NbTestSuite("CompletionTest");
        try {
            //I need to get a list of projects
            File datadir = new CompletionTest(null, null,null).getDataDir();
            //File projectsDir = new File(datadir.getParentFile(), "editortests/data/projects");
            File projectsDir = new File(datadir, "projects");
            
            System.out.println("projects dir = " + projectsDir.getAbsolutePath());
            
            //get list of projects to be used for testing
            File[] projects = projectsDir.listFiles();
            
            System.out.println("available projects:");
            for(int i = 0; i < projects.length; i++) {
                System.out.println(projects[i].getAbsolutePath());
                
                //create ProjectInfo instance for the project;
                //the PI contains information about test which should be performed on the project
                ProjectInfo pi = new ProjectInfo(projects[i]);
                
                //create CompletionTestSupport for this project
                CompletionTestSupport cts = new CompletionTestSupport(projects[i]);
                
                //iterate throught all tested files in the project
                ProjectInfo.TestFileInfo tfis[] = pi.getTestFileInfos();
                for(int j = 0; j < tfis.length; j++) {
                    ProjectInfo.TestFileInfo tfi = tfis[j];
                    
                    //create a filecompletionRequester for the file
                    CompletionTestSupport.FileCompletionRequester fcr = cts.getFileCompletionRequester(tfi.getTestFileName());
                    
                    //create and add a new testcase for the actual project/file
                    String testcaseName = "test_" + pi.getProjectPath().getName() + "_" + tfi.getTestFileName();
                    CompletionTest ct = new CompletionTest(testcaseName.replace('/','_'), fcr, tfi);
                    suite.addTest(ct);
                    
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return suite;
    }
    
    //instance fields
    private CompletionTestSupport.FileCompletionRequester fcr;
    private ProjectInfo.TestFileInfo tfi;
    
    public CompletionTest(String testName, CompletionTestSupport.FileCompletionRequester fcr, ProjectInfo.TestFileInfo tfi) {
        super(testName);
        this.fcr = fcr;
        this.tfi = tfi;
    }
    
    protected void runTest() throws Throwable {
        PrintStream ref = getRef();
        //get indexes to be tested
        int[][] indexes = tfi.getIndexes();
        
        for(int k = 0; k < indexes.length; k++) {
            //invoke cc on row-lineindex
            String[] cc = fcr.getCompletion(indexes[k][0], indexes[k][1]);
            //print the cc
            ref.println("CC on [" + indexes[k][0] +"," + indexes[k][1] + "]:\n-------------");
            for(int z = 0; z < cc.length; z++) {
                ref.println(cc[z]);
            }
        }
    }
    
    protected void tearDown() throws Exception {
        compareReferenceFiles();
    }
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.