| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/include/fxcrt/fx_basic.h" | |
| 6 #include "include/BC_PDF417HighLevelEncoder.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #include "testing/fx_string_testhelpers.h" | |
| 9 | |
| 10 TEST(PDF417HighLevelEncoder, EncodeHighLevel) { | |
| 11 // TODO(tsepez): implement test cases. | |
| 12 } | |
| 13 | |
| 14 TEST(PDF417HighLevelEncoder, EncodeText) { | |
| 15 // TODO(tsepez): implement test cases. | |
| 16 } | |
| 17 | |
| 18 TEST(PDF417HighLevelEncoder, EncodeBinary) { | |
| 19 struct EncodeBinaryCase { | |
| 20 const char* input; | |
| 21 int offset; | |
| 22 int count; | |
| 23 int startmode; | |
| 24 const wchar_t* expected; | |
| 25 int expected_length; | |
| 26 } encode_binary_cases[] = { | |
| 27 // Empty string encodes as empty string. | |
| 28 { "", 0, 0, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, L"", 0 }, | |
| 29 | |
| 30 // Fewer than 6 characters encodes as prefix without compaction. | |
| 31 { "xxxxx", 0, 5, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, L"\x0385xxxxx"
, 6 }, | |
| 32 | |
| 33 // 6 charcters triggerst text encoding compaction. | |
| 34 { "xxxxxx", 0, 6, CBC_PDF417HighLevelEncoder::TEXT_COMPACTION, | |
| 35 L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6 }, | |
| 36 | |
| 37 // Same result if initially in numeric compaction mode. | |
| 38 { "xxxxxx", 0, 6, CBC_PDF417HighLevelEncoder::NUMERIC_COMPACTION, | |
| 39 L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6 }, | |
| 40 }; | |
| 41 | |
| 42 CBC_PDF417HighLevelEncoder::Initialize(); | |
| 43 for (size_t i = 0; i < FX_ArraySize(encode_binary_cases); ++i) { | |
| 44 EncodeBinaryCase* ptr = &encode_binary_cases[i]; | |
| 45 CFX_ByteArray input_array; | |
| 46 size_t input_length = strlen(ptr->input); | |
| 47 input_array.SetSize(input_length); | |
| 48 for (size_t j = 0; j < input_length; ++j) { | |
| 49 input_array.SetAt(j, ptr->input[j]); | |
| 50 } | |
| 51 CFX_WideString expected(ptr->expected, ptr->expected_length); | |
| 52 CFX_WideString result; | |
| 53 CBC_PDF417HighLevelEncoder::encodeBinary( | |
| 54 &input_array, ptr->offset, ptr->count, ptr->startmode, result); | |
| 55 EXPECT_EQ(expected, result) << " for case number " << i; | |
| 56 } | |
| 57 CBC_PDF417HighLevelEncoder::Finalize(); | |
| 58 } | |
| 59 | |
| 60 TEST(PDF417HighLevelEncoder, EncodeNumeric) { | |
| 61 struct EncodeNumericCase { | |
| 62 const wchar_t* input; | |
| 63 int offset; | |
| 64 int count; | |
| 65 const wchar_t* expected; | |
| 66 int expected_length; | |
| 67 } encode_numeric_cases[] = { | |
| 68 // Empty string encodes as empty string. | |
| 69 { L"", 0, 0, L"", 0 }, | |
| 70 | |
| 71 // Blank string encodes as empty string. | |
| 72 { L" ", 0, 1, L"", 0 }, | |
| 73 | |
| 74 // Single 0 should encode as 10 base-900 == 10. | |
| 75 { L"0", 0, 1, L"", 0 }, // wrong - should be \u000a? | |
| 76 | |
| 77 // 800 should encode as 1800 base-900 == 2,0. | |
| 78 { L"800", 0, 3, L"\x0002\x0000", 2 }, | |
| 79 | |
| 80 // Test longer strings and sub-strings. | |
| 81 { L"123456", 0, 6, L"\x0001\x015c\x0100", 3 }, | |
| 82 { L"123456", 0, 5, L"\x007c\x02e9", 2 }, | |
| 83 { L"123456", 1, 5, L"\x0089\x009c", 2 }, | |
| 84 { L"123456", 2, 2, L"\x0086", 1 }, | |
| 85 | |
| 86 // Up to 44 characters encodes as 15 base-900 words. | |
| 87 { L"00000000000000000000000000000000000000000000", 0, 44, | |
| 88 L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6\x0090
\x020b\x019b\x0064", 15 }, | |
| 89 | |
| 90 // 45 characters should encode as same 15 words followed by one additional w
ord. | |
| 91 { L"000000000000000000000000000000000000000000000", 0, 45, | |
| 92 L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6\x0090
\x020b\x019b\x0064\x000a", 16 }, | |
| 93 | |
| 94 // 44 characters followed by 800 should encode as 15 words followed by 1800
base-900 == 2,0. | |
| 95 { L"00000000000000000000000000000000000000000000800", 0, 47, | |
| 96 L"\x01b5\x006f\x02cc\x0084\x01bc\x0076\x00b3\x005c\x01f0\x034f\x01e6\x0090
\x020b\x019b\x0064\x0002\x0000", 17 }, | |
| 97 | |
| 98 // Even longer input. | |
| 99 { L"10000000000000000000000000000000000000000000000000", 0, 50, | |
| 100 L"\x01e0\x02f0\x036d\x02ad\x029c\x01ea\x0011\x000b\x02d6\x023c\x0108\x02bb
\x0023\x02d2\x00c8\x0001\x00d3\x0064", 18 }, | |
| 101 }; | |
| 102 | |
| 103 CBC_PDF417HighLevelEncoder::Initialize(); | |
| 104 for (size_t i = 0; i < FX_ArraySize(encode_numeric_cases); ++i) { | |
| 105 EncodeNumericCase* ptr = &encode_numeric_cases[i]; | |
| 106 CFX_WideString input(ptr->input); | |
| 107 CFX_WideString expected(ptr->expected, ptr->expected_length); | |
| 108 CFX_WideString result; | |
| 109 CBC_PDF417HighLevelEncoder::encodeNumeric( | |
| 110 input, ptr->offset, ptr->count, result); | |
| 111 EXPECT_EQ(expected, result) << " for case number " << i; | |
| 112 } | |
| 113 CBC_PDF417HighLevelEncoder::Finalize(); | |
| 114 } | |
| 115 | |
| 116 TEST(PDF417HighLevelEncoder, ConsecutiveDigitCount) { | |
| 117 struct ConsecutiveDigitCase { | |
| 118 const wchar_t* input; | |
| 119 int offset; | |
| 120 int expected_count; | |
| 121 } consecutive_digit_cases[] = { | |
| 122 // Empty string contains 0 consecuitve digits. | |
| 123 { L"", 0, 0 }, | |
| 124 | |
| 125 // Single non-digit character contains 0 consecutive digits. | |
| 126 { L"X", 0, 0 }, | |
| 127 | |
| 128 // Leading non-digit followed by digits contains 0 consecutive. | |
| 129 { L"X123", 0, 0 }, | |
| 130 | |
| 131 // Single digit contains 1 consecutive digit. | |
| 132 { L"1", 0, 1 }, | |
| 133 | |
| 134 // Single digit followe by non-digit contains 1 consecutive digit. | |
| 135 { L"1Z", 0, 1 }, | |
| 136 | |
| 137 // Test longer strings. | |
| 138 { L"123FOO45678", 0, 3 }, | |
| 139 | |
| 140 // Test subtring starting in digits field. | |
| 141 { L"123FOO45678", 3, 0 }, | |
| 142 | |
| 143 // Test subtring starting in non-digits field. | |
| 144 { L"123FOO45678", 3, 0 }, | |
| 145 | |
| 146 // Test substring starting in digits field following non-digit field. | |
| 147 { L"123FOO45678", 6, 5 }, | |
| 148 }; | |
| 149 | |
| 150 CBC_PDF417HighLevelEncoder::Initialize(); | |
| 151 for (size_t i = 0; i < FX_ArraySize(consecutive_digit_cases); ++i) { | |
| 152 ConsecutiveDigitCase* ptr = &consecutive_digit_cases[i]; | |
| 153 CFX_WideString input(ptr->input); | |
| 154 int actual_count = CBC_PDF417HighLevelEncoder::determineConsecutiveDigitCoun
t(input, ptr->offset); | |
| 155 EXPECT_EQ(ptr->expected_count, actual_count) << " for case number " << i; | |
| 156 } | |
| 157 CBC_PDF417HighLevelEncoder::Finalize(); | |
| 158 } | |
| 159 | |
| 160 TEST(PDF417HighLevelEncoder, ConsecutiveTextCount) { | |
| 161 struct ConsecutiveTextCase { | |
| 162 const wchar_t* input; | |
| 163 int offset; | |
| 164 int expected_count; | |
| 165 } consecutive_text_cases[] = { | |
| 166 // Empty string contains 0 consecutive text characters. | |
| 167 { L"", 0, 0 }, | |
| 168 | |
| 169 // Single text character is 1 consecutive text characters. | |
| 170 { L"X", 0, 1 }, | |
| 171 | |
| 172 // Trailing numbers count as text characters. | |
| 173 { L"X123", 0, 4 }, | |
| 174 | |
| 175 // Leading numbers count as text characters. | |
| 176 { L"123X", 0, 4 }, | |
| 177 | |
| 178 // Embedded lo-value binary characters terminate text runs. | |
| 179 { L"ABC\x0001XXXX", 0, 3 }, | |
| 180 | |
| 181 // Embedded hi-value binary characters terminate text runs. | |
| 182 { L"ABC\x0100XXXX", 0, 3 }, | |
| 183 | |
| 184 // Text run still found after indexing past lo-value character. | |
| 185 { L"ABC\x0001XXXX", 4, 4 }, | |
| 186 | |
| 187 // Text run still found after indexing past hi-value character. | |
| 188 { L"ABC\x0100XXXX", 4, 4 }, | |
| 189 | |
| 190 // Leading hi-value character results in 0 consecutive characters. | |
| 191 { L"\x0100XXX", 0, 0 }, | |
| 192 | |
| 193 // Up to 12 numbers count as text. | |
| 194 { L"123456789012", 0, 12 }, | |
| 195 | |
| 196 // 13 or more numbers are compresssed using numeric compression, not text. | |
| 197 { L"1234567890123", 0, 0 }, | |
| 198 | |
| 199 // Leading Text character doesn't affect the 12 character case. | |
| 200 { L"X123456789012", 0, 13 }, | |
| 201 | |
| 202 // Leading Text character doesn't affect the 13 character case. | |
| 203 { L"X1234567890123", 0, 1 }, | |
| 204 | |
| 205 // Jumping between numbers and letters works properly. | |
| 206 { L"XXX121XXX12345678901234", 0, 9 }, | |
| 207 }; | |
| 208 | |
| 209 CBC_PDF417HighLevelEncoder::Initialize(); | |
| 210 for (size_t i = 0; i < FX_ArraySize(consecutive_text_cases); ++i) { | |
| 211 ConsecutiveTextCase* ptr = &consecutive_text_cases[i]; | |
| 212 CFX_WideString input(ptr->input); | |
| 213 int actual_count = CBC_PDF417HighLevelEncoder::determineConsecutiveTextCount
(input, ptr->offset); | |
| 214 EXPECT_EQ(ptr->expected_count, actual_count) << " for case number " << i; | |
| 215 } | |
| 216 CBC_PDF417HighLevelEncoder::Finalize(); | |
| 217 } | |
| 218 | |
| 219 TEST(PDF417HighLevelEncoder, ConsecutiveBinaryCount) { | |
| 220 | |
| 221 } | |
| OLD | NEW |