Skip to content
Snippets Groups Projects
Commit 396bf465 authored by apvrille's avatar apvrille
Browse files

Help manager with tests

parent 64a6aca2
No related branches found
No related tags found
No related merge requests found
......@@ -39,19 +39,9 @@
package help;
import common.ConfigurationTTool;
import common.SpecConfigTTool;
import launcher.RTLLauncher;
import myutil.PluginManager;
import myutil.TraceManager;
import ui.MainGUI;
import ui.util.IconManager;
import ui.window.JDialogSystemCGeneration;
import ui.*;
import java.io.File;
import java.util.BitSet;
import java.util.*;
import java.util.Vector;
/**
......@@ -61,7 +51,7 @@ import java.util.*;
*
* @author Ludovic APVRILLE
*/
public class HelpEntry {
public class HelpEntry {
public String pathToHTMLFile;
public String masterKeyword;
public String[] keywords;
......@@ -75,24 +65,26 @@ public class HelpEntry {
}
// infos are: file of name, master key, list of keywords
// Infos are: file of name, master key, list of keywords
public boolean fillInfos(String infos) {
infos = infos.trim();
infos = myutil.Conversion.replaceAllString(infos, " ", " ");
String[] splitted = infos.split(" ");
if (splitted.length < 3) {
TraceManager.addDev("Split too small");
return false;
}
pathToHTMLFile = splitted[0] + ".html";
masterKeyword = splitted[1];
keywords = new String[splitted.length-2];
for(int i = 2; i<splitted.length; i++) {
keywords[i] = splitted[i+2];
keywords = new String[splitted.length - 2];
for (int i = 0; i < splitted.length - 2; i++) {
keywords[i] = splitted[i + 2];
}
return true;
//TraceManager.addDev("Infos ok");
return true;
}
public int getNbInHierarchy() {
......@@ -133,19 +125,17 @@ public class HelpEntry {
public String printHierarchy(int n) {
String ret = "";
for (int i=0; i<n; i++){
for (int i = 0; i < n; i++) {
ret += " ";
}
ret += toString() + "\n";
if (entries != null) {
for(HelpEntry he: entries) {
ret += he.printHierarchy(n+1);
for (HelpEntry he : entries) {
ret += he.printHierarchy(n + 1);
}
}
return ret;
}
}
......@@ -43,12 +43,8 @@ import myutil.TraceManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
/**
......@@ -58,7 +54,7 @@ import java.util.Scanner;
*
* @author Ludovic APVRILLE
*/
public class HelpManager extends HelpEntry {
public class HelpManager extends HelpEntry {
private static String PATH_TO_INDEX = "helpTable.txt";
private static String INIT_CHAR = "-";
......@@ -71,53 +67,55 @@ public class HelpManager extends HelpEntry {
}
// Returns false in case of failure
public boolean loadEntries() {
if (helpLoaded) {
return true;
}
File file = getContent(PATH_TO_INDEX);
//File file = getContent(PATH_TO_INDEX);
URL url = getURL(PATH_TO_INDEX);
int lineNb = 0;
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
TraceManager.addDev("File=" + file);
//TraceManager.addDev("File=" + file);
HelpEntry currentHelpEntry = this;
HelpEntry currentHelpEntry = this;
//try (BufferedReader br = new BufferedReader(new FileReader(file))) {
//try {
//try (BufferedReader br = new BufferedReader(new FileReader(file))) {
//try {
String line;
lineNb ++;
lineNb++;
while ((line = in.readLine()) != null) {
// while ((line = br.readLine()) != null) {
TraceManager.addDev("Reading index line: " + line);
line = line.trim();
if (line.length() > 0) {
TraceManager.addDev("Getting number of inits");
int nb = getNumberOfInit(line);
TraceManager.addDev("Testing number of inits=" + nb);
if (nb > 0) {
TraceManager.addDev("Before adding Entry");
currentHelpEntry = addEntry(currentHelpEntry, nb, removeInitChars(line));
TraceManager.addDev("After adding Entry");
if (currentHelpEntry == null) {
TraceManager.addDev("\nHelp: error when loading help index file at line: " + lineNb + "\n");
return false;
}
}
}
// while ((line = br.readLine()) != null) {
//TraceManager.addDev("Reading index line: " + line);
line = line.trim();
if (line.length() > 0) {
//TraceManager.addDev("Getting number of inits");
int nb = getNumberOfInit(line);
//TraceManager.addDev("Testing number of inits=" + nb);
if (nb > 0) {
//TraceManager.addDev("Before adding Entry");
currentHelpEntry = addEntry(currentHelpEntry, nb, removeInitChars(line));
//TraceManager.addDev("After adding Entry");
if (currentHelpEntry == null) {
TraceManager.addDev("\nHelp: error when loading help index file at line: " + lineNb + "\n");
//System.exit(-1);
return false;
}
}
}
lineNb ++;
}
} catch (Exception e) {
TraceManager.addDev("Help: exception when loading help index file at line: " + lineNb + "\n");
//System.exit(-1);
return false;
}
......@@ -127,7 +125,7 @@ public class HelpManager extends HelpEntry {
return true;
}
public HelpEntry addEntry (HelpEntry entry, int inHierarchy, String infos){
public HelpEntry addEntry(HelpEntry entry, int inHierarchy, String infos) {
if (entry == null) {
return null;
}
......@@ -145,12 +143,17 @@ public class HelpManager extends HelpEntry {
return null;
}
//TraceManager.addDev("New node");
HelpEntry newNode = new HelpEntry();
boolean ok = newNode.fillInfos(infos);
if (!ok) {
TraceManager.addDev("HELP: Not ok");
return null;
}
//TraceManager.addDev("Before child");
// Child?
if (inHierarchy == (currentN + 1)) {
entry.addKid(newNode);
......@@ -158,6 +161,8 @@ public class HelpManager extends HelpEntry {
return newNode;
}
//TraceManager.addDev("Before brother");
// Brother?
if (inHierarchy == (currentN)) {
if (entry.getFather() == null) {
......@@ -183,10 +188,8 @@ public class HelpManager extends HelpEntry {
}
private String removeInitChars(String s) {
while(s.startsWith(INIT_CHAR)) {
while (s.startsWith(INIT_CHAR)) {
s = s.substring(1, s.length());
}
return s;
......@@ -194,8 +197,8 @@ public class HelpManager extends HelpEntry {
private int getNumberOfInit(String s) {
int cpt = 0;
while(s.startsWith(INIT_CHAR)) {
cpt ++;
while (s.startsWith(INIT_CHAR)) {
cpt++;
s = s.substring(1, s.length());
}
return cpt;
......@@ -207,24 +210,25 @@ public class HelpManager extends HelpEntry {
public static File getContent(String resource) {
try {
TraceManager.addDev("Getting resource:" + resource);
TraceManager.addDev("Getting help resource:" + resource);
URL url = HelpManager.class.getResource(resource);
if (url != null) {
TraceManager.addDev("url = " + url);
TraceManager.addDev("help url = " + url);
File myFile = new File(url.toURI());
return myFile;
}
TraceManager.addDev("NULL URL");
} catch (Exception e) {}
//TraceManager.addDev("NULL URL");
} catch (Exception e) {
}
return null;
}
public String printHierarchy() {
String top = "root\n";
for(HelpEntry he: entries) {
for (HelpEntry he : entries) {
top += he.printHierarchy(1);
}
return top;
......
- general TTool general
- general TTool general info tool
- diplodocus diplodocus hardware software partitioning dse design space exploration
-- architecture
-- architecture architecture hardware os operating system
--- cpu cpu processor cpu os
----clockdivider clock_divider clock divider cpu
- avatar avatar software embedded systems
/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* /**
* Class AvatarGuardTests
* Creation: 20/05/2015
* @version 1.1 01/07/2015
* @author Ludovic APVRILLE, Letitia LI
* @see
*/
package help;
import org.junit.Test;
import org.junit.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.Vector;
import ui.TAttribute;
import avatartranslator.*;
public class HelpTests {
AvatarGuard res;
AvatarBlock A,B;
public HelpTests () {
// super ("AvatarGuards", false);
}
@Test
public void testLoadHelp(){
HelpManager helpManager;
helpManager = new HelpManager();
boolean ok = helpManager.loadEntries();
assertTrue(ok);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment