Package freegressi.graphics

Source Code of freegressi.graphics.FilesTest

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    Copyright (C) 2013  Marchand Eric <ricoh51@free.fr>
   
    This file is part of Freegressi.

    Freegressi is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Freegressi is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Freegressi.  If not, see <http://www.gnu.org/licenses/>.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package freegressi.graphics;

import freegressi.main.FRGHandler;
import freegressi.main.MainModel;
import freegressi.main.UndoRedo;
import freegressi.tableur.EditColumnsModel;
import freegressi.tableur.SpreadSheets;
import freegressi.fit.FitModel;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.junit.Test;
import org.xml.sax.SAXException;

/**
* Teste la création de nouveaux documents
* @author marchand, 17 avr. 2013, 09:17:15
*/
public class FilesTest {
  private static int nBons = 0, nTotal = 0;

  public FilesTest(){
    // Le undoredo écoute le tendancemodel
    FitModel.getInstance().addTendanceListener(UndoRedo.getInstance());
    // le undoredo écoute le mainmodel
    MainModel.getInstance().addMainListener(UndoRedo.getInstance());
    // le undoredo écoute le SpreadSheets
    SpreadSheets.getInstance().addSheetsListener(UndoRedo.getInstance());
    // Le FitModel écoute le SpreadSheets
    SpreadSheets.getInstance().addSheetsListener(FitModel.getInstance());
    // Le GraphicModel écoute le SpreadSheets
    SpreadSheets.getInstance().addSheetsListener(GraphicModel.getInstance());
    // Le EditColumnModel écoute le SpreadSheets
    SpreadSheets.getInstance().addSheetsListener(EditColumnsModel.getInstance());
    // Le EditColumnModel écoute le MainModel
    MainModel.getInstance().addMainListener(EditColumnsModel.getInstance());       
  }
 
  /**
   * Tests.
   */
  @Test
  public void test() {
   
    System.out.println("******* Files *******");
   
    errorRapport(openFile("test1.frg"), "Erreur à l'ouverture de test1");
    errorRapport(openFile("1000sinxsurx.frg"), "Erreur à l'ouverture de 1000sinxsurx");
   
    System.out.println("Files : " + nBons + "/"+nTotal+" tests passés avec succès!");
  }  
 
  private boolean testCurve(String fileName, String varX, String varY){
   
    return true;
  }
 
  private boolean openFile(String fileName){
    String dir = "test/frg/";
    File file = new File(dir + fileName);
    SAXParserFactory fabrique = SAXParserFactory.newInstance();
    FRGHandler gestionnaire = new FRGHandler();
    try {
      SAXParser parseur = fabrique.newSAXParser();
      parseur.parse(file, gestionnaire);
    } catch (ParserConfigurationException | SAXException | IOException exc) {
      System.err.println("Erreur pendant la lecture du document! : "
              + exc.getMessage());
      JOptionPane.showMessageDialog(null,
              "Erreur pendant la lecture du document!\n" + file.getName() +
              "\n" + exc.getMessage(),
              "Oups une erreur...", JOptionPane.ERROR_MESSAGE);
      return false;
    }

    if (!gestionnaire.isFichierOk()) {
      JOptionPane.showMessageDialog(null,
              "Il n'y a pas de données dans ce document!\n" + file.getName(),
              "Oups une erreur...", JOptionPane.ERROR_MESSAGE);
      return false;
    }
   
   
   
    return true;
   
  }
  private void errorRapport(boolean ok, String errorText){
    nTotal++;
    if (!ok){
      System.out.println(errorText);
    }else{
      nBons++;
    }
  }
 
}
TOP

Related Classes of freegressi.graphics.FilesTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.