/* Generated By:JJTree&JavaCC: Do not edit this line. AtFormulaParser.java */
package de.foconis.test.formula;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jline.ANSIBuffer;
import jline.Terminal;
import org.openntf.formula.Formulas;
public abstract class TestRunnerCommon implements Runnable {
private boolean VIRTUAL_CONSOLE = false;
public TestRunnerCommon() {
// whatever you might want to do in your constructor, but stay away from Domino objects
VIRTUAL_CONSOLE = Terminal.getTerminal().getTerminalWidth() < 10;
}
// Some Formatters
public String NTF(final Object o) {
if (VIRTUAL_CONSOLE)
return o.toString();
ANSIBuffer ab = new ANSIBuffer();
return ab.cyan(o.toString()).toString();
}
public String LOTUS(final Object o) {
if (VIRTUAL_CONSOLE)
return o.toString();
ANSIBuffer ab = new ANSIBuffer();
return ab.magenta(o.toString()).toString();
}
public String ERROR(final Object o) {
if (VIRTUAL_CONSOLE)
return o.toString();
ANSIBuffer ab = new ANSIBuffer();
return ab.red(o.toString()).toString();
}
public String SUCCESS() {
if (VIRTUAL_CONSOLE)
return "[OK]\t";
ANSIBuffer ab = new ANSIBuffer();
ab.append("[");
ab.green("OK");
ab.append("]\t");
return ab.toString();
}
public String FAIL() {
if (VIRTUAL_CONSOLE)
return "[FAIL]\t";
ANSIBuffer ab = new ANSIBuffer();
ab.append("[");
ab.red("FAIL");
ab.append("]\t");
return ab.toString();
}
protected String formatTime(final long time) {
return String.format("%.3f ms", (double) time / 1000000);
}
protected void fillDemoDoc(final Map<String, Object> doc, final double rndVal) {
doc.put("rnd", new double[] { rndVal });
doc.put("text1", "This is a test string");
doc.put("text2", new String[] { "1", "2", "3" });
doc.put("int1", new int[] { 1 });
doc.put("int2", new int[] { 1, 2, 3 });
Map<String, String> map = new HashMap<String, String>();
map.put("K1", "v1");
map.put("K2", "v2");
doc.put("mime1", map);
}
protected String dump(final Object lotus) {
// TODO Auto-generated method stub
int width = Terminal.getTerminal().getTerminalWidth() - 20;
String s = lotus + "";
if (s.length() > width && width > 0) {
s = s.substring(0, width) + "... (l=" + width + ")";
}
return s;
}
protected boolean compareList(final List<Object> list1, final List<Object> list2) {
boolean equals = true;
if (list1 == null && list2 == null)
return true;
if (list1 == null || list2 == null)
return false;
if (list1.size() == 0 && list2.size() == 1) {
if ("".equals(list2.get(0)))
return true;
}
if (list2.size() == 0 && list1.size() == 1) {
if ("".equals(list1.get(0)))
return true;
}
if (list1.size() == list2.size()) {
for (int i = 0; i < list1.size(); i++) {
Object a = list1.get(i);
Object b = list2.get(i);
if (a == null && b == null) {
} else if (a == null || b == null) {
equals = false;
break;
} else if (a instanceof Boolean && b instanceof Number) {
if ((Boolean) a) {
if (Double.compare(1.0, ((Number) b).doubleValue()) != 0) {
equals = false;
break;
}
} else {
if (Double.compare(0.0, ((Number) b).doubleValue()) != 0) {
equals = false;
break;
}
}
} else if (a instanceof Number && b instanceof Number) {
if (Double.compare(((Number) a).doubleValue(), ((Number) b).doubleValue()) != 0) {
equals = false;
break;
}
} else if ((a instanceof org.openntf.formula.DateTime || a instanceof lotus.domino.DateTime) && // LF
(b instanceof org.openntf.formula.DateTime || b instanceof lotus.domino.DateTime)) {
try {
org.openntf.formula.DateTime sdt1, sdt2;
if (a instanceof org.openntf.formula.DateTime)
sdt1 = (org.openntf.formula.DateTime) a;
else {
lotus.domino.DateTime ldt = (lotus.domino.DateTime) a;
sdt1 = Formulas.getFormatter().getNewInitializedSDTInstance(ldt.toJavaDate(), ldt.getDateOnly().isEmpty(),
ldt.getTimeOnly().isEmpty());
}
if (b instanceof org.openntf.formula.DateTime)
sdt2 = (org.openntf.formula.DateTime) b;
else {
lotus.domino.DateTime ldt = (lotus.domino.DateTime) b;
sdt2 = Formulas.getFormatter().getNewInitializedSDTInstance(ldt.toJavaDate(), ldt.getDateOnly().isEmpty(),
ldt.getTimeOnly().isEmpty());
}
equals = (sdt1.compare(sdt1, sdt2) == 0);
} catch (Exception e) {
e.printStackTrace();
equals = false;
}
} else if (!a.equals(b)) {
equals = false;
break;
}
}
} else {
equals = false;
}
return equals;
}
}