1 package be
.nikiroo
.fanfix
.test
;
4 import java
.io
.IOException
;
6 import be
.nikiroo
.fanfix
.Instance
;
7 import be
.nikiroo
.fanfix
.bundles
.Config
;
8 import be
.nikiroo
.fanfix
.bundles
.ConfigBundle
;
9 import be
.nikiroo
.utils
.IOUtils
;
10 import be
.nikiroo
.utils
.TempFiles
;
11 import be
.nikiroo
.utils
.resources
.Bundles
;
12 import be
.nikiroo
.utils
.test
.TestLauncher
;
19 public class Test
extends TestLauncher
{
21 // 3 files can control the test:
22 // - test/VERBOSE: enable verbose mode
23 // - test/OFFLINE: to forbid any downloading
24 // - test/FORCE_REFRESH: to force a clear of the cache
26 // The test files will be:
27 // - test/*.url: URL to download in text format, content = URL
28 // - test/*.story: text mode story, content = story
32 * The temporary files handler.
34 static TempFiles tempFiles
;
37 * Create the Fanfix {@link TestLauncher}.
40 * the arguments to configure the number of columns and the ok/ko
45 public Test(String
[] args
) throws IOException
{
46 super("Fanfix", args
);
47 Instance
.setTraceHandler(null);
48 addSeries(new BasicSupportUtilitiesTest(args
));
49 addSeries(new BasicSupportDeprecatedTest(args
));
50 addSeries(new LibraryTest(args
));
52 File sources
= new File("test/");
53 if (sources
.isDirectory()) {
54 for (File file
: sources
.listFiles()) {
55 if (file
.isDirectory()) {
59 String expectedDir
= new File(file
.getParentFile(), "expected_"
60 + file
.getName()).getAbsolutePath();
61 String resultDir
= new File(file
.getParentFile(), "result_"
62 + file
.getName()).getAbsolutePath();
65 if (file
.getName().endsWith(".url")) {
66 uri
= IOUtils
.readSmallFile(file
).trim();
67 } else if (file
.getName().endsWith(".story")) {
68 uri
= file
.getAbsolutePath();
73 addSeries(new ConversionTest(file
.getName(), uri
, expectedDir
,
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 ConfigBundle config
= new ConfigBundle();
111 Bundles
.setDirectory(tmpConfig
.getAbsolutePath());
112 config
.setString(Config
.CACHE_DIR
, localCache
.getAbsolutePath());
113 config
.setInteger(Config
.CACHE_MAX_TIME_STABLE
, -1);
114 config
.setInteger(Config
.CACHE_MAX_TIME_CHANGING
, -1);
115 config
.updateFile(tmpConfig
.getPath());
116 System
.setProperty("CONFIG_DIR", tmpConfig
.getAbsolutePath());
119 Instance
.getCache().setOffline(offline
);
121 TestLauncher tests
= new Test(args
);
122 tests
.setDetails(verbose
);
124 result
= tests
.launch();
126 IOUtils
.deltree(tmpConfig
);
131 // This is usually done in Fanfix.Main:
132 Instance
.getTempFiles().close();