pushtop.c 1.9 KB

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