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