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/. */
9 #include "nsStreamUtils.h"
15 static bool test_consume_stream() {
17 "Get your facts first, and then you can distort them as much as you "
20 nsCOMPtr
<nsIInputStream
> input
;
21 nsCOMPtr
<nsIOutputStream
> output
;
22 NS_NewPipe(getter_AddRefs(input
), getter_AddRefs(output
), 10, UINT32_MAX
);
23 if (!input
|| !output
) return false;
26 output
->Write(kData
, sizeof(kData
) - 1, &n
);
27 if (n
!= (sizeof(kData
) - 1)) return false;
28 output
= nullptr; // close output
31 if (NS_FAILED(NS_ConsumeStream(input
, UINT32_MAX
, buf
))) return false;
33 if (!buf
.Equals(kData
)) return false;
40 typedef bool (*TestFunc
)();
41 #define DECL_TEST(name) \
44 static const struct Test
{
47 } tests
[] = {DECL_TEST(test_consume_stream
), {nullptr, nullptr}};
49 int main(int argc
, char** argv
) {
51 if (argc
> 1) count
= atoi(argv
[1]);
53 if (NS_FAILED(NS_InitXPCOM(nullptr, nullptr, nullptr))) return -1;
56 for (const Test
* t
= tests
; t
->name
!= nullptr; ++t
) {
57 printf("%25s : %s\n", t
->name
, t
->func() ? "SUCCESS" : "FAILURE");
61 NS_ShutdownXPCOM(nullptr);