Continue with suppressions unsafe_buffers in (barcode) test files.

Bug: 42271175
Change-Id: I65dddc43b5ed78e8a1042f15fda38a5a408df68a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120250
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
index f77b7f1..57d4830 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
 
 #include <string.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -24,9 +20,9 @@
       "#  #  # ##";  // B End
   DataVector<uint8_t> encoded = writer.Encode("");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
   static const char kExpected2[] =
       "# ##  #  # "  // A Start
       "# # ##  # "   // 1
@@ -35,9 +31,9 @@
       "#  #  # ##";  // B End
   encoded = writer.Encode("123");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
   static const char kExpected3[] =
       "# ##  #  # "  // A Start
       "# #  ## # "   // -
@@ -49,9 +45,9 @@
       "#  #  # ##";  // B End
   encoded = writer.Encode("-$./:+");
   ASSERT_EQ(strlen(kExpected3), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected3); i++)
-    EXPECT_EQ(kExpected3[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected3); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected3[i] != ' ', !!encoded[i])) << i;
+  }
   static const char kExpected4[] =
       "# ##  #  # "  // A Start
       "# ## #  # "   // 4
@@ -74,8 +70,9 @@
       "#  #  # ##";  // B End
   encoded = writer.Encode("456.987987987/001");
   ASSERT_EQ(strlen(kExpected4), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected4); i++)
-    EXPECT_EQ(kExpected4[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected4); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected4[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 TEST(OnedCodaBarWriterTest, SetDelimiters) {
@@ -118,8 +115,9 @@
       "# #  #  ##";  // * (same as C) End
   DataVector<uint8_t> encoded = writer.Encode("987");
   ASSERT_EQ(strlen(kExpected), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected); i++)
-    EXPECT_EQ(kExpected[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 }  // namespace
diff --git a/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp b/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
index 4e3edc1..7212e8e 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp
@@ -2,20 +2,24 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedCode128Writer.h"
 
 #include <iterator>
 
+#include "core/fxcrt/compiler_specific.h"
+#include "core/fxcrt/span.h"
+#include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+using ::testing::ElementsAreArray;
+
 namespace {
 
 struct TestCase {
+  pdfium::span<const int32_t> pattern_span() const {
+    return UNSAFE_TODO(pdfium::make_span(patterns, num_patterns));
+  }
+
   const char* input;
   int32_t checksum;
   int32_t patterns[7];
@@ -23,7 +27,6 @@
 };
 
 TEST(OnedCode128WriterTest, Encode128B) {
-  char buf[100];
   static const TestCase kTestCases[] = {
       {"", 104, {104}, 1},
       {"a", 169, {104, 65}, 2},
@@ -38,25 +41,16 @@
       {"321ABC", 722, {104, 19, 18, 17, 33, 34, 35}, 7},
       {"XYZ", 448, {104, 56, 57, 58}, 4},
   };
-  for (size_t i = 0; i < std::size(kTestCases); ++i) {
-    FXSYS_snprintf(buf, sizeof(buf) - 1, "Test case %zu", i);
-    SCOPED_TRACE(buf);
-    const TestCase& test_case = kTestCases[i];
+  for (const auto& test_case : kTestCases) {
     std::vector<int32_t> patterns;
     int32_t checksum =
         CBC_OnedCode128Writer::Encode128B(test_case.input, &patterns);
     EXPECT_EQ(test_case.checksum, checksum);
-    ASSERT_EQ(test_case.num_patterns, patterns.size());
-    for (size_t j = 0; j < patterns.size(); ++j) {
-      FXSYS_snprintf(buf, sizeof(buf) - 1, "Comparison %zu", j);
-      SCOPED_TRACE(buf);
-      EXPECT_EQ(test_case.patterns[j], patterns[j]);
-    }
+    EXPECT_THAT(patterns, ElementsAreArray(test_case.pattern_span()));
   }
 }
 
 TEST(OnedCode128WriterTest, Encode128C) {
-  char buf[100];
   static const TestCase kTestCases[] = {
       {"", 105, {105}, 1},
       {"a", 202, {105, 97}, 2},
@@ -71,20 +65,12 @@
       {"321ABC", 933, {105, 32, 1, 65, 66, 67}, 6},
       {"XYZ", 641, {105, 88, 89, 90}, 4},
   };
-  for (size_t i = 0; i < std::size(kTestCases); ++i) {
-    FXSYS_snprintf(buf, sizeof(buf) - 1, "Test case %zu", i);
-    SCOPED_TRACE(buf);
-    const TestCase& test_case = kTestCases[i];
+  for (const auto& test_case : kTestCases) {
     std::vector<int32_t> patterns;
     int32_t checksum =
         CBC_OnedCode128Writer::Encode128C(test_case.input, &patterns);
     EXPECT_EQ(test_case.checksum, checksum);
-    ASSERT_EQ(test_case.num_patterns, patterns.size());
-    for (size_t j = 0; j < patterns.size(); ++j) {
-      FXSYS_snprintf(buf, sizeof(buf) - 1, "Comparison %zu", j);
-      SCOPED_TRACE(buf);
-      EXPECT_EQ(test_case.patterns[j], patterns[j]);
-    }
+    EXPECT_THAT(patterns, ElementsAreArray(test_case.pattern_span()));
   }
 }
 
diff --git a/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp b/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
index 7689525..3c0aa80 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedCode39Writer.h"
 
 #include <string.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -43,9 +39,9 @@
       "#   # ### ### #";  // * End
   DataVector<uint8_t> encoded = writer.Encode("PDFIUM");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
   writer.SetWideNarrowRatio(2);
 
   static const char kExpected2[] =
@@ -59,8 +55,9 @@
       "#  # ## ## #";  // * End
   encoded = writer.Encode("PDFIUM");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 TEST(OnedCode39WriterTest, Encode) {
@@ -71,8 +68,9 @@
       "#   # ### ### #";  // * End
   DataVector<uint8_t> encoded = writer.Encode("");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
 
   static const char kExpected2[] =
       "#   # ### ### # "  // * Start
@@ -82,8 +80,9 @@
       "#   # ### ### #";  // * End
   encoded = writer.Encode("123");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
 
   static const char kExpected3[] =
       "#   # ### ### # "  // * Start
@@ -96,8 +95,9 @@
       "#   # ### ### #";  // * End
   encoded = writer.Encode("PDFIUM");
   ASSERT_EQ(strlen(kExpected3), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected3); i++)
-    EXPECT_EQ(kExpected3[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected3); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected3[i] != ' ', !!encoded[i])) << i;
+  }
 
   static const char kExpected4[] =
       "#   # ### ### # "  // * Start
@@ -113,8 +113,9 @@
       "#   # ### ### #";  // * End
   encoded = writer.Encode("A -$%./+Z");
   ASSERT_EQ(strlen(kExpected4), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected4); i++)
-    EXPECT_EQ(kExpected4[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected4); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected4[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 TEST(OnedCode39WriterTest, Checksum) {
@@ -131,7 +132,7 @@
   DataVector<uint8_t> encoded = writer.Encode("123");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
   for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
 
   static const char kExpected2[] =
       "#   # ### ### # "  // * Start
@@ -145,8 +146,9 @@
       "#   # ### ### #";  // * End
   encoded = writer.Encode("PDFIUM");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 }  // namespace
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp b/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
index 4d8b463..6671fe2 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedEAN13Writer.h"
 
 #include <string.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -45,9 +41,9 @@
       "#  #   "  // 8 R
       "# #";     // End
   DataVector<uint8_t> encoded = writer.Encode("1234567890128");
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
   static const char kExpected2[] =
       "# #"  // Start
       // 7 implicit by LGLGLG in next 6 digits
@@ -67,8 +63,9 @@
       "# #";     // End
   encoded = writer.Encode("7776665554440");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 TEST(OnedEAN13WriterTest, Checksum) {
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp b/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
index 79f5c33..12fa994 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedEAN8Writer.h"
 
 #include <string.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -41,9 +37,9 @@
       "# #";     // End
   DataVector<uint8_t> encoded = writer.Encode("12345670");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
-
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
   static const char kExpected2[] =
       "# #"      // Start
       "   # ##"  // 9 L
@@ -59,7 +55,7 @@
   encoded = writer.Encode("99441104");
   ASSERT_EQ(strlen(kExpected2), encoded.size());
   for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
 }
 
 TEST(OnedEAN8WriterTest, Checksum) {
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp b/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
index 56b52d9..e818d7c 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/oned/BC_OnedUPCAWriter.h"
 
 #include <string.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -45,8 +41,9 @@
       "# #";     // End
   DataVector<uint8_t> encoded = writer.Encode("123456789012");
   ASSERT_EQ(strlen(kExpected1), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected1); i++)
-    EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected1); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
+  }
 
   encoded = writer.Encode("777666555440");
   static const char kExpected2[] =
@@ -66,8 +63,9 @@
       "###  # "  // 0 R
       "# #";     // End
   ASSERT_EQ(strlen(kExpected2), encoded.size());
-  for (size_t i = 0; i < strlen(kExpected2); i++)
-    EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
+  for (size_t i = 0; i < strlen(kExpected2); i++) {
+    UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
+  }
 }
 
 TEST(OnedUPCAWriterTest, Checksum) {
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
index 256b169..e35bac9 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp
@@ -2,11 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h"
 
 #include <vector>
@@ -44,8 +39,8 @@
       {L"0000000000000", L"\x0386\x000f\x00d9\x017b\x000b\x0064", 6},
   };
 
-  for (size_t i = 0; i < std::size(kEncodeHighLevelCases); ++i) {
-    const EncodeHighLevelCase& testcase = kEncodeHighLevelCases[i];
+  size_t i = 0;
+  for (const EncodeHighLevelCase& testcase : kEncodeHighLevelCases) {
     WideStringView input(testcase.input);
     auto expected = UNSAFE_TODO(
         WideString::Create(testcase.expected, testcase.expected_length));
@@ -53,6 +48,7 @@
         CBC_PDF417HighLevelEncoder::EncodeHighLevel(input);
     ASSERT_TRUE(result.has_value());
     EXPECT_EQ(expected, result.value()) << " for case number " << i;
+    ++i;
   }
 }
 
@@ -89,21 +85,16 @@
        L"\u039c\u00c9\u031f\u012a\u00d2\u02d0", 6},
   };
 
-  for (size_t i = 0; i < std::size(kEncodeBinaryCases); ++i) {
-    const EncodeBinaryCase& testcase = kEncodeBinaryCases[i];
-    std::vector<uint8_t> input_array;
-    size_t input_length = strlen(testcase.input);
-    input_array.resize(input_length);
-    for (size_t j = 0; j < input_length; ++j) {
-      input_array[j] = testcase.input[j];
-    }
+  size_t i = 0;
+  for (const EncodeBinaryCase& testcase : kEncodeBinaryCases) {
+    WideString result;
+    CBC_PDF417HighLevelEncoder::EncodeBinary(
+        ByteStringView(testcase.input).unsigned_span(), testcase.offset,
+        testcase.count, testcase.startmode, &result);
     auto expected = UNSAFE_TODO(
         WideString::Create(testcase.expected, testcase.expected_length));
-    WideString result;
-    CBC_PDF417HighLevelEncoder::EncodeBinary(input_array, testcase.offset,
-                                             testcase.count, testcase.startmode,
-                                             &result);
     EXPECT_EQ(expected, result) << " for case number " << i;
+    ++i;
   }
 }
 
@@ -157,8 +148,8 @@
        18},
   };
 
-  for (size_t i = 0; i < std::size(kEncodeNumericCases); ++i) {
-    const EncodeNumericCase& testcase = kEncodeNumericCases[i];
+  size_t i = 0;
+  for (const EncodeNumericCase& testcase : kEncodeNumericCases) {
     WideString input(testcase.input);
     auto expected = UNSAFE_TODO(
         WideString::Create(testcase.expected, testcase.expected_length));
@@ -166,6 +157,7 @@
     CBC_PDF417HighLevelEncoder::EncodeNumeric(input, testcase.offset,
                                               testcase.count, &result);
     EXPECT_EQ(expected, result) << " for case number " << i;
+    ++i;
   }
 }
 
@@ -202,15 +194,15 @@
       // Test substring starting in digits field following non-digit field.
       {L"123FOO45678", 6, 5},
   };
-
-  for (size_t i = 0; i < std::size(kConsecutiveDigitCases); ++i) {
-    const ConsecutiveDigitCase& testcase = kConsecutiveDigitCases[i];
+  size_t i = 0;
+  for (const ConsecutiveDigitCase& testcase : kConsecutiveDigitCases) {
     WideString input(testcase.input);
     int actual_count =
         CBC_PDF417HighLevelEncoder::DetermineConsecutiveDigitCount(
             input, testcase.offset);
     EXPECT_EQ(testcase.expected_count, actual_count)
         << " for case number " << i;
+    ++i;
   }
 }
 
@@ -263,14 +255,15 @@
       {L"XXX121XXX12345678901234", 0, 9},
   };
 
-  for (size_t i = 0; i < std::size(kConsecutiveTextCases); ++i) {
-    const ConsecutiveTextCase& testcase = kConsecutiveTextCases[i];
+  size_t i = 0;
+  for (const ConsecutiveTextCase& testcase : kConsecutiveTextCases) {
     WideString input(testcase.input);
     int actual_count =
         CBC_PDF417HighLevelEncoder::DetermineConsecutiveTextCount(
             input, testcase.offset);
     EXPECT_EQ(testcase.expected_count, actual_count)
         << " for case number " << i;
+    ++i;
   }
 }