A few more tests and fix handling of data: URIs in command line decoder

This commit is contained in:
Sean Owen 2018-07-24 17:59:52 -05:00
parent 9065c4daee
commit a0a4d8ff80
4 changed files with 90 additions and 3 deletions

View file

@ -93,8 +93,13 @@ final class DecodeWorker implements Callable<Integer> {
inputFileName = inputPath.getFileName().toString();
} else {
outDir = Paths.get(".").toRealPath();
String[] pathElements = input.getPath().split("/");
inputFileName = pathElements[pathElements.length - 1];
String path = input.getPath();
if (path == null) {
inputFileName = "input";
} else {
String[] pathElements = path.split("/");
inputFileName = pathElements[pathElements.length - 1];
}
}
// Replace/add extension

View file

@ -0,0 +1,51 @@
/*
* Copyright 2018 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.j2se;
import org.junit.Assert;
import org.junit.Test;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
public final class CommandLineEncoderTestCase extends Assert {
@Test
public void testEncode() throws Exception {
File out = File.createTempFile("qrcode", ".png");
out.deleteOnExit();
String[] args = {
"--barcode_format", "QR_CODE",
"--image_format", "PNG",
"--output", out.toString(),
"--width", "1", "--height", "1",
"--error-correction-level", "L",
"HELLO" };
CommandLineEncoder.main(args);
Path outPath = out.toPath();
assertTrue(Files.exists(outPath));
assertTrue(Files.size(outPath) > 0);
BufferedImage image = ImageIO.read(out);
assertEquals(33, image.getHeight());
assertEquals(33, image.getWidth());
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright 2018 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.client.j2se;
import org.junit.Assert;
import org.junit.Test;
public final class CommandLineRunnerTestCase extends Assert {
@Test
public void testCommandLineRunner() throws Exception {
String[] args = { "--pure_barcode", DecodeWorkerTestCase.IMAGE_DATA_URI };
// Not a lot to do here but make sure it runs
CommandLineRunner.main(args);
}
}

View file

@ -30,7 +30,7 @@ import java.util.Queue;
*/
public final class DecodeWorkerTestCase extends Assert {
private static final String IMAGE_DATA_URI =
static final String IMAGE_DATA_URI =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAhAQAAAAB/n//CAAAAkklEQVR42mP4DwQNDJjkB4" +
"E77A0M369N/d7A8CV6rjiQjPMFkWG1QPL7RVGg%2BAfREKCa/5/vA9V/nFSQ3sDwb7/KdiDJqX4dSH4pXN/A8DfyDVD2" +
"988HQPUfPVaqA0XKz%2BgD9bIk1AP1fgwvB7KlS9VBdqXbA82PT9AH2fiaH2SXGdDM71fDgeIfhIvKsbkTTAIAKYVr0N" +