Bug 1284031 (Part 2) - Add new StreamingLexer tests for zero-length states. r=njn
authorSeth Fowler <mark.seth.fowler@gmail.com>
Thu, 14 Jul 2016 20:00:21 -0700
changeset 330264 0284587d752d35d2ddf6f2d9983047597ff1e38e
parent 330263 656d5e742049c4ad966389fa2db3b11bf956c7cf
child 330265 b1e09b3b77dd0253abb363c2146323393c9c0592
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1284031
milestone50.0a1
Bug 1284031 (Part 2) - Add new StreamingLexer tests for zero-length states. r=njn
image/test/gtest/TestStreamingLexer.cpp
--- a/image/test/gtest/TestStreamingLexer.cpp
+++ b/image/test/gtest/TestStreamingLexer.cpp
@@ -269,16 +269,50 @@ TEST_F(ImageStreamingLexer, OneByteChunk
       EXPECT_TRUE(result.isNothing());
     }
   }
 
   EXPECT_EQ(8u, mCountResumes->Count());
   mSourceBuffer->Complete(NS_OK);
 }
 
+TEST_F(ImageStreamingLexer, ZeroLengthState)
+{
+  mSourceBuffer->Append(mData, sizeof(mData));
+  mSourceBuffer->Complete(NS_OK);
+
+  // Create a special StreamingLexer for this test because we want the first
+  // state to be zero length.
+  StreamingLexer<TestState> lexer(Transition::To(TestState::ONE, 0));
+
+  Maybe<TerminalState> result =
+    lexer.Lex(mIterator, mExpectNoResume, DoLexWithZeroLengthStates);
+
+  EXPECT_TRUE(result.isSome());
+  EXPECT_EQ(Some(TerminalState::SUCCESS), result);
+}
+
+TEST_F(ImageStreamingLexer, ZeroLengthStateWithUnbuffered)
+{
+  mSourceBuffer->Append(mData, sizeof(mData));
+  mSourceBuffer->Complete(NS_OK);
+
+  // Create a special StreamingLexer for this test because we want the first
+  // state to be both zero length and unbuffered.
+  StreamingLexer<TestState> lexer(Transition::ToUnbuffered(TestState::ONE,
+                                                           TestState::UNBUFFERED,
+                                                           0));
+
+  Maybe<TerminalState> result =
+    lexer.Lex(mIterator, mExpectNoResume, DoLexWithZeroLengthStatesUnbuffered);
+
+  EXPECT_TRUE(result.isSome());
+  EXPECT_EQ(Some(TerminalState::SUCCESS), result);
+}
+
 TEST_F(ImageStreamingLexer, TerminateSuccessFromSourceBuffer)
 {
   mSourceBuffer->Append(mData, sizeof(mData));
   mSourceBuffer->Complete(NS_OK);
 
   // Test that Terminate is "sticky".
   SourceBufferIterator iterator = mSourceBuffer->Iterator();
   Maybe<TerminalState> result =