1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
10 #include "nsStreamUtils.h"
16 static bool test_consume_stream() {
18 "Get your facts first, and then you can distort them as much as you "
21 nsCOMPtr
<nsIInputStream
> input
;
22 nsCOMPtr
<nsIOutputStream
> output
;
23 NS_NewPipe(getter_AddRefs(input
),
24 getter_AddRefs(output
),
26 if (!input
|| !output
)
30 output
->Write(kData
, sizeof(kData
) - 1, &n
);
31 if (n
!= (sizeof(kData
) - 1))
33 output
= nullptr; // close output
36 if (NS_FAILED(NS_ConsumeStream(input
, UINT32_MAX
, buf
)))
39 if (!buf
.Equals(kData
))
47 typedef bool (*TestFunc
)();
48 #define DECL_TEST(name) { #name, name }
50 static const struct Test
{
54 DECL_TEST(test_consume_stream
),
58 int main(int argc
, char **argv
) {
61 count
= atoi(argv
[1]);
63 if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr)))
67 for (const Test
* t
= tests
; t
->name
!= nullptr; ++t
) {
68 printf("%25s : %s\n", t
->name
, t
->func() ? "SUCCESS" : "FAILURE");
72 NS_ShutdownXPCOM(nullptr);