Bug 1837620 - Part 1: Remove baseline ICs that guard shapes when the shape becomes...
[gecko.git] / xpcom / tests / TestStreamUtils.cpp
blob9ba6d36aa3ac6be2ea69c6dc5aa198e288d524ea
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/. */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "nsStreamUtils.h"
10 #include "nsString.h"
11 #include "nsCOMPtr.h"
13 //----
15 static bool test_consume_stream() {
16 const char kData[] =
17 "Get your facts first, and then you can distort them as much as you "
18 "please.";
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;
25 uint32_t n = 0;
26 output->Write(kData, sizeof(kData) - 1, &n);
27 if (n != (sizeof(kData) - 1)) return false;
28 output = nullptr; // close output
30 nsCString buf;
31 if (NS_FAILED(NS_ConsumeStream(input, UINT32_MAX, buf))) return false;
33 if (!buf.Equals(kData)) return false;
35 return true;
38 //----
40 typedef bool (*TestFunc)();
41 #define DECL_TEST(name) \
42 { \
43 # name, name \
46 static const struct Test {
47 const char* name;
48 TestFunc func;
49 } tests[] = {DECL_TEST(test_consume_stream), {nullptr, nullptr}};
51 int main(int argc, char** argv) {
52 int count = 1;
53 if (argc > 1) count = atoi(argv[1]);
55 if (NS_FAILED(NS_InitXPCOM(nullptr, nullptr, nullptr))) return -1;
57 while (count--) {
58 for (const Test* t = tests; t->name != nullptr; ++t) {
59 printf("%25s : %s\n", t->name, t->func() ? "SUCCESS" : "FAILURE");
63 NS_ShutdownXPCOM(nullptr);
64 return 0;