| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 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/. */ |
| 5 |
|
| 6 |
/* A regression test for bug 794316 */ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
#include "prio.h" |
| 12 |
|
| 13 |
static PRIOMethods dummyMethods; |
| 14 |
|
| 15 |
int main() { |
| 16 |
PRDescIdentity topId, middleId, bottomId; |
| 17 |
PRFileDesc *top, *middle, *bottom; |
| 18 |
PRFileDesc* fd; |
| 19 |
|
| 20 |
topId = PR_GetUniqueIdentity("top"); |
| 21 |
middleId = PR_GetUniqueIdentity("middle"); |
| 22 |
bottomId = PR_GetUniqueIdentity("bottom"); |
| 23 |
|
| 24 |
top = PR_CreateIOLayerStub(topId, &dummyMethods); |
| 25 |
middle = PR_CreateIOLayerStub(middleId, &dummyMethods); |
| 26 |
bottom = PR_CreateIOLayerStub(bottomId, &dummyMethods); |
| 27 |
|
| 28 |
fd = bottom; |
| 29 |
PR_PushIOLayer(fd, PR_TOP_IO_LAYER, middle); |
| 30 |
PR_PushIOLayer(fd, PR_TOP_IO_LAYER, top); |
| 31 |
|
| 32 |
top = fd; |
| 33 |
middle = top->lower; |
| 34 |
bottom = middle->lower; |
| 35 |
|
| 36 |
/* Verify that the higher pointers are correct. */ |
| 37 |
if (middle->higher != top) { |
| 38 |
fprintf(stderr, "middle->higher is wrong\n"); |
| 39 |
fprintf(stderr, "FAILED\n"); |
| 40 |
exit(1); |
| 41 |
} |
| 42 |
if (bottom->higher != middle) { |
| 43 |
fprintf(stderr, "bottom->higher is wrong\n"); |
| 44 |
fprintf(stderr, "FAILED\n"); |
| 45 |
exit(1); |
| 46 |
} |
| 47 |
|
| 48 |
top = PR_PopIOLayer(fd, topId); |
| 49 |
top->dtor(top); |
| 50 |
|
| 51 |
middle = fd; |
| 52 |
bottom = middle->lower; |
| 53 |
|
| 54 |
/* Verify that the higher pointer is correct. */ |
| 55 |
if (bottom->higher != middle) { |
| 56 |
fprintf(stderr, "bottom->higher is wrong\n"); |
| 57 |
fprintf(stderr, "FAILED\n"); |
| 58 |
exit(1); |
| 59 |
} |
| 60 |
|
| 61 |
middle = PR_PopIOLayer(fd, middleId); |
| 62 |
middle->dtor(middle); |
| 63 |
if (fd->identity != bottomId) { |
| 64 |
fprintf(stderr, "The bottom layer has the wrong identity\n"); |
| 65 |
fprintf(stderr, "FAILED\n"); |
| 66 |
exit(1); |
| 67 |
} |
| 68 |
fd->dtor(fd); |
| 69 |
|
| 70 |
printf("PASS\n"); |
| 71 |
return 0; |
| 72 |
} |