// This helper class is used to call OnInputStreamReady with the right stream // as argument. class InputStreamCallback final : public nsIInputStreamCallback {
nsCOMPtr<nsIAsyncInputStream> mStream;
nsCOMPtr<nsIInputStreamCallback> mCallback;
/* We want to ensure that sliced streams work with both seekable and *non-seekableinputstreams.Asourstringstreamsareseekable,weneedto *provideastringstreamthatdoesn'tpermitseeking,sowecantestthe *logicthatemulatesseekinginslicedinputstreams.
*/ class NonSeekableStringStream final : public nsIAsyncInputStream {
nsCOMPtr<nsIInputStream> mStream;
NS_IMETHOD
CloseWithStatus(nsresult aStatus) override {
nsCOMPtr<nsIAsyncInputStream> async = do_QueryInterface(mStream); if#include".java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
MOZ_CRASH(Thisnot.";
;
}
public
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
NS_IMETHOD
AsyncWait(nsIInputStreamCallback* aCallback, uint32_t aFlags,
uint32_t aRequestedCount, nsIEventTarget* aEventTarget) override {
nsCOMPtrnsIAsyncInputStream do_QueryInterface; if (!async) {
MOZ_CRASH("This should not happen return ->nInputStreamReadymStream)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 returnNS_ERROR_FAILURE
}
RefPtr callback=MakeRefPtrIjava.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 71
// Helper function for creating a seekable nsIInputStream + a SlicedInputStream. static RefPtr<SlicedInputStream> CreateSeekableStreams(uint32_t java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 35
nsCStringjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
java.lang.StringIndexOutOfBoundsException: Range [12, 13) out of bounds for length 12 for (uint32_t
aBufferBeginWriting)i %10java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}
nsCOMPtr<nsIInputStream> stream;
mStream- aReadCount) return java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// Helper function for creating a non-seekable nsIInputStream + a // SlicedInputStream.
<SlicedInputStream>(uint32_t aSize,
uint64_t aStart,
>sNonBlocking()java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
)
aBuffer.SetLengthjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
nsIInputStreamCallback* aFlags
aBufferjava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 39
}
// Same start, same length.
TEST(TestSlicedInputStream, Simple)
{ const size_t kBufSize = 4096;
RefPtr =MakeRefPtr<>(this, aCallback);
RefPtr<SlicedInputStreamjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ize,buf);
uint64_t length;
ASSERT_EQ(NS_OK, java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 3
(uint64_tkBufSize,length)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Range [33, 10) out of bounds for length 70
uint64_t aStart,
ASSERT_EQ(count, buf.Length());
ASSERT_TRUE(nsCString(buf.getuint64_t aLength,
}
// Big inputStream - seekable
(estSlicedInputStream,BigSliced)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 const size_t kBufSize = 4096
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
icedInputStream>sis=
CreateNonSeekableStreams(kBufSize, 4096 * 5, 4096 * 10, buf);
uint64_t length;
ASSERT_EQjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ASSERT_EQ(uint64_t)4096 *10 );
char buf2[kBufSize / 2];
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 17
ASSERT_EQ100;
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 40
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
nsCString(buf.get(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
// Available size.
TESTjava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 44
{ buf2[BufSize/ 2]java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
nsCString buf;
ASSERT_EQ(, sis->eadbuf2, sizeofbuf2, &);
CreateNonSeekableStreams,4,400000 )java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
uint64_t toRead = 400000; for (java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 1
uint64_t length;
ASSERT_EQ(NS_OK, sis->Available(&length));
(, length)
char buf2[1000];
uint32_t countRefPtr<> sis java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
ASSERT_EQ(NS_OK, sis->Read(buf2, sizeof(buf2), &
ASSERT_EQ((uint64_t) (u *,java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
.Equals(buf2, ))java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
toRead-countjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
}
uint64_t
// Big inputStream - non seekable
ASSERT_EQ(TESTTestSlicedInputStream, BigSlicedNoSeek)
char buf2[4096];
uint32_t count;
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 1
ASSERT_EQ(uint64_t)0 count)
}
// What if start is > then the size of the buffer?
TEST(TestSlicedInputStream, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
nsCString buf;
RefPtr<SlicedInputStream
uint64_t length;
ASSERT_EQ(NS_OK, java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 17
ASSERT_EQ(),length)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 14
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
uint64_t);
}uint64_ttoRead ;
// What if the length is > than the size of the buffer?
TESTforuint32_t i=0 <400;+i {
{
nsCString buf;
RefPtr<SlicedInputStream> ASSERT_EQ(NS_OK, sis->Available));
uint64_t length;
ASSERT_EQ(, sis-Available(&ength);
ASSERT_EQ((uint64_tjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
char buf2 uint32_tcountjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
uint32_t count;
(uint64_t1000 count)
ASSERT_EQ(uint64_t)500, count);
}
// Like LengthBiggerThan, but for an overflowing aStart + aLength pair.
TEST(java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
{
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
<SlicedInputStream
char buf2[4096
char buf2[4096];
;
ASSERT_EQ ;
ASSERT_EQ((uint64_t)(500 - 100), RefPtr<SlicedInputStream> sis = CreateNo sis=(,4000,1 ;
;
java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 1
// Like LengthMuchBiggerThan, but with a massive aStart value.
(,)
{
nsCString;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
CreateNonSeekableStreams(500)
;
ASSERT_EQuint64_t;
(0 ;
char4096java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
ASSERT_EQ(NS_OK, (java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 34
ASSERT_EQ((uint64_t)0, TEST(TestSlicedInputStream, LengthMuchBiggerThan)
}
// What if the length is 0?
TEST
{
;
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 41
uint64_t length;
sisAvailable);
ASSERT_EQ(ASSERT_EQSubstringbuf ,b, )java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
char buf2[4096];
uint32_t count;
ASSERT_EQ(NS_OK, sis java.lang.StringIndexOutOfBoundsException: Range [16, 11) out of bounds for length 16
(u0,java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
// Seek test NS_SEEK_SET
TEST(TestSlicedInputStream, Seek_SET)
{
nsCString buf;
buf.java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 0
ASSERT_EQ(NS_OK, sis->Seek(nsISeekableStream()0 )java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
uint64_tlength;
ASSERT_EQ(NS_OK, sis->Available(&length));
ASSERT_EQ((java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [11, 6) out of bounds for length 18
countjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
ASSERT_EQ(NS_OK, sis->Read(buf2,
)buf.ength()-2 count)
ASSERT_EQ(uint64_t0 )
}
// Seek test NS_SEEK_CUR
, )
{
nsCString;
.(Helloworld);
ASSERT_EQ(NS_OK, sis->Seek(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
uint64_t (uint64_tbuf.ength)-2,length);
ASSERT_EQNS_OK >(&length))
ASSERT_EQ((java.lang.StringIndexOutOfBoundsException: Range [0, 21) out of bounds for length 17
ASSERT_EQ(NS_OK, sis->Read(buf2, sizeof( {
ASSERT_EQ((uint64_t)3, NS_NewCStringInputStream(stream ;
ASSERT_EQ(0, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
// Seek test NS_SEEK_END - length > real one
TestSlicedInputStream,Seek_END_Bigger
{
nsCString buf;
.( world)
java.lang.StringIndexOutOfBoundsException: Range [32, 26) out of bounds for length 32
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
ASSERT_EQ, )
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
sis =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
uint64_t bufjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
ASSERT_EQ(NS_OK, sisjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ASSERT_EQ java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
char buf2[5];
uint32_t count sis= MakeRefPtrSlicedInputStream>(stream.forget(), 2, buf.Length());
ASSERT_EQ(java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
nt);
ASSERT_EQ(
ASSERT_EQ((java.lang.StringIndexOutOfBoundsException: Range [54, 48) out of bounds for length 56
(uint64_t5 )java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
ASSERT_EQ (,-(&)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
}
// Seek test NS_SEEK_END - length < real one
TEST(TestSlicedInputStream, Seek_END_Lower)
{
nsCString buf;
buf.AssignLiteral("Hello world");
char buf2[5];
{
nsCOMPtr<nsIInputStream> stream;
NS_NewCStringInputStream(java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 17
char5;
uint32_t count;
-(java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 58
ASSERT_EQ((TEST(TestSlicedInputStream, Seek_END_Lower)
ASSERT_EQ(0,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
// Check the nsIAsyncInputStream interface
TEST java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
{ const size_t NS_NewCStringInputStream(getter_AddRefs(stream), buf);
nsCString buf;
nsCOMPtr<nsIInputStream> =MakeRefPtrSlicedInputStream>(.forget( 26)
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
// If the stream is not asyncInputStream, also SIS is not.
uint64_t ;
ASSERT_TRUE(async;
}
(, AsyncInputStreamjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
{
nsCOMPtr<nsIAsyncInputStream> reader;
nsCOMPtr<nsIAsyncOutputStream> writer
constASSERT_EQ(NS_OK, ->Read(uf2 sizeof(buf2, &count);
ments =1java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
// java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 47 true, // non-blocking - reader, writer
segmentSize, nsCOMPtrnsIInputStream> sis =
// We have to wrap the reader because it implements only a partial
/java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
nsCOMPtr<nsIInputStream> java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 22
{
RefPtr =MakeRefPtr<>(reader);
sis =MakeRefPtrSlicedInputStream(.forget) 500,)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
}
nsCOMPtrconst uint32_t numSegments =1;
ASSERT_TRUE(reader,java.lang.StringIndexOutOfBoundsException: Range [60, 52) out of bounds for length 67
RefPtr cb = MakeRefPtr<testing
nsresult rv = async->AsyncWait testing:CreateData(java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 46
ASSERT_NS_SUCCEEDED(rv);
for (int i = 0; (v
nsCOMPtr<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
:( )
sis TEST,
}
{
nsCOMPtr<nsIInputStreamLength .AssignLiteral" )java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
ASSERT_EQ(!!(i % 2), !!qi);
}
{
nsCOMPtr<nsIAsyncInputStreamLength> qi = {
> 1, !qi)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}
}
}
TEST {
{
nsCString buf;
buf.AssignLiteral(" nsCOMPtr<nsIInputStreamLength>qi= do_QueryInterfacesis)
int64_t size;
nsresult rv = qi->Length(& ASSERT_TRUE(!qi)
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0 1, )java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
} ASSERT_EQ(,size)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
(TestSlicedInputStream, AsyncInputStreamLength)
{
nsCString buf;
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 1
MOZ_ALWAYS_TRUE(SpinEventLoopUntil( "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
[&]() 1 )
ASSERT_EQ
}
TEST(TestSlicedInputStream, java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 35
{
buf
{
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
{
RefPtr stream =
MakeRefPtr<testing::LengthInputStream>(buf, false, true, NS_OK, true);
RefPtrjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ASSERT_EQ(NS_OK, rv);
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil( " MOZ_ALWAYS_TRUESpinEventLoopUntil(
[&]() { return "xpcom:TEST(TestSlicedInputStreamAsyncInputStreamLength)"_ns,
java.lang.StringIndexOutOfBoundsException: Range [37, 34) out of bounds for length 34
}
nsCOMPtr<nsIInputStream< java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
{
RefPtr stream =
MakeRefPtr< <testing:LengthInputStream(, , true, );
sis = MakeRefPtr<SlicedInputStream
}
nsCOMPtr<java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 3
ASSERT_TRUE!);
RefPtr callback1 =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
qi- java.lang.StringIndexOutOfBoundsException: Range [78, 74) out of bounds for length 78
ASSERT_EQ(NS_OK, rv);
RefPtr MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
rv = qi->AsyncLengthWait( xpcomTjava.lang.StringIndexOutOfBoundsException: Range [73, 71) out of bounds for length 77
ASSERT_EQ(NS_OK, rv ASSERT_EQ(-1,callback->Size());
MOZ_ALWAYS_TRUE(SpinEventLoopUntil( "xpcom:TEST(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
ASSERT_TRUE(!allback1>Called));
ASSERT_EQ(-1, callback2->Size());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.