mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
A few more tests and fix handling of data: URIs in command line decoder
This commit is contained in:
parent
9065c4daee
commit
a0a4d8ff80
|
@ -93,9 +93,14 @@ final class DecodeWorker implements Callable<Integer> {
|
||||||
inputFileName = inputPath.getFileName().toString();
|
inputFileName = inputPath.getFileName().toString();
|
||||||
} else {
|
} else {
|
||||||
outDir = Paths.get(".").toRealPath();
|
outDir = Paths.get(".").toRealPath();
|
||||||
String[] pathElements = input.getPath().split("/");
|
String path = input.getPath();
|
||||||
|
if (path == null) {
|
||||||
|
inputFileName = "input";
|
||||||
|
} else {
|
||||||
|
String[] pathElements = path.split("/");
|
||||||
inputFileName = pathElements[pathElements.length - 1];
|
inputFileName = pathElements[pathElements.length - 1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Replace/add extension
|
// Replace/add extension
|
||||||
int pos = inputFileName.lastIndexOf('.');
|
int pos = inputFileName.lastIndexOf('.');
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ import java.util.Queue;
|
||||||
*/
|
*/
|
||||||
public final class DecodeWorkerTestCase extends Assert {
|
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" +
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAhAQAAAAB/n//CAAAAkklEQVR42mP4DwQNDJjkB4" +
|
||||||
"E77A0M369N/d7A8CV6rjiQjPMFkWG1QPL7RVGg%2BAfREKCa/5/vA9V/nFSQ3sDwb7/KdiDJqX4dSH4pXN/A8DfyDVD2" +
|
"E77A0M369N/d7A8CV6rjiQjPMFkWG1QPL7RVGg%2BAfREKCa/5/vA9V/nFSQ3sDwb7/KdiDJqX4dSH4pXN/A8DfyDVD2" +
|
||||||
"988HQPUfPVaqA0XKz%2BgD9bIk1AP1fgwvB7KlS9VBdqXbA82PT9AH2fiaH2SXGdDM71fDgeIfhIvKsbkTTAIAKYVr0N" +
|
"988HQPUfPVaqA0XKz%2BgD9bIk1AP1fgwvB7KlS9VBdqXbA82PT9AH2fiaH2SXGdDM71fDgeIfhIvKsbkTTAIAKYVr0N" +
|
||||||
|
|
Loading…
Reference in a new issue