Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / pipepong.c
blob965aec32de9eb4e07b4d8ab2fe3a79781780739a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * File: pipepong.c
9 * Description:
10 * This test runs in conjunction with the pipeping test.
11 * The pipeping test creates two pipes and redirects the
12 * stdin and stdout of this test to the pipes. Then the
13 * pipeping test writes "ping" to this test and this test
14 * writes "pong" back. Note that this test does not depend
15 * on NSPR at all. To run this pair of tests, just invoke
16 * pipeping.
18 * Tested areas: process creation, pipes, file descriptor
19 * inheritance, standard I/O redirection.
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
26 #define NUM_ITERATIONS 10
28 int main(int argc, char **argv)
30 char buf[1024];
31 size_t nBytes;
32 int idx;
34 for (idx = 0; idx < NUM_ITERATIONS; idx++) {
35 memset(buf, 0, sizeof(buf));
36 nBytes = fread(buf, 1, 5, stdin);
37 fprintf(stderr, "pong process: received \"%s\"\n", buf);
38 if (nBytes != 5) {
39 fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n",
40 nBytes);
41 exit(1);
43 if (strcmp(buf, "ping") != 0) {
44 fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n",
45 buf);
46 exit(1);
49 strcpy(buf, "pong");
50 fprintf(stderr, "pong process: sending \"%s\"\n", buf);
51 nBytes = fwrite(buf, 1, 5, stdout);
52 if (nBytes != 5) {
53 fprintf(stderr, "pong process: fwrite failed\n");
54 exit(1);
56 fflush(stdout);
59 return 0;