Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / fdcach.c
blob5fa51b706a8a2e8edece6a806fb9e17da2738304
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: fdcach.c
8 * Description:
9 * This test verifies that the fd cache is working
10 * correctly.
13 #include "nspr.h"
15 #include <stdio.h>
16 #include <stdlib.h>
19 * Define ORDER_PRESERVED if the implementation of PR_SetFDCacheSize
20 * preserves the ordering of the fd's when moving them between the
21 * cache.
23 #define ORDER_PRESERVED 1
26 * NUM_FDS must be <= FD_CACHE_SIZE.
28 #define FD_CACHE_SIZE 1024
29 #define NUM_FDS 20
31 int main(int argc, char **argv)
33 int i;
34 PRFileDesc *fds[NUM_FDS];
35 PRFileDesc *savefds[NUM_FDS];
36 int numfds = sizeof(fds)/sizeof(fds[0]);
38 PR_SetFDCacheSize(0, FD_CACHE_SIZE);
40 /* Add some fd's to the fd cache. */
41 for (i = 0; i < numfds; i++) {
42 savefds[i] = PR_NewTCPSocket();
43 if (NULL == savefds[i]) {
44 fprintf(stderr, "PR_NewTCPSocket failed\n");
45 exit(1);
48 for (i = 0; i < numfds; i++) {
49 if (PR_Close(savefds[i]) == PR_FAILURE) {
50 fprintf(stderr, "PR_Close failed\n");
51 exit(1);
56 * Create some fd's. These fd's should come from
57 * the fd cache. Verify the FIFO ordering of the fd
58 * cache.
60 for (i = 0; i < numfds; i++) {
61 fds[i] = PR_NewTCPSocket();
62 if (NULL == fds[i]) {
63 fprintf(stderr, "PR_NewTCPSocket failed\n");
64 exit(1);
66 if (fds[i] != savefds[i]) {
67 fprintf(stderr, "fd cache malfunctioned\n");
68 exit(1);
71 /* Put the fd's back to the fd cache. */
72 for (i = 0; i < numfds; i++) {
73 if (PR_Close(savefds[i]) == PR_FAILURE) {
74 fprintf(stderr, "PR_Close failed\n");
75 exit(1);
79 /* Switch to the fd cache. */
80 PR_SetFDCacheSize(0, FD_CACHE_SIZE);
82 for (i = 0; i < numfds; i++) {
83 fds[i] = PR_NewTCPSocket();
84 if (NULL == fds[i]) {
85 fprintf(stderr, "PR_NewTCPSocket failed\n");
86 exit(1);
88 #ifdef ORDER_PRESERVED
89 if (fds[i] != savefds[i]) {
90 fprintf(stderr, "fd cache malfunctioned\n");
91 exit(1);
93 #else
94 savefds[i] = fds[i];
95 #endif
97 for (i = 0; i < numfds; i++) {
98 if (PR_Close(savefds[i]) == PR_FAILURE) {
99 fprintf(stderr, "PR_Close failed\n");
100 exit(1);
104 for (i = 0; i < numfds; i++) {
105 fds[i] = PR_NewTCPSocket();
106 if (NULL == fds[i]) {
107 fprintf(stderr, "PR_NewTCPSocket failed\n");
108 exit(1);
110 if (fds[i] != savefds[i]) {
111 fprintf(stderr, "fd cache malfunctioned\n");
112 exit(1);
115 for (i = 0; i < numfds; i++) {
116 if (PR_Close(savefds[i]) == PR_FAILURE) {
117 fprintf(stderr, "PR_Close failed\n");
118 exit(1);
122 PR_Cleanup();
123 printf("PASS\n");
124 return 0;