1 package be
.nikiroo
.fanfix
.test
;
4 import java
.io
.FileOutputStream
;
5 import java
.io
.IOException
;
6 import java
.util
.Properties
;
8 import be
.nikiroo
.fanfix
.Instance
;
9 import be
.nikiroo
.fanfix
.bundles
.ConfigBundle
;
10 import be
.nikiroo
.utils
.IOUtils
;
11 import be
.nikiroo
.utils
.TempFiles
;
12 import be
.nikiroo
.utils
.resources
.Bundles
;
13 import be
.nikiroo
.utils
.test
.TestLauncher
;
20 public class Test
extends TestLauncher
{
22 // 3 files can control the test:
23 // - test/VERBOSE: enable verbose mode
24 // - test/OFFLINE: to forbid any downloading
25 // - test/FORCE_REFRESH: to force a clear of the cache
27 // The test files will be:
28 // - test/*.url: URL to download in text format, content = URL
29 // - test/*.story: text mode story, content = story
33 * The temporary files handler.
35 static TempFiles tempFiles
;
38 * Create the Fanfix {@link TestLauncher}.
41 * the arguments to configure the number of columns and the ok/ko
46 public Test(String
[] args
) throws IOException
{
47 super("Fanfix", args
);
48 Instance
.setTraceHandler(null);
49 addSeries(new BasicSupportUtilitiesTest(args
));
50 addSeries(new BasicSupportDeprecatedTest(args
));
51 addSeries(new LibraryTest(args
));
53 File sources
= new File("test/");
54 if (sources
.isDirectory()) {
55 for (File file
: sources
.listFiles()) {
56 if (file
.isDirectory()) {
60 String expectedDir
= new File(file
.getParentFile(), "expected_"
61 + file
.getName()).getAbsolutePath();
62 String resultDir
= new File(file
.getParentFile(), "result_"
63 + file
.getName()).getAbsolutePath();
66 if (file
.getName().endsWith(".url")) {
67 uri
= IOUtils
.readSmallFile(file
).trim();
68 } else if (file
.getName().endsWith(".story")) {
69 uri
= file
.getAbsolutePath();
74 addSeries(new ConversionTest(uri
, expectedDir
, resultDir
, args
));
80 * Main entry point of the program.
83 * the arguments passed to the {@link TestLauncher}s.
85 * in case of I/O error
87 static public void main(String
[] args
) throws IOException
{
91 boolean verbose
= new File("test/VERBOSE").exists();
94 boolean forceRefresh
= new File("test/FORCE_REFRESH").exists();
96 // Only download files if allowed:
97 boolean offline
= new File("test/OFFLINE").exists();
98 Instance
.getCache().setOffline(offline
);
101 tempFiles
= new TempFiles("fanfix-test");
103 File tmpConfig
= tempFiles
.createTempDir("fanfix-config");
104 File localCache
= new File("test/CACHE");
106 IOUtils
.deltree(localCache
);
110 FileOutputStream out
= null;
112 out
= new FileOutputStream(new File(tmpConfig
,
113 "config.properties"));
114 Properties props
= new Properties();
115 props
.setProperty("CACHE_DIR", localCache
.getAbsolutePath());
116 props
.store(out
, null);
123 ConfigBundle config
= new ConfigBundle();
124 Bundles
.setDirectory(tmpConfig
.getAbsolutePath());
125 config
.updateFile(tmpConfig
.getPath());
127 System
.setProperty("CONFIG_DIR", tmpConfig
.getAbsolutePath());
129 TestLauncher tests
= new Test(args
);
130 tests
.setDetails(verbose
);
132 result
= tests
.launch();
134 IOUtils
.deltree(tmpConfig
);
135 IOUtils
.deltree(localCache
);
140 // This is usually done in Fanfix.Main:
141 Instance
.getTempFiles().close();