mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
cargo fmt
This commit is contained in:
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2014 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.pdf417.encoder;
|
|
||||||
|
|
||||||
import com.google.zxing.WriterException;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link PDF417HighLevelEncoder}.
|
|
||||||
*/
|
|
||||||
public final class PDF417EncoderTestCase extends Assert {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeAuto() throws Exception {
|
|
||||||
String encoded = PDF417HighLevelEncoder.encodeHighLevel(
|
|
||||||
"ABCD", Compaction.AUTO, StandardCharsets.UTF_8, false);
|
|
||||||
assertEquals("\u039f\u001A\u0385ABCD", encoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeAutoWithSpecialChars() throws Exception {
|
|
||||||
// Just check if this does not throw an exception
|
|
||||||
PDF417HighLevelEncoder.encodeHighLevel(
|
|
||||||
"1%§s ?aG$", Compaction.AUTO, StandardCharsets.UTF_8, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeIso88591WithSpecialChars() throws Exception {
|
|
||||||
// Just check if this does not throw an exception
|
|
||||||
PDF417HighLevelEncoder.encodeHighLevel("asdfg§asd", Compaction.AUTO, StandardCharsets.ISO_8859_1, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeText() throws Exception {
|
|
||||||
String encoded = PDF417HighLevelEncoder.encodeHighLevel(
|
|
||||||
"ABCD", Compaction.TEXT, StandardCharsets.UTF_8, false);
|
|
||||||
assertEquals("Ο\u001A\u0001?", encoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeNumeric() throws Exception {
|
|
||||||
String encoded = PDF417HighLevelEncoder.encodeHighLevel(
|
|
||||||
"1234", Compaction.NUMERIC, StandardCharsets.UTF_8, false);
|
|
||||||
assertEquals("\u039f\u001A\u0386\f\u01b2", encoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncodeByte() throws Exception {
|
|
||||||
String encoded = PDF417HighLevelEncoder.encodeHighLevel(
|
|
||||||
"abcd", Compaction.BYTE, StandardCharsets.UTF_8, false);
|
|
||||||
assertEquals("\u039f\u001A\u0385abcd", encoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = WriterException.class)
|
|
||||||
public void testEncodeEmptyString() throws Exception {
|
|
||||||
PDF417HighLevelEncoder.encodeHighLevel("", Compaction.AUTO, null, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
/**
|
/**
|
||||||
* Represents possible PDF417 barcode compaction types.
|
* Represents possible PDF417 barcode compaction types.
|
||||||
*/
|
*/
|
||||||
#[derive(Clone, Copy,PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Compaction {
|
pub enum Compaction {
|
||||||
AUTO = 0,
|
AUTO = 0,
|
||||||
TEXT = 1,
|
TEXT = 1,
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ mod pdf_417;
|
|||||||
pub use pdf_417::*;
|
pub use pdf_417::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod pdf_417_high_level_encoder_test_adapter;
|
pub mod pdf_417_high_level_encoder_test_adapter;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -212,3 +212,75 @@ pub fn generateErrorCorrection(
|
|||||||
}
|
}
|
||||||
Ok(sb)
|
Ok(sb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests {@link PDF417HighLevelEncoder}.
|
||||||
|
*/
|
||||||
|
#[cfg(test)]
|
||||||
|
mod PDF417EncoderTestCase {
|
||||||
|
use crate::pdf417::encoder::{pdf_417_high_level_encoder::encodeHighLevel, Compaction};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeAuto() {
|
||||||
|
let encoded = encodeHighLevel("ABCD", Compaction::AUTO, Some(encoding::all::UTF_8), false)
|
||||||
|
.expect("encode");
|
||||||
|
assert_eq!("\u{039f}\u{001A}\u{0385}ABCD", encoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeAutoWithSpecialChars() {
|
||||||
|
// Just check if this does not throw an exception
|
||||||
|
encodeHighLevel(
|
||||||
|
"1%§s ?aG$",
|
||||||
|
Compaction::AUTO,
|
||||||
|
Some(encoding::all::UTF_8),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.expect("encode");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeIso88591WithSpecialChars() {
|
||||||
|
// Just check if this does not throw an exception
|
||||||
|
encodeHighLevel(
|
||||||
|
"asdfg§asd",
|
||||||
|
Compaction::AUTO,
|
||||||
|
Some(encoding::all::ISO_8859_1),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.expect("encode");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeText() {
|
||||||
|
let encoded = encodeHighLevel("ABCD", Compaction::TEXT, Some(encoding::all::UTF_8), false)
|
||||||
|
.expect("encode");
|
||||||
|
assert_eq!("Ο\u{001A}\u{0001}?", encoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeNumeric() {
|
||||||
|
let encoded = encodeHighLevel(
|
||||||
|
"1234",
|
||||||
|
Compaction::NUMERIC,
|
||||||
|
Some(encoding::all::UTF_8),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.expect("encode");
|
||||||
|
assert_eq!("\u{039f}\u{001A}\u{0386}\u{0046}\u{01b2}", encoded);
|
||||||
|
// converted \f to \u{0046}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn testEncodeByte() {
|
||||||
|
let encoded = encodeHighLevel("abcd", Compaction::BYTE, Some(encoding::all::UTF_8), false)
|
||||||
|
.expect("encode");
|
||||||
|
assert_eq!("\u{039f}\u{001A}\u{0385}abcd", encoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn testEncodeEmptyString() {
|
||||||
|
encodeHighLevel("", Compaction::AUTO, None, false).expect("encode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user