1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/pushtop.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* A regression test for bug 794316 */ 1.10 + 1.11 +#include <stdio.h> 1.12 +#include <stdlib.h> 1.13 + 1.14 +#include "prio.h" 1.15 + 1.16 +static PRIOMethods dummyMethods; 1.17 + 1.18 +int main() 1.19 +{ 1.20 + PRDescIdentity topId, middleId, bottomId; 1.21 + PRFileDesc *top, *middle, *bottom; 1.22 + PRFileDesc *fd; 1.23 + 1.24 + topId = PR_GetUniqueIdentity("top"); 1.25 + middleId = PR_GetUniqueIdentity("middle"); 1.26 + bottomId = PR_GetUniqueIdentity("bottom"); 1.27 + 1.28 + top = PR_CreateIOLayerStub(topId, &dummyMethods); 1.29 + middle = PR_CreateIOLayerStub(middleId, &dummyMethods); 1.30 + bottom = PR_CreateIOLayerStub(bottomId, &dummyMethods); 1.31 + 1.32 + fd = bottom; 1.33 + PR_PushIOLayer(fd, PR_TOP_IO_LAYER, middle); 1.34 + PR_PushIOLayer(fd, PR_TOP_IO_LAYER, top); 1.35 + 1.36 + top = fd; 1.37 + middle = top->lower; 1.38 + bottom = middle->lower; 1.39 + 1.40 + /* Verify that the higher pointers are correct. */ 1.41 + if (middle->higher != top) { 1.42 + fprintf(stderr, "middle->higher is wrong\n"); 1.43 + fprintf(stderr, "FAILED\n"); 1.44 + exit(1); 1.45 + } 1.46 + if (bottom->higher != middle) { 1.47 + fprintf(stderr, "bottom->higher is wrong\n"); 1.48 + fprintf(stderr, "FAILED\n"); 1.49 + exit(1); 1.50 + } 1.51 + 1.52 + top = PR_PopIOLayer(fd, topId); 1.53 + top->dtor(top); 1.54 + 1.55 + middle = fd; 1.56 + bottom = middle->lower; 1.57 + 1.58 + /* Verify that the higher pointer is correct. */ 1.59 + if (bottom->higher != middle) { 1.60 + fprintf(stderr, "bottom->higher is wrong\n"); 1.61 + fprintf(stderr, "FAILED\n"); 1.62 + exit(1); 1.63 + } 1.64 + 1.65 + middle = PR_PopIOLayer(fd, middleId); 1.66 + middle->dtor(middle); 1.67 + if (fd->identity != bottomId) { 1.68 + fprintf(stderr, "The bottom layer has the wrong identity\n"); 1.69 + fprintf(stderr, "FAILED\n"); 1.70 + exit(1); 1.71 + } 1.72 + fd->dtor(fd); 1.73 + 1.74 + printf("PASS\n"); 1.75 + return 0; 1.76 +}