home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / atomic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  76 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "prio.h"
  20. #include "prprf.h"
  21. #include "pratom.h"
  22.  
  23. PRIntn main(PRIntn argc, char **argv)
  24. {
  25.     PRInt32 rv, test, result = 0;
  26.     PRFileDesc *output = PR_GetSpecialFD(PR_StandardOutput);
  27.  
  28.     test = -2;
  29.     rv = PR_AtomicIncrement(&test);
  30.     result = result | ((rv < 0) ? 0 : 1);
  31.     PR_fprintf(
  32.         output, "PR_AtomicIncrement(%d) == %d: %s\n",
  33.         test, rv, (rv < 0) ? "PASSED" : "FAILED");
  34.     rv = PR_AtomicIncrement(&test);
  35.     result = result | ((rv == 0) ? 0 : 1);
  36.     PR_fprintf(
  37.         output, "PR_AtomicIncrement(%d) == %d: %s\n",
  38.         test, rv, (rv == 0) ? "PASSED" : "FAILED");
  39.     rv = PR_AtomicIncrement(&test);
  40.     result = result | ((rv > 0) ? 0 : 1);
  41.     PR_fprintf(
  42.         output, "PR_AtomicIncrement(%d) == %d: %s\n",
  43.         test, rv, (rv > 0) ? "PASSED" : "FAILED");
  44.  
  45.     test = 2;
  46.     rv = PR_AtomicDecrement(&test);
  47.     result = result | ((rv > 0) ? 0 : 1);
  48.     PR_fprintf(
  49.         output, "PR_AtomicDecrement(%d) == %d: %s\n",
  50.         test, rv, (rv > 0) ? "PASSED" : "FAILED");
  51.     rv = PR_AtomicDecrement(&test);
  52.     result = result | ((rv == 0) ? 0 : 1);
  53.     PR_fprintf(
  54.         output, "PR_AtomicDecrement(%d) == %d: %s\n",
  55.         test, rv, (rv == 0) ? "PASSED" : "FAILED");
  56.     rv = PR_AtomicDecrement(&test);
  57.     result = result | ((rv < 0) ? 0 : 1);
  58.     PR_fprintf(
  59.         output, "PR_AtomicDecrement(%d) == %d: %s\n",
  60.         test, rv, (rv < 0) ? "PASSED" : "FAILED");
  61.  
  62.     test = -2;
  63.     rv = PR_AtomicSet(&test, 2);
  64.     result = result | (((rv == -2) && (test == 2)) ? 0 : 1);
  65.     PR_fprintf(
  66.         output, "PR_AtomicSet(%d) == %d: %s\n",
  67.         test, rv, ((rv == -2) && (test == 2)) ? "PASSED" : "FAILED");
  68.  
  69.     PR_fprintf(
  70.         output, "Atomic operations test %s\n",
  71.         (result == 0) ? "PASSED" : "FAILED");
  72.     return result;
  73. }  /* main */
  74.  
  75. /* atomic.c */
  76.