Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3164)

Unified Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp

Issue 1433503002: Add test for CPDF_SyntaxParser::ReadHexString. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1f1284517d6a985772ee8b12e500993f7e8d919f
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
@@ -0,0 +1,69 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "../../../include/fpdfapi/fpdf_parser.h"
+
+// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal.
+// Come up or wait for something better.
+using ScopedFileStream =
+ nonstd::unique_ptr<IFX_FileStream, ReleaseDeleter<IFX_FileStream>>;
+
+TEST(fpdf_parser_parser, ReadHexString) {
+ {
Tom Sepez 2015/11/03 17:41:08 first test is usually empty string. "", " ". Next
dsinclair 2015/11/03 18:29:49 Done.
+ // Regular conversion.
+ uint8_t data[] = "1A2b>abcd";
Tom Sepez 2015/11/03 17:41:08 nit: these are all const.
dsinclair 2015/11/03 18:29:49 FX_CreateMemoryStream does not take a const data p
Tom Sepez 2015/11/03 18:39:55 Ok, let's fix that too sometime.
+ ScopedFileStream stream(FX_CreateMemoryStream(data, 9, FALSE));
+
+ CPDF_SyntaxParser parser;
+ parser.InitParser(stream.get(), 0);
+ EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
+ EXPECT_EQ(5, parser.SavePos());
+ }
+
+ {
+ // Position out of bounds.
+ uint8_t data[] = "12ab>";
+ ScopedFileStream stream(FX_CreateMemoryStream(data, 5, FALSE));
+
+ CPDF_SyntaxParser parser;
+ parser.InitParser(stream.get(), 0);
+ parser.RestorePos(6);
Tom Sepez 2015/11/03 17:41:08 How about testing 5 and 6? data[5] is the nul, da
dsinclair 2015/11/03 18:29:49 Done.
+ EXPECT_EQ("", parser.ReadHexString());
+ }
+
+ {
+ // Missing ending >.
+ uint8_t data[] = "1A2b";
Tom Sepez 2015/11/03 17:41:08 How about also 12abz?
dsinclair 2015/11/03 18:29:49 Done, although the code just keeps reading until i
+ ScopedFileStream stream(FX_CreateMemoryStream(data, 4, FALSE));
+
+ CPDF_SyntaxParser parser;
+ parser.InitParser(stream.get(), 0);
+ EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
+ EXPECT_EQ(4, parser.SavePos());
+ }
+
+ {
+ // Uneven number of bytes.
+ uint8_t data[] = "1A2>asdf";
Tom Sepez 2015/11/03 17:41:08 also 1a2z as above
dsinclair 2015/11/03 18:29:49 Done.
+ ScopedFileStream stream(FX_CreateMemoryStream(data, 8, FALSE));
+
+ CPDF_SyntaxParser parser;
+ parser.InitParser(stream.get(), 0);
+ EXPECT_EQ("\x1a\x20", parser.ReadHexString());
+ EXPECT_EQ(4, parser.SavePos());
+ }
+
+ {
+ // Just ending character.
+ uint8_t data[] = ">";
+ ScopedFileStream stream(FX_CreateMemoryStream(data, 1, FALSE));
+
+ CPDF_SyntaxParser parser;
+ parser.InitParser(stream.get(), 0);
+ EXPECT_EQ("", parser.ReadHexString());
+ EXPECT_EQ(1, parser.SavePos());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698