/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL"), in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your
* version of this file only under the terms of the GPL and not to
* allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient
* may use your version of this file under either the MPL or the
* GPL.
*/
#include "nspr.h"
#include "prpriv.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#include <process.h>
#endif
#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
#include <pthread.h>
#endif
#if defined(XP_OS2)
#define INCL_DOSFILEMGR
#include <os2.h>
#ifdef XP_OS2_EMX
#include <getopt.h>
#include <errno.h>
#endif /* XP_OS2_EMX */
#endif /* XP_OS2 */
static int _debug_on = 0;
#ifdef XP_MAC
#include "prlog.h"
#include "primpl.h"
#define setbuf(x,y)
extern void SetupMacPrintfLog(char *logFile);
#endif
#ifdef XP_WIN
#define mode_t int
#endif
int thread_count;
#ifdef WIN16
#else
#endif
typedef struct buffer {
} buffer;
typedef struct File_Rdwr_Param {
char *pathname;
char *buf;
int offset;
int len;
#ifdef XP_PC
#ifdef XP_OS2
#else
#endif
#else
#endif
void *arg,
{
switch(index % 4) {
case 0:
scope = (PR_LOCAL_THREAD);
break;
case 1:
scope = (PR_GLOBAL_THREAD);
break;
case 2:
break;
case 3:
native_thread = 1;
break;
default:
PR_ASSERT(!"Invalid scope");
break;
}
if (native_thread) {
#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
else
return (NULL);
if (tid == -1) {
return (NULL);
}
else
#else
unsigned tid;
NULL,
arg,
0,
&tid);
#endif
} else {
}
#else
#endif
}
{
return;
}
return;
}
return;
}
--thread_count;
}
{
return;
}
return;
}
return;
}
--thread_count;
}
{
/*
* Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
*/
return -1;
}
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
"testfile: Error - PR_GetFileInfo returned incorrect type for file %s\n",
pathname);
rv = -1;
goto cleanup;
}
"testfile PR_GetFileInfo returned incorrect size (%d should be 0) for file %s\n",
rv = -1;
goto cleanup;
}
if (len < 0) {
rv = -1;
goto cleanup;
} else if (len != 0) {
0, len);
rv = -1;
goto cleanup;
}
goto cleanup;
}
"testfile PR_GetFileInfo returned incorrect status-change time: %s\n",
pathname);
rv = -1;
goto cleanup;
}
if (len < 0) {
rv = -1;
goto cleanup;
}
goto cleanup;
}
"testfile PR_GetFileInfo returned incorrect size (%d should be %d) for file %s\n",
rv = -1;
goto cleanup;
}
"testfile PR_GetFileInfo returned incorrect modify time: %s\n",
pathname);
rv = -1;
goto cleanup;
}
if (len < 0) {
rv = -1;
goto cleanup;
} else if (len != 0) {
0, len);
rv = -1;
goto cleanup;
}
if (len < 0) {
rv = -1;
goto cleanup;
} else if (len != CHUNK_SIZE) {
CHUNK_SIZE, len);
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
}
rv = -1;
}
rv = -1;
}
return rv;
}
{
PRThread *t;
/*
* Create Test dir
*/
return -1;
}
rv = -1;
goto cleanup;
}
"testfile failed to alloc buffer struct\n");
rv = -1;
goto cleanup;
}
"testfile failed to alloc buffer struct\n");
rv = -1;
goto cleanup;
}
/*
* Start a bunch of writer threads
*/
offset = 0;
len = CHUNK_SIZE;
for (i = 0; i < NUM_RDWR_THREADS; i++) {
"testfile failed to alloc File_Rdwr_Param struct\n");
rv = -1;
goto cleanup;
}
File_Write, (void *)fparamp,
0, i);
}
thread_count = i;
/* Wait for writer threads to exit */
while (thread_count) {
}
/*
* Start a bunch of reader threads
*/
offset = 0;
len = CHUNK_SIZE;
for (i = 0; i < NUM_RDWR_THREADS; i++) {
"testfile failed to alloc File_Rdwr_Param struct\n");
rv = -1;
goto cleanup;
}
0, i);
break;
}
thread_count = i;
/* Wait for reader threads to exit */
while (thread_count) {
}
printf("File Test failed: file data corrupted\n");
rv = -1;
goto cleanup;
}
rv = -1;
goto cleanup;
}
/*
* Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
*/
if (Misc_File_Tests(pathname) < 0) {
rv = -1;
}
rv = -1;
}
return rv;
}
struct dirtest_arg {
};
{
int i;
PRThread *t;
mon = PR_NewMonitor();
if (!mon) {
printf("RunDirTest: Error - failed to create monitor\n");
dirtest_failed = 1;
return -1;
}
for (i = 0; i < NUM_DIRTEST_THREADS; i++) {
0, i);
if (!t) {
printf("RunDirTest: Error - failed to create thread\n");
dirtest_failed = 1;
return -1;
}
}
return 0;
}
{
int i;
int path_len;
#endif
/*
* Create Test dir
*/
"testfile failed to create dir %s [%d, %d]\n",
return -1;
}
"testfile failed to open dirctory %s [%d, %d]\n",
return -1;
}
for (i = 0; i < FILES_IN_DIR; i++) {
return -1;
}
}
#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
/*
* Create a hidden file - a platform-dependent operation
*/
return -1;
}
#if defined(XP_MAC)
{
#include <files.h>
return -1;
}
return -1;
}
return -1;
}
}
#endif
NULL,
NULL);
if (hfile == INVALID_HANDLE_VALUE) {
pathname, GetLastError());
return -1;
}
return -1;
}
#endif /* XP _UNIX || XP_MAC*/
#endif /* XP_UNIX || XP_MAC ||(XP_PC && WIN32) */
{
"testfile failed to close dirctory %s [%d, %d]\n",
return -1;
}
"testfile failed to reopen dirctory %s [%d, %d]\n",
return -1;
}
/*
* List all files, including hidden files
*/
#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
#else
#endif
num_files--;
"testfile failed to GetFileInfo file %s [%d, %d]\n",
return -1;
}
"testfile incorrect fileinfo for file %s [%d, %d]\n",
return -1;
}
}
if (num_files != 0)
{
"testfile failed to find all files in directory %s [%d, %d]\n",
return -1;
}
#if defined(XP_UNIX) || defined(XP_MAC) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2) || defined(XP_BEOS)
/*
* List all files, except hidden files
*/
"testfile failed to reopen dirctory %s [%d, %d]\n",
return -1;
}
return -1;
}
}
/*
* Delete hidden file
*/
"testfile failed to delete hidden file %s [%d, %d]\n",
return -1;
}
#endif /* XP_UNIX || XP_MAC || (XP_PC && WIN32) */
"testfile failed to rename directory %s [%d, %d]\n",
return -1;
}
"testfile failed to recreate dir %s [%d, %d]\n",
return -1;
}
"testfile renamed directory to existing name %s\n",
return -1;
}
"testfile failed to rmdir %s [%d, %d]\n",
return -1;
}
"testfile failed to rename directory %s [%d, %d]\n",
return -1;
}
"testfile failed to reopen directory %s [%d, %d]\n",
return -1;
}
for (i = 0; i < FILES_IN_DIR; i++) {
"testfile failed to delete file %s [%d, %d]\n",
return -1;
}
}
"testfile failed to rmdir %s [%d, %d]\n",
return -1;
}
return 0;
}
/************************************************************************/
/*
* Test file and directory NSPR APIs
*/
{
#ifdef WIN32
#endif
#if defined(XP_UNIX) || defined(XP_OS2_EMX)
int opt;
extern char *optarg;
extern int optind;
#endif
#if defined(XP_UNIX) || defined(XP_OS2_EMX)
switch(opt) {
case 'd':
_debug_on = 1;
break;
default:
break;
}
}
#endif
#ifdef XP_MAC
SetupMacPrintfLog("testfile.log");
#endif
mon = PR_NewMonitor();
printf("testfile: PR_NewMonitor failed\n");
exit(2);
}
#ifdef WIN32
/*
* enough space for prdir
*/
}
#endif
if (FileTest() < 0) {
printf("File Test failed\n");
exit(2);
}
printf("File Test passed\n");
if ((RunDirTest() < 0) || dirtest_failed) {
printf("Dir Test failed\n");
exit(2);
}
printf("Dir Test passed\n");
PR_Cleanup();
return 0;
}