1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks;
21
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25
26 import com.github.maven_nar.cpptasks.compiler.ProcessorConfiguration;
27
28
29
30
31
32
33 public class TestTargetHistoryTable extends TestXMLConsumer {
34 public static class MockProcessorConfiguration implements ProcessorConfiguration {
35 public MockProcessorConfiguration() {
36 }
37
38 @Override
39 public int bid(final String fileName) {
40 return 100;
41 }
42
43 @Override
44 public String getIdentifier() {
45 return "Mock Configuration";
46 }
47
48 @Override
49 public String[] getOutputFileNames(final String baseName, final VersionInfo versionInfo) {
50 return new String[] {
51 baseName
52 };
53 }
54
55 @Override
56 public ProcessorParam[] getParams() {
57 return new ProcessorParam[0];
58 }
59
60 @Override
61 public boolean getRebuild() {
62 return false;
63 }
64 }
65
66
67
68
69
70
71
72
73 public TestTargetHistoryTable(final String name) {
74 super(name);
75 }
76
77
78
79
80
81
82 public void testLoadOpenshore() throws IOException {
83 try {
84 copyResourceToTmpDir("openshore/history.xml", "history.xml");
85 final CCTask task = new CCTask();
86 final String tmpDir = System.getProperty("java.io.tmpdir");
87 final TargetHistoryTable history = new TargetHistoryTable(task, new File(tmpDir));
88 } finally {
89 deleteTmpFile("history.xml");
90 }
91 }
92
93
94
95
96
97
98 public void testLoadXerces() throws IOException {
99 try {
100 copyResourceToTmpDir("xerces-c/history.xml", "history.xml");
101 final CCTask task = new CCTask();
102 final String tmpDir = System.getProperty("java.io.tmpdir");
103 final TargetHistoryTable history = new TargetHistoryTable(task, new File(tmpDir));
104 } finally {
105 deleteTmpFile("history.xml");
106 }
107 }
108
109
110
111
112
113
114 public void testUpdateTimeResolution() throws IOException {
115 File compiledFile = null;
116
117 try {
118
119
120
121 final String tempDir = System.getProperty("java.io.tmpdir");
122 File historyFile = new File(tempDir, "history.xml");
123 historyFile.deleteOnExit();
124 if (historyFile.exists()) {
125 historyFile.delete();
126 }
127 final TargetHistoryTable table = new TargetHistoryTable(null, new File(tempDir));
128
129
130
131 compiledFile = new File(tempDir, "dummy.o");
132 final FileOutputStream compiledStream = new FileOutputStream(compiledFile);
133 compiledStream.close();
134
135
136
137
138
139 final long startTime = compiledFile.lastModified() + 1;
140
141
142
143 table.update(new MockProcessorConfiguration(), new String[] {
144 "dummy.o"
145 }, null);
146
147
148
149
150 table.commit();
151 historyFile = table.getHistoryFile();
152 assertTrue("History file was not created", historyFile.exists());
153 assertTrue("History file was empty", historyFile.length() > 10);
154 } finally {
155 if (compiledFile != null && compiledFile.exists()) {
156 compiledFile.delete();
157 }
158
159 }
160 }
161 }