| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.regression; |
| 20 |
|
| 21 |
import java.io.FileNotFoundException; |
| 22 |
import java.text.ParseException; |
| 23 |
|
| 24 |
import footleg.cavesurvey.converter.CaveConverter; |
| 25 |
import footleg.cavesurvey.converter.CaveConverter.CmdlineOpt; |
| 26 |
import footleg.cavesurvey.converter.CaveConverter.CmdlineSplaysOpt; |
| 27 |
import footleg.cavesurvey.converter.CaveConverter.SurveyDataInputFormats; |
| 28 |
import footleg.cavesurvey.converter.CaveConverter.SurveyDataOutputFormats; |
| 29 |
import footleg.cavesurvey.converter.CmdLineLogger; |
| 30 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public final class RunFileConverter { |
| 45 |
final static String refFilesLocation = "./test/data/regression/"; |
| 46 |
final static String genFilesLocation = "./build/test/data/"; |
| 47 |
final static String defaultCharset = "UTF8"; |
| 48 |
|
| 49 |
private static boolean oldJRE = false; |
| 50 |
|
| 51 |
private static final char compassFormat = 'c'; |
| 52 |
private static final char dxfFormat = 'd'; |
| 53 |
private static final char pocketTopoFormat = 'p'; |
| 54 |
private static final char survexFormat = 's'; |
| 55 |
private static final char toporobotFormat = 't'; |
| 56 |
|
| 57 |
public static void setOldJRE(boolean oldJRE) { |
| 58 |
RunFileConverter.oldJRE = oldJRE; |
| 59 |
} |
| 60 |
|
| 61 |
public static String convertCompassToSurvex( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 62 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 63 |
|
| 64 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.Compass, SurveyDataOutputFormats.Survex, |
| 65 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 66 |
return fileCompare; |
| 67 |
} |
| 68 |
|
| 69 |
public static String convertDxfToSurvex( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 70 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 71 |
|
| 72 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.DXF, SurveyDataOutputFormats.Survex, |
| 73 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 74 |
return fileCompare; |
| 75 |
} |
| 76 |
|
| 77 |
public static String convertSurvexToSurvex( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 78 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 79 |
|
| 80 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.Survex, SurveyDataOutputFormats.Survex, |
| 81 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 82 |
return fileCompare; |
| 83 |
} |
| 84 |
|
| 85 |
public static String convertSurvexToTopoRobot( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 86 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 87 |
|
| 88 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.Survex, SurveyDataOutputFormats.Toporobot, |
| 89 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 90 |
return fileCompare; |
| 91 |
} |
| 92 |
|
| 93 |
public static String convertDxfToTopoRobot( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 94 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 95 |
|
| 96 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.DXF, SurveyDataOutputFormats.Toporobot, |
| 97 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 98 |
return fileCompare; |
| 99 |
} |
| 100 |
|
| 101 |
public static String convertPocketTopoToSurvex( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 102 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 103 |
|
| 104 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.PocketTopo, SurveyDataOutputFormats.Survex, |
| 105 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 106 |
return fileCompare; |
| 107 |
} |
| 108 |
|
| 109 |
public static String convertPocketTopoToToporobot( String filePrefix, CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, |
| 110 |
String charSetEncoding ) throws ParseException, FileNotFoundException { |
| 111 |
|
| 112 |
String fileCompare = convertFile( filePrefix, SurveyDataInputFormats.PocketTopo, SurveyDataOutputFormats.Toporobot, |
| 113 |
splaysOpt, genLRUDOpt, charSetEncoding, new CmdLineLogger() ); |
| 114 |
return fileCompare; |
| 115 |
} |
| 116 |
|
| 117 |
private static String generateFileSuffix( SurveyDataInputFormats format ) { |
| 118 |
String fileSuffix = ""; |
| 119 |
|
| 120 |
if( format == SurveyDataInputFormats.PocketTopo ) { |
| 121 |
fileSuffix = ".txt"; |
| 122 |
} |
| 123 |
else if( format == SurveyDataInputFormats.DXF ) { |
| 124 |
fileSuffix = ".dxf"; |
| 125 |
} |
| 126 |
else if( format == SurveyDataInputFormats.Survex ) { |
| 127 |
fileSuffix = ".svx"; |
| 128 |
} |
| 129 |
else if( format == SurveyDataInputFormats.Compass ) { |
| 130 |
fileSuffix = ".dat"; |
| 131 |
} |
| 132 |
else { |
| 133 |
fileSuffix = ".txt"; |
| 134 |
} |
| 135 |
|
| 136 |
return fileSuffix; |
| 137 |
} |
| 138 |
|
| 139 |
private static String generateFileSuffix( SurveyDataOutputFormats format ) { |
| 140 |
String fileSuffix = ""; |
| 141 |
|
| 142 |
if( format == SurveyDataOutputFormats.Survex ) { |
| 143 |
fileSuffix = ".svx"; |
| 144 |
} |
| 145 |
else if( format == SurveyDataOutputFormats.Toporobot ) { |
| 146 |
fileSuffix = ".text"; |
| 147 |
} |
| 148 |
else { |
| 149 |
fileSuffix = ".svx"; |
| 150 |
} |
| 151 |
|
| 152 |
return fileSuffix; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
private static String generateInputFilename( String filePrefix, SurveyDataInputFormats fromFormat ) { |
| 157 |
return refFilesLocation + filePrefix + "_in" + generateFileSuffix( fromFormat ); |
| 158 |
} |
| 159 |
|
| 160 |
private static char letterCodeFromInputDataFormat( SurveyDataInputFormats format ) { |
| 161 |
char letterCode = 'x'; |
| 162 |
|
| 163 |
switch ( format) { |
| 164 |
case Compass: |
| 165 |
letterCode = compassFormat; |
| 166 |
break; |
| 167 |
case DXF: |
| 168 |
letterCode = dxfFormat; |
| 169 |
break; |
| 170 |
case PocketTopo: |
| 171 |
letterCode = pocketTopoFormat; |
| 172 |
break; |
| 173 |
case Survex: |
| 174 |
letterCode = survexFormat; |
| 175 |
break; |
| 176 |
} |
| 177 |
|
| 178 |
return letterCode; |
| 179 |
} |
| 180 |
|
| 181 |
private static char letterCodeFromOutputDataFormat( SurveyDataOutputFormats format ) { |
| 182 |
char letterCode = 'x'; |
| 183 |
|
| 184 |
switch ( format) { |
| 185 |
case Survex: |
| 186 |
letterCode = survexFormat; |
| 187 |
break; |
| 188 |
case Toporobot: |
| 189 |
letterCode = toporobotFormat; |
| 190 |
break; |
| 191 |
} |
| 192 |
|
| 193 |
return letterCode; |
| 194 |
} |
| 195 |
|
| 196 |
private static String generateFilename( String location, String filePrefix, SurveyDataInputFormats fromFormat, SurveyDataOutputFormats toFormat, |
| 197 |
CmdlineSplaysOpt splaysOpt, String suffix ) { |
| 198 |
String splayOptString = ""; |
| 199 |
if ( splaysOpt == CmdlineSplaysOpt.Named ) { |
| 200 |
splayOptString = "_spl"; |
| 201 |
} |
| 202 |
else if ( splaysOpt == CmdlineSplaysOpt.None ) { |
| 203 |
splayOptString = "_nsp"; |
| 204 |
} |
| 205 |
else if ( splaysOpt == CmdlineSplaysOpt.Anon ) { |
| 206 |
splayOptString = "_asp"; |
| 207 |
} |
| 208 |
return location + filePrefix + "_" + letterCodeFromInputDataFormat( fromFormat ) + letterCodeFromOutputDataFormat( toFormat ) + splayOptString + "_" + suffix + generateFileSuffix( toFormat ); |
| 209 |
} |
| 210 |
|
| 211 |
private static String generateRefFilename( String filePrefix, SurveyDataInputFormats fromFormat, SurveyDataOutputFormats toFormat, CmdlineSplaysOpt splaysOpt, boolean oldJRE ) { |
| 212 |
String suffix = "ref"; |
| 213 |
if ( oldJRE ) { |
| 214 |
suffix += "7"; |
| 215 |
} |
| 216 |
return generateFilename( refFilesLocation, filePrefix, fromFormat, toFormat, splaysOpt, suffix ); |
| 217 |
} |
| 218 |
|
| 219 |
private static String generateOutputFilename( String filePrefix, SurveyDataInputFormats fromFormat, SurveyDataOutputFormats toFormat, CmdlineSplaysOpt splaysOpt ) { |
| 220 |
return generateFilename( genFilesLocation, filePrefix, fromFormat, toFormat, splaysOpt, "testgen" ); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
private static void setDateForConversions() { |
| 228 |
|
| 229 |
try { |
| 230 |
CaveConverter.setToday( UtilityFunctions.stringToDate("16/08/2012 13:14:15", "dd/MM/yyyy HH:mm:ss") ); |
| 231 |
} catch (ParseException e) { |
| 232 |
|
| 233 |
e.printStackTrace(); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
private static String convertFile( String filePrefix, SurveyDataInputFormats fromFormat, SurveyDataOutputFormats toFormat, |
| 238 |
CmdlineSplaysOpt splaysOpt, CmdlineOpt genLRUDOpt, String charSetEncoding, CmdLineLogger logger ) throws ParseException, FileNotFoundException { |
| 239 |
|
| 240 |
String inputFile = generateInputFilename(filePrefix, fromFormat); |
| 241 |
String outputFile = generateOutputFilename(filePrefix, fromFormat, toFormat, splaysOpt); |
| 242 |
String referenceFile = generateRefFilename(filePrefix, fromFormat, toFormat, splaysOpt, oldJRE); |
| 243 |
|
| 244 |
setDateForConversions(); |
| 245 |
|
| 246 |
|
| 247 |
CaveConverter.convertFile(inputFile, outputFile, fromFormat, toFormat, splaysOpt, genLRUDOpt, charSetEncoding, logger); |
| 248 |
|
| 249 |
|
| 250 |
String fileCompare = DiffFiles.diffFiles( referenceFile, outputFile ); |
| 251 |
|
| 252 |
return fileCompare; |
| 253 |
} |
| 254 |
|
| 255 |
public static String convertUsingCmdLine( String filePrefix, char fromFormatCode, char toFormatCode, String options ) throws ParseException, FileNotFoundException { |
| 256 |
SurveyDataInputFormats fromFormat = UtilityFunctions.inputDataFormatFromLetterCode( fromFormatCode ); |
| 257 |
SurveyDataOutputFormats toFormat = UtilityFunctions.outputDataFormatFromLetterCode( toFormatCode ); |
| 258 |
String inputFile = generateInputFilename(filePrefix, fromFormat); |
| 259 |
String outputFile = generateOutputFilename(filePrefix, fromFormat, toFormat, CmdlineSplaysOpt.None); |
| 260 |
String referenceFile = generateRefFilename(filePrefix, fromFormat, toFormat, CmdlineSplaysOpt.None, oldJRE); |
| 261 |
|
| 262 |
|
| 263 |
String fileSuffix = "_cmd"; |
| 264 |
if ( options.contains("nosplays") ) { |
| 265 |
fileSuffix += "n"; |
| 266 |
} |
| 267 |
else if ( options.contains("splays") ) { |
| 268 |
fileSuffix += "s"; |
| 269 |
} |
| 270 |
if ( options.contains("lrud") ) { |
| 271 |
fileSuffix += "l"; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
outputFile = outputFile.replace("_nsp", fileSuffix); |
| 276 |
referenceFile = referenceFile.replace("_nsp", fileSuffix); |
| 277 |
|
| 278 |
setDateForConversions(); |
| 279 |
|
| 280 |
String[] opts = options.split(" "); |
| 281 |
int numArgs = 4 + opts.length; |
| 282 |
String[] args = new String[numArgs]; |
| 283 |
args[0] = inputFile; |
| 284 |
args[1] = outputFile; |
| 285 |
args[2] = "" + letterCodeFromInputDataFormat( fromFormat ); |
| 286 |
args[3] = "" + letterCodeFromOutputDataFormat( toFormat ); |
| 287 |
for (int iArg = 0; iArg < opts.length; iArg++ ) { |
| 288 |
args[4 + iArg] = opts[iArg]; |
| 289 |
} |
| 290 |
|
| 291 |
CaveConverter.main(args); |
| 292 |
|
| 293 |
|
| 294 |
String fileCompare = DiffFiles.diffFiles( referenceFile, outputFile ); |
| 295 |
|
| 296 |
return fileCompare; |
| 297 |
} |
| 298 |
} |