Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/tests/gtest/TestStringStream.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "gtest/gtest.h"
8
#include "Helpers.h"
9
#include "nsICloneableInputStream.h"
10
#include "nsStringStream.h"
11
#include "nsTArray.h"
12
#include "nsIInputStream.h"
13
#include "nsCOMPtr.h"
14
15
namespace {
16
17
static void TestStringStream(uint32_t aNumBytes)
18
0
{
19
0
  nsTArray<char> inputData;
20
0
  testing::CreateData(aNumBytes, inputData);
21
0
  nsDependentCSubstring inputString(inputData.Elements(), inputData.Length());
22
0
23
0
  nsCOMPtr<nsIInputStream> stream;
24
0
  nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), inputString);
25
0
  ASSERT_TRUE(NS_SUCCEEDED(rv));
26
0
27
0
  testing::ConsumeAndValidateStream(stream, inputString);
28
0
}
29
30
static void TestStringStreamClone(uint32_t aNumBytes)
31
0
{
32
0
  nsTArray<char> inputData;
33
0
  testing::CreateData(aNumBytes, inputData);
34
0
  nsDependentCSubstring inputString(inputData.Elements(), inputData.Length());
35
0
36
0
  nsCOMPtr<nsIInputStream> stream;
37
0
  nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), inputString);
38
0
  ASSERT_TRUE(NS_SUCCEEDED(rv));
39
0
40
0
  nsCOMPtr<nsICloneableInputStream> cloneable = do_QueryInterface(stream);
41
0
  ASSERT_TRUE(cloneable != nullptr);
42
0
  ASSERT_TRUE(cloneable->GetCloneable());
43
0
44
0
  nsCOMPtr<nsIInputStream> clone;
45
0
  rv = cloneable->Clone(getter_AddRefs(clone));
46
0
47
0
  testing::ConsumeAndValidateStream(stream, inputString);
48
0
49
0
  // Release the stream to verify that the clone's string survives correctly.
50
0
  stream = nullptr;
51
0
52
0
  testing::ConsumeAndValidateStream(clone, inputString);
53
0
}
54
55
} // namespace
56
57
TEST(StringStream, Simple_4k)
58
0
{
59
0
  TestStringStream(1024 * 4);
60
0
}
61
62
TEST(StringStream, Clone_4k)
63
0
{
64
0
  TestStringStreamClone(1024 * 4);
65
0
}