michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include "nsIPipe.h" michael@0: #include "nsStreamUtils.h" michael@0: #include "nsString.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: //---- michael@0: michael@0: static bool test_consume_stream() { michael@0: const char kData[] = michael@0: "Get your facts first, and then you can distort them as much as you " michael@0: "please."; michael@0: michael@0: nsCOMPtr input; michael@0: nsCOMPtr output; michael@0: NS_NewPipe(getter_AddRefs(input), michael@0: getter_AddRefs(output), michael@0: 10, UINT32_MAX); michael@0: if (!input || !output) michael@0: return false; michael@0: michael@0: uint32_t n = 0; michael@0: output->Write(kData, sizeof(kData) - 1, &n); michael@0: if (n != (sizeof(kData) - 1)) michael@0: return false; michael@0: output = nullptr; // close output michael@0: michael@0: nsCString buf; michael@0: if (NS_FAILED(NS_ConsumeStream(input, UINT32_MAX, buf))) michael@0: return false; michael@0: michael@0: if (!buf.Equals(kData)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: //---- michael@0: michael@0: typedef bool (*TestFunc)(); michael@0: #define DECL_TEST(name) { #name, name } michael@0: michael@0: static const struct Test { michael@0: const char* name; michael@0: TestFunc func; michael@0: } tests[] = { michael@0: DECL_TEST(test_consume_stream), michael@0: { nullptr, nullptr } michael@0: }; michael@0: michael@0: int main(int argc, char **argv) { michael@0: int count = 1; michael@0: if (argc > 1) michael@0: count = atoi(argv[1]); michael@0: michael@0: if (NS_FAILED(NS_InitXPCOM2(nullptr, nullptr, nullptr))) michael@0: return -1; michael@0: michael@0: while (count--) { michael@0: for (const Test* t = tests; t->name != nullptr; ++t) { michael@0: printf("%25s : %s\n", t->name, t->func() ? "SUCCESS" : "FAILURE"); michael@0: } michael@0: } michael@0: michael@0: NS_ShutdownXPCOM(nullptr); michael@0: return 0; michael@0: }