Back to index

lightning-sunbird  0.9+nobinonly
lazyinit.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File:        lazyinit.c
00040 ** Description: Testing lazy initialization
00041 **
00042 **      Since you only get to initialize once, you have to rerun the test
00043 **      for each test case. The test cases are numbered. If you want to
00044 **      add more tests, take the next number and add it to the switch
00045 **      statement.
00046 **
00047 **      This test is problematic on systems that don't support the notion
00048 **      of console output. The workarounds to emulate that feature include
00049 **      initializations themselves, which defeats the purpose here.
00050 */
00051 
00052 #include "prcvar.h"
00053 #include "prenv.h"
00054 #include "prinit.h"
00055 #include "prinrval.h"
00056 #include "prio.h"
00057 #include "prlock.h"
00058 #include "prlog.h"
00059 #include "prthread.h"
00060 #include "prtypes.h"
00061 
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064 
00065 static void PR_CALLBACK lazyEntry(void *arg)
00066 {
00067     PR_ASSERT(NULL == arg);
00068 }  /* lazyEntry */
00069 
00070 
00071 PRIntn main(PRIntn argc, char *argv[])
00072 {
00073     PRUintn pdkey;
00074     PRStatus status;
00075     char *path = NULL;
00076     PRDir *dir = NULL;
00077     PRLock *ml = NULL;
00078     PRCondVar *cv = NULL;
00079     PRThread *thread = NULL;
00080     PRIntervalTime interval = 0;
00081     PRFileDesc *file, *udp, *tcp, *pair[2];
00082     PRIntn test;
00083 
00084     if ( argc < 2)
00085     {
00086         test = 0;
00087     }
00088     else
00089         test = atoi(argv[1]);
00090         
00091     switch (test)
00092     {
00093         case 0: ml = PR_NewLock(); 
00094             break;
00095             
00096         case 1: interval = PR_SecondsToInterval(1);
00097             break;
00098             
00099         case 2: thread = PR_CreateThread(
00100             PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
00101             PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); 
00102             break;
00103             
00104         case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0); 
00105             break;
00106             
00107         case 4: udp = PR_NewUDPSocket(); 
00108             break;
00109             
00110         case 5: tcp = PR_NewTCPSocket(); 
00111             break;
00112             
00113         case 6: dir = PR_OpenDir("/usr/tmp/"); 
00114             break;
00115             
00116         case 7: (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
00117             break;
00118         
00119         case 8: path = PR_GetEnv("PATH");
00120             break;
00121             
00122         case 9: status = PR_NewTCPSocketPair(pair);
00123             break;
00124             
00125         case 10: PR_SetConcurrency(2);
00126             break;
00127             
00128         default: 
00129             printf(
00130                 "lazyinit: unrecognized command line argument: %s\n", 
00131                 argv[1] );
00132             printf( "FAIL\n" );
00133             exit( 1 );
00134             break;
00135     } /* switch() */
00136     return 0;
00137 }  /* Lazy */
00138 
00139 /* lazyinit.c */