2005-12-10 00:35:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-12-10 00:35:27 +03:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsIPipe.h"
|
|
|
|
#include "nsStreamUtils.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
//----
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool test_consume_stream() {
|
2005-12-10 00:35:27 +03:00
|
|
|
const char kData[] =
|
|
|
|
"Get your facts first, and then you can distort them as much as you "
|
|
|
|
"please.";
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> input;
|
|
|
|
nsCOMPtr<nsIOutputStream> output;
|
|
|
|
NS_NewPipe(getter_AddRefs(input), getter_AddRefs(output), 10, UINT32_MAX);
|
|
|
|
if (!input || !output) return false;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t n = 0;
|
2005-12-10 00:35:27 +03:00
|
|
|
output->Write(kData, sizeof(kData) - 1, &n);
|
|
|
|
if (n != (sizeof(kData) - 1)) return false;
|
2012-07-30 18:20:58 +04:00
|
|
|
output = nullptr; // close output
|
2005-12-10 00:35:27 +03:00
|
|
|
|
|
|
|
nsCString buf;
|
2012-09-28 10:57:33 +04:00
|
|
|
if (NS_FAILED(NS_ConsumeStream(input, UINT32_MAX, buf))) return false;
|
2005-12-10 00:35:27 +03:00
|
|
|
|
|
|
|
if (!buf.Equals(kData)) return false;
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return true;
|
2005-12-10 00:35:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
typedef bool (*TestFunc)();
|
2005-12-10 00:35:27 +03:00
|
|
|
#define DECL_TEST(name) \
|
|
|
|
{ #name, name }
|
|
|
|
|
|
|
|
static const struct Test {
|
|
|
|
const char* name;
|
|
|
|
TestFunc func;
|
|
|
|
} tests[] = {DECL_TEST(test_consume_stream), {nullptr, nullptr}};
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int count = 1;
|
|
|
|
if (argc > 1) count = atoi(argv[1]);
|
|
|
|
|
2019-03-15 09:38:09 +03:00
|
|
|
if (NS_FAILED(NS_InitXPCOM(nullptr, nullptr, nullptr))) return -1;
|
2005-12-10 00:35:27 +03:00
|
|
|
|
|
|
|
while (count--) {
|
2012-07-30 18:20:58 +04:00
|
|
|
for (const Test* t = tests; t->name != nullptr; ++t) {
|
2005-12-10 00:35:27 +03:00
|
|
|
printf("%25s : %s\n", t->name, t->func() ? "SUCCESS" : "FAILURE");
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
2005-12-10 00:35:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|