Skip to content

Commit 42837f5

Browse files
committed
Add some additional tests to cover custom control files.
1 parent 86d2619 commit 42837f5

File tree

7 files changed

+55
-2
lines changed

7 files changed

+55
-2
lines changed

src/test/java/org/vafer/jdeb/DebMakerTestCase.java

+46-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void visit(TarArchiveEntry entry, byte[] content) throws IOException {
121121
}
122122

123123
@Test
124-
public void testCreationUtf8() throws Exception {
124+
public void testCreationEncoding() throws Exception {
125125
DataProducer[] data = prepareData();
126126
File deb = File.createTempFile("jdeb", ".deb");
127127

@@ -144,7 +144,7 @@ public void testCreationUtf8() throws Exception {
144144

145145
DebMaker maker = new DebMaker(new NullConsole(), Arrays.asList(data), Arrays.<DataProducer>asList(conffile1, conffile2));
146146

147-
maker.setControl(new File(getClass().getResource("deb/controlutf8").toURI()));
147+
maker.setControl(new File(getClass().getResource("deb/controlencoding").toURI()));
148148
maker.setDeb(deb);
149149

150150
// first step: invalid encoding
@@ -176,6 +176,28 @@ else if (entry.getName().equals("./postinst") || entry.getName().equals("./prerm
176176
throw new IOException(e);
177177
}
178178
}
179+
else if (entry.getName().startsWith("./shell_")) {
180+
try {
181+
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
182+
if(line.startsWith("# Custom script")) {
183+
assertFalse("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
184+
}
185+
}
186+
} catch(Exception e) {
187+
throw new IOException(e);
188+
}
189+
}
190+
else if (entry.getName().equals("./text.txt")) {
191+
try {
192+
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
193+
if(line.startsWith("Text file")) {
194+
assertFalse("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
195+
}
196+
}
197+
} catch(Exception e) {
198+
throw new IOException(e);
199+
}
200+
}
179201
}
180202
});
181203

@@ -208,6 +230,28 @@ else if (entry.getName().equals("./postinst") || entry.getName().equals("./prerm
208230
throw new IOException(e);
209231
}
210232
}
233+
else if (entry.getName().startsWith("./shell_")) {
234+
try {
235+
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
236+
if(line.startsWith("# Custom script")) {
237+
assertTrue("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
238+
}
239+
}
240+
} catch(Exception e) {
241+
throw new IOException(e);
242+
}
243+
}
244+
else if (entry.getName().equals("./text.txt")) {
245+
try {
246+
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) {
247+
if(line.startsWith("Text file")) {
248+
assertTrue("the encoding is valid but should be wrong", line.endsWith("created by ジョン"));
249+
}
250+
}
251+
} catch(Exception e) {
252+
throw new IOException(e);
253+
}
254+
}
211255
}
212256
});
213257
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
#
3+
# Custom script created by ジョン
4+
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
#
3+
# Custom script created by ジョン
4+
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Text file created by ジョン

0 commit comments

Comments
 (0)