|
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 { |
|
17 PRDescIdentity topId, middleId, bottomId; |
|
18 PRFileDesc *top, *middle, *bottom; |
|
19 PRFileDesc *fd; |
|
20 |
|
21 topId = PR_GetUniqueIdentity("top"); |
|
22 middleId = PR_GetUniqueIdentity("middle"); |
|
23 bottomId = PR_GetUniqueIdentity("bottom"); |
|
24 |
|
25 top = PR_CreateIOLayerStub(topId, &dummyMethods); |
|
26 middle = PR_CreateIOLayerStub(middleId, &dummyMethods); |
|
27 bottom = PR_CreateIOLayerStub(bottomId, &dummyMethods); |
|
28 |
|
29 fd = bottom; |
|
30 PR_PushIOLayer(fd, PR_TOP_IO_LAYER, middle); |
|
31 PR_PushIOLayer(fd, PR_TOP_IO_LAYER, top); |
|
32 |
|
33 top = fd; |
|
34 middle = top->lower; |
|
35 bottom = middle->lower; |
|
36 |
|
37 /* Verify that the higher pointers are correct. */ |
|
38 if (middle->higher != top) { |
|
39 fprintf(stderr, "middle->higher is wrong\n"); |
|
40 fprintf(stderr, "FAILED\n"); |
|
41 exit(1); |
|
42 } |
|
43 if (bottom->higher != middle) { |
|
44 fprintf(stderr, "bottom->higher is wrong\n"); |
|
45 fprintf(stderr, "FAILED\n"); |
|
46 exit(1); |
|
47 } |
|
48 |
|
49 top = PR_PopIOLayer(fd, topId); |
|
50 top->dtor(top); |
|
51 |
|
52 middle = fd; |
|
53 bottom = middle->lower; |
|
54 |
|
55 /* Verify that the higher pointer is correct. */ |
|
56 if (bottom->higher != middle) { |
|
57 fprintf(stderr, "bottom->higher is wrong\n"); |
|
58 fprintf(stderr, "FAILED\n"); |
|
59 exit(1); |
|
60 } |
|
61 |
|
62 middle = PR_PopIOLayer(fd, middleId); |
|
63 middle->dtor(middle); |
|
64 if (fd->identity != bottomId) { |
|
65 fprintf(stderr, "The bottom layer has the wrong identity\n"); |
|
66 fprintf(stderr, "FAILED\n"); |
|
67 exit(1); |
|
68 } |
|
69 fd->dtor(fd); |
|
70 |
|
71 printf("PASS\n"); |
|
72 return 0; |
|
73 } |