nsprpub/pr/tests/pushtop.c

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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/. */
     6 /* A regression test for bug 794316 */
     8 #include <stdio.h>
     9 #include <stdlib.h>
    11 #include "prio.h"
    13 static PRIOMethods dummyMethods;
    15 int main()
    16 {
    17     PRDescIdentity topId, middleId, bottomId;
    18     PRFileDesc *top, *middle, *bottom;
    19     PRFileDesc *fd;
    21     topId = PR_GetUniqueIdentity("top");
    22     middleId = PR_GetUniqueIdentity("middle");
    23     bottomId = PR_GetUniqueIdentity("bottom");
    25     top = PR_CreateIOLayerStub(topId, &dummyMethods);
    26     middle = PR_CreateIOLayerStub(middleId, &dummyMethods);
    27     bottom = PR_CreateIOLayerStub(bottomId, &dummyMethods);
    29     fd = bottom;
    30     PR_PushIOLayer(fd, PR_TOP_IO_LAYER, middle);
    31     PR_PushIOLayer(fd, PR_TOP_IO_LAYER, top);
    33     top = fd;
    34     middle = top->lower;
    35     bottom = middle->lower;
    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     }
    49     top = PR_PopIOLayer(fd, topId);
    50     top->dtor(top);
    52     middle = fd;
    53     bottom = middle->lower;
    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     }
    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);
    71     printf("PASS\n");
    72     return 0;
    73 }

mercurial