614cec14ea2609f45bc9af7c2b09e6a48f7445a3
[fanfix.git] / src / be / nikiroo / fanfix / test / Test.java
1 package be.nikiroo.fanfix.test;
2
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.util.Properties;
7
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;
14
15 /**
16 * Tests for Fanfix.
17 *
18 * @author niki
19 */
20 public class Test extends TestLauncher {
21 /**
22 * The temporary files handler.
23 */
24 static TempFiles tempFiles;
25
26 /**
27 * Create the Fanfix {@link TestLauncher}.
28 *
29 * @param args
30 * the arguments to configure the number of columns and the ok/ko
31 * {@link String}s
32 */
33 public Test(String[] args) {
34 super("Fanfix", args);
35 Instance.setTraceHandler(null);
36 addSeries(new BasicSupportTest(args));
37 addSeries(new LibraryTest(args));
38 addSeries(new ConversionTest(args));
39 }
40
41 /**
42 * Main entry point of the program.
43 *
44 * @param args
45 * the arguments passed to the {@link TestLauncher}s.
46 * @throws IOException
47 * in case of I/O error
48 */
49 static public void main(String[] args) throws IOException {
50 int result = 0;
51 tempFiles = new TempFiles("fanfix-test");
52 try {
53 File tmpConfig = tempFiles.createTempDir("fanfix-config");
54 File tmpCache = tempFiles.createTempDir("fanfix-cache");
55
56 FileOutputStream out = null;
57 try {
58 out = new FileOutputStream(new File(tmpConfig,
59 "config.properties"));
60 Properties props = new Properties();
61 props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
62 props.store(out, null);
63 } finally {
64 if (out != null) {
65 out.close();
66 }
67 }
68
69 ConfigBundle config = new ConfigBundle();
70 Bundles.setDirectory(tmpConfig.getAbsolutePath());
71 config.updateFile(tmpConfig.getPath());
72
73 System.setProperty("CONFIG_DIR", tmpConfig.getAbsolutePath());
74
75 result = new Test(args).launch();
76
77 IOUtils.deltree(tmpConfig);
78 IOUtils.deltree(tmpCache);
79 } finally {
80 // Test temp files
81 tempFiles.close();
82
83 // This is usually done in Fanfix.Main:
84 Instance.getTempFiles().close();
85 }
86
87 System.exit(result);
88 }
89 }