home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / lazyinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.3 KB  |  121 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. /*
  20. ** File:        lazyinit.c
  21. ** Description: Testing lazy initialization
  22. **
  23. **      Since you only get to initialize once, you have to rerun the test
  24. **      for each test case. The test cases are numbered. If you want to
  25. **      add more tests, take the next number and add it to the switch
  26. **      statement.
  27. **
  28. **      This test is problematic on systems that don't support the notion
  29. **      of console output. The workarounds to emulate that feature include
  30. **      initializations themselves, which defeats the purpose here.
  31. */
  32.  
  33. #include "prcvar.h"
  34. #include "prenv.h"
  35. #include "prinit.h"
  36. #include "prinrval.h"
  37. #include "prio.h"
  38. #include "prlock.h"
  39. #include "prlog.h"
  40. #include "prthread.h"
  41. #include "prtypes.h"
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45.  
  46. static void PR_CALLBACK lazyEntry(void *arg)
  47. {
  48.     PR_ASSERT(NULL == arg);
  49. }  /* lazyEntry */
  50.  
  51.  
  52. PRIntn main(PRIntn argc, char *argv[])
  53. {
  54.     PRUintn pdkey;
  55.     PRStatus status;
  56.     char *path = NULL;
  57.     PRDir *dir = NULL;
  58.     PRLock *ml = NULL;
  59.     PRCondVar *cv = NULL;
  60.     PRThread *thread = NULL;
  61.     PRIntervalTime interval = 0;
  62.     PRFileDesc *file, *udp, *tcp, *pair[2];
  63.     PRIntn test;
  64.  
  65.     if ( argc < 2)
  66.     {
  67.         test = 0;
  68.     }
  69.     else
  70.         test = atoi(argv[1]);
  71.         
  72.     switch (test)
  73.     {
  74.         case 0: ml = PR_NewLock(); 
  75.             break;
  76.             
  77.         case 1: interval = PR_SecondsToInterval(1);
  78.             break;
  79.             
  80.         case 2: thread = PR_CreateThread(
  81.             PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
  82.             PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); 
  83.             break;
  84.             
  85.         case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0); 
  86.             break;
  87.             
  88.         case 4: udp = PR_NewUDPSocket(); 
  89.             break;
  90.             
  91.         case 5: tcp = PR_NewTCPSocket(); 
  92.             break;
  93.             
  94.         case 6: dir = PR_OpenDir("/usr/tmp/"); 
  95.             break;
  96.             
  97.         case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
  98.             break;
  99.         
  100.         case 8: path = PR_GetEnv("PATH");
  101.             break;
  102.             
  103.         case 9: status = PR_NewTCPSocketPair(pair);
  104.             break;
  105.             
  106.         case 10: PR_SetConcurrency(2);
  107.             break;
  108.             
  109.         default: 
  110.             printf(
  111.                 "lazyinit: unrecognized command line argument: %s\n", 
  112.                 argv[1] );
  113.             printf( "FAIL\n" );
  114.             exit( 1 );
  115.             break;
  116.     } /* switch() */
  117.     return 0;
  118. }  /* Lazy */
  119.  
  120. /* lazyinit.c */
  121.