mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 09:36:46 +00:00
add js to tree
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3693 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1
libs/js/nsprpub/lib/tests/.cvsignore
Normal file
1
libs/js/nsprpub/lib/tests/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
Makefile
|
6
libs/js/nsprpub/lib/tests/CVS/Entries
Normal file
6
libs/js/nsprpub/lib/tests/CVS/Entries
Normal file
@@ -0,0 +1,6 @@
|
||||
/.cvsignore/1.2/Sat May 12 01:31:18 2001//
|
||||
/Makefile.in/1.14/Mon Nov 8 02:52:55 2004//
|
||||
/arena.c/3.7/Sun Apr 25 15:00:46 2004//
|
||||
/base64t.c/3.5/Sun Apr 25 15:00:46 2004//
|
||||
/string.c/3.8/Sun Apr 25 15:00:46 2004//
|
||||
D
|
1
libs/js/nsprpub/lib/tests/CVS/Entries.Log
Normal file
1
libs/js/nsprpub/lib/tests/CVS/Entries.Log
Normal file
@@ -0,0 +1 @@
|
||||
A D/windows////
|
1
libs/js/nsprpub/lib/tests/CVS/Repository
Normal file
1
libs/js/nsprpub/lib/tests/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
mozilla/nsprpub/lib/tests
|
1
libs/js/nsprpub/lib/tests/CVS/Root
Normal file
1
libs/js/nsprpub/lib/tests/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
|
259
libs/js/nsprpub/lib/tests/Makefile.in
Normal file
259
libs/js/nsprpub/lib/tests/Makefile.in
Normal file
@@ -0,0 +1,259 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1998-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#! gmake
|
||||
|
||||
MOD_DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(MOD_DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
# DIRS = windows
|
||||
endif
|
||||
|
||||
ifeq ($(OS_TARGET), WIN16)
|
||||
OS_CFLAGS = $(OS_EXE_CFLAGS)
|
||||
endif
|
||||
|
||||
CSRCS = \
|
||||
arena.c \
|
||||
string.c \
|
||||
base64t.c
|
||||
|
||||
ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
|
||||
CSRCS += arena.c
|
||||
endif
|
||||
|
||||
ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
|
||||
PROG_SUFFIX = .exe
|
||||
else
|
||||
PROG_SUFFIX =
|
||||
endif
|
||||
|
||||
PROGS = $(addprefix $(OBJDIR)/, $(CSRCS:.c=$(PROG_SUFFIX)))
|
||||
|
||||
TARGETS = $(PROGS) $(OBJS)
|
||||
|
||||
INCLUDES = -I$(dist_includedir)
|
||||
|
||||
# Setting the variables LDOPTS and LIBPR. We first initialize
|
||||
# them to the default values, then adjust them for some platforms.
|
||||
LDOPTS = -L$(dist_libdir)
|
||||
LIBPR = -lnspr$(MOD_MAJOR_VERSION)
|
||||
LIBPLC = -lplc$(MOD_MAJOR_VERSION)
|
||||
LIBPLDS = -lplds$(MOD_MAJOR_VERSION)
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
ifeq ($(OS_TARGET), WIN16)
|
||||
LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).lib
|
||||
LIBPLC= $(dist_libdir)/plc$(MOD_MAJOR_VERSION).lib
|
||||
LIBPLDS= $(dist_libdir)/plds$(MOD_MAJOR_VERSION).lib
|
||||
else
|
||||
LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
|
||||
ifeq ($(OS_TARGET), WIN95)
|
||||
LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLC= $(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLDS= $(dist_libdir)/plds$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
else
|
||||
LIBPR = $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLC= $(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLDS= $(dist_libdir)/libplds$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
ifeq ($(MOZ_OS2_TOOLS),VACPP)
|
||||
LDOPTS = -NOE -DEBUG -nologo -PMTYPE:VIO /S:32768
|
||||
LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).lib
|
||||
LIBPLC = $(dist_libdir)/plc$(MOD_MAJOR_VERSION).lib
|
||||
LIBPLDS= $(dist_libdir)/plds$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
|
||||
else
|
||||
LDOPTS += -Zomf -Zlinker /PM:VIO
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(OS_ARCH), WINNT)
|
||||
PWD = $(shell pwd)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), IRIX)
|
||||
LDOPTS += -rpath $(PWD)/$(dist_libdir)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
ifeq ($(OS_RELEASE), 1.2)
|
||||
EXTRA_LIBS = -ldl
|
||||
else
|
||||
LDOPTS += -Xlinker -rpath $(PWD)/$(dist_libdir)
|
||||
ifeq ($(USE_PTHREADS),1)
|
||||
EXTRA_LIBS = -lpthread
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), OSF1)
|
||||
LDOPTS += -rpath $(PWD)/$(dist_libdir) -lpthread
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), HP-UX)
|
||||
LDOPTS += -Wl,+s,+b,$(PWD)/$(dist_libdir)
|
||||
endif
|
||||
|
||||
# AIX
|
||||
ifeq ($(OS_ARCH),AIX)
|
||||
LDOPTS += -blibpath:$(PWD)/$(dist_libdir):/usr/lib:/lib
|
||||
LIBPR = -lnspr$(MOD_MAJOR_VERSION)_shr
|
||||
LIBPLC = -lplc$(MOD_MAJOR_VERSION)_shr
|
||||
endif
|
||||
|
||||
# Solaris
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
ifneq ($(OS_RELEASE), 4.1.3_U1)
|
||||
ifdef NS_USE_GCC
|
||||
LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(dist_libdir)
|
||||
else
|
||||
LDOPTS += -R $(PWD)/$(dist_libdir)
|
||||
endif
|
||||
endif
|
||||
|
||||
# SunOS 5.4 and 5.5 need to link with -lthread or -lpthread,
|
||||
# even though we already linked with these system libraries
|
||||
# when we built libnspr.so.
|
||||
ifeq ($(OS_RELEASE), 5.4)
|
||||
EXTRA_LIBS = -lthread
|
||||
endif
|
||||
|
||||
ifeq ($(OS_RELEASE), 5.5)
|
||||
ifdef USE_PTHREADS
|
||||
EXTRA_LIBS = -lpthread
|
||||
else
|
||||
EXTRA_LIBS = -lthread
|
||||
endif
|
||||
endif
|
||||
endif # SunOS
|
||||
|
||||
ifeq ($(OS_ARCH), NCR)
|
||||
# NCR needs to link against -lsocket -lnsl (and -lc, which is linked
|
||||
# implicitly by $(CC)) again even though we already linked with these
|
||||
# system libraries when we built libnspr.so.
|
||||
EXTRA_LIBS = -lsocket -lnsl
|
||||
# This hardcodes in the executable programs the directory to find
|
||||
# libnspr.so etc. at program startup. Equivalent to the -R or -rpath
|
||||
# option for ld on other platforms.
|
||||
export LD_RUN_PATH = $(PWD)/$(dist_libdir)
|
||||
endif
|
||||
|
||||
#####################################################
|
||||
#
|
||||
# The rules
|
||||
#
|
||||
#####################################################
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
AIX_PRE_4_2 = 0
|
||||
ifeq ($(OS_ARCH),AIX)
|
||||
ifneq ($(OS_RELEASE),4.2)
|
||||
ifneq ($(USE_PTHREADS), 1)
|
||||
#AIX_PRE_4_2 = 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(AIX_PRE_4_2),1)
|
||||
|
||||
# AIX releases prior to 4.2 need a special two-step linking hack
|
||||
# in order to both override the system select() and be able to
|
||||
# get at the original system select().
|
||||
#
|
||||
# We use a pattern rule in ns/nspr20/config/rules.mk to generate
|
||||
# the .$(OBJ_SUFFIX) file from the .c source file, then do the
|
||||
# two-step linking hack below.
|
||||
|
||||
$(OBJDIR)/%: $(OBJDIR)/%.$(OBJ_SUFFIX)
|
||||
@$(MAKE_OBJDIR)
|
||||
rm -f $@ $(AIX_TMP)
|
||||
$(CC) $(AIX_LINK_OPTS) -o $(AIX_TMP) $< $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).a
|
||||
$(CC) -o $@ $(AIX_TMP) $(AIX_WRAP)
|
||||
rm -f $(AIX_TMP)
|
||||
|
||||
else
|
||||
|
||||
# All platforms that are not AIX pre-4.2.
|
||||
|
||||
$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
|
||||
@$(MAKE_OBJDIR)
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
ifeq ($(OS_TARGET),WIN16)
|
||||
echo system windows >w16link
|
||||
echo option map >>w16link
|
||||
echo option stack=10K >>w16link
|
||||
echo option heapsize=32K >>w16link
|
||||
echo debug $(DEBUGTYPE) all >>w16link
|
||||
echo name $@ >>w16link
|
||||
echo file >>w16link
|
||||
echo $< >>w16link
|
||||
echo library >>w16link
|
||||
echo $(LIBPR), >>w16link
|
||||
echo $(LIBPLC), >>w16link
|
||||
echo winsock.lib >>w16link
|
||||
wlink @w16link.
|
||||
else
|
||||
link $(LDOPTS) $< $(LIBPLC) $(LIBPLDS) $(LIBPR) wsock32.lib -out:$@
|
||||
endif
|
||||
else
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
$(LINK) $(EXEFLAGS) $(LDOPTS) $< $(LIBPLC) $(LIBPLDS) $(LIBPR) $(OS_LIBS) $(EXTRA_LIBS)
|
||||
else
|
||||
$(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBPLDS) $(LIBPR) $(EXTRA_LIBS) -o $@
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
export:: $(TARGETS)
|
||||
clean::
|
||||
rm -f $(TARGETS)
|
||||
|
||||
|
||||
|
401
libs/js/nsprpub/lib/tests/arena.c
Normal file
401
libs/js/nsprpub/lib/tests/arena.c
Normal file
@@ -0,0 +1,401 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1998-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
** File: arena.c
|
||||
** Description: Testing arenas
|
||||
**
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "nspr.h"
|
||||
#include "plarena.h"
|
||||
#include "plgetopt.h"
|
||||
|
||||
PRLogModuleInfo *tLM;
|
||||
PRIntn threadCount = 0;
|
||||
PRMonitor *tMon;
|
||||
PRBool failed_already = PR_FALSE;
|
||||
|
||||
/* Arguments from the command line with default values */
|
||||
PRIntn debug_mode = 0;
|
||||
PRIntn poolMin = 4096;
|
||||
PRIntn poolMax = (100 * 4096);
|
||||
PRIntn arenaMin = 40;
|
||||
PRIntn arenaMax = (100 * 40);
|
||||
PRIntn stressIterations = 15;
|
||||
PRIntn maxAlloc = (1024 * 1024);
|
||||
PRIntn stressThreads = 4;
|
||||
|
||||
void DumpAll( void )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Test Arena allocation.
|
||||
*/
|
||||
static void ArenaAllocate( void )
|
||||
{
|
||||
PLArenaPool ap;
|
||||
void *ptr;
|
||||
PRInt32 i;
|
||||
|
||||
PL_InitArenaPool( &ap, "AllocArena", 2048, sizeof(double));
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d",
|
||||
&ap, ap.first, ap.current, ap.arenasize ));
|
||||
|
||||
for( i = 0; i < 150; i++ )
|
||||
{
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
|
||||
&ap, ap.first, ap.current, ap.arenasize ));
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,(
|
||||
"AA -- Pool: %p. alloc: %p ", &ap, ptr ));
|
||||
}
|
||||
|
||||
PL_FreeArenaPool( &ap );
|
||||
|
||||
for( i = 0; i < 221; i++ )
|
||||
{
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
|
||||
&ap, ap.first, ap.current, ap.arenasize ));
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,(
|
||||
"AA -- Pool: %p. alloc: %p ", &ap, ptr ));
|
||||
}
|
||||
|
||||
PL_FreeArenaPool( &ap );
|
||||
|
||||
return;
|
||||
} /* end ArenaGrow() */
|
||||
/*
|
||||
** Test Arena grow.
|
||||
*/
|
||||
static void ArenaGrow( void )
|
||||
{
|
||||
PLArenaPool ap;
|
||||
void *ptr;
|
||||
PRInt32 i;
|
||||
|
||||
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
|
||||
|
||||
for( i = 0; i < 10; i++ )
|
||||
{
|
||||
PL_ARENA_GROW( ptr, &ap, 512, 7000 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
} /* end ArenaGrow() */
|
||||
|
||||
|
||||
/*
|
||||
** Test arena Mark and Release.
|
||||
*/
|
||||
static void MarkAndRelease( void )
|
||||
{
|
||||
PLArenaPool ap;
|
||||
void *ptr = NULL;
|
||||
void *mark0, *mark1;
|
||||
PRIntn i;
|
||||
|
||||
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
|
||||
mark0 = PL_ARENA_MARK( &ap );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
|
||||
|
||||
for( i = 0; i < 201; i++ )
|
||||
{
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
}
|
||||
|
||||
mark1 = PL_ARENA_MARK( &ap );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
|
||||
|
||||
|
||||
for( i = 0; i < 225; i++ )
|
||||
{
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
}
|
||||
|
||||
PL_ARENA_RELEASE( &ap, mark1 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
|
||||
mark1, &ap, ap.first, ap.current, ap.arenasize ));
|
||||
|
||||
for( i = 0; i < 20; i++ )
|
||||
{
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
}
|
||||
|
||||
PL_ARENA_RELEASE( &ap, mark1 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
|
||||
PL_ARENA_RELEASE( &ap, mark0 );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
|
||||
PL_FreeArenaPool( &ap );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
|
||||
PL_FinishArenaPool( &ap );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG,
|
||||
("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
|
||||
&ap, ap.first.next, ap.current, ap.arenasize, ptr ));
|
||||
|
||||
return;
|
||||
} /* end MarkAndRelease() */
|
||||
|
||||
/*
|
||||
** RandSize() returns a random number in the range
|
||||
** min..max, rounded to the next doubleword
|
||||
**
|
||||
*/
|
||||
static PRIntn RandSize( PRIntn min, PRIntn max )
|
||||
{
|
||||
PRIntn sz = (rand() % (max -min)) + min + sizeof(double);
|
||||
|
||||
sz &= ~sizeof(double)-1;
|
||||
|
||||
return(sz);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** StressThread()
|
||||
** A bunch of these beat on individual arenas
|
||||
** This tests the free_list protection.
|
||||
**
|
||||
*/
|
||||
static void PR_CALLBACK StressThread( void *arg )
|
||||
{
|
||||
PLArenaPool ap;
|
||||
PRIntn i;
|
||||
PRIntn sz;
|
||||
void *ptr;
|
||||
PRThread *tp = PR_GetCurrentThread();
|
||||
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("Stress Thread %p started\n", PR_GetCurrentThread()));
|
||||
PL_InitArenaPool( &ap, "TheArena", RandSize( poolMin, poolMax), sizeof(double));
|
||||
|
||||
for ( i = 0; i < stressIterations; i++ )
|
||||
{
|
||||
PRIntn allocated = 0;
|
||||
|
||||
while ( allocated < maxAlloc )
|
||||
{
|
||||
sz = RandSize( arenaMin, arenaMax );
|
||||
PL_ARENA_ALLOCATE( ptr, &ap, sz );
|
||||
if ( ptr == NULL )
|
||||
{
|
||||
PR_LOG( tLM, PR_LOG_ERROR, ("ARENA_ALLOCATE() returned NULL\n\tAllocated: %d\n", allocated));
|
||||
break;
|
||||
}
|
||||
allocated += sz;
|
||||
}
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished one iteration\n", tp));
|
||||
PL_FreeArenaPool( &ap );
|
||||
}
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished all iteration\n", tp));
|
||||
PL_FinishArenaPool( &ap );
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p after FinishArenaPool()\n", tp));
|
||||
|
||||
/* That's all folks! let's quit */
|
||||
PR_EnterMonitor(tMon);
|
||||
threadCount--;
|
||||
PR_Notify(tMon);
|
||||
PR_ExitMonitor(tMon);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Stress()
|
||||
** Flog the hell out of arenas multi-threaded.
|
||||
** Do NOT pass an individual arena to another thread.
|
||||
**
|
||||
*/
|
||||
static void Stress( void )
|
||||
{
|
||||
PRThread *tt;
|
||||
PRIntn i;
|
||||
|
||||
tMon = PR_NewMonitor();
|
||||
|
||||
for ( i = 0 ; i < stressThreads ; i++ )
|
||||
{
|
||||
PR_EnterMonitor(tMon);
|
||||
tt = PR_CreateThread(PR_USER_THREAD,
|
||||
StressThread,
|
||||
NULL,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
threadCount++;
|
||||
PR_ExitMonitor(tMon);
|
||||
}
|
||||
|
||||
/* Wait for all threads to exit */
|
||||
PR_EnterMonitor(tMon);
|
||||
while ( threadCount != 0 )
|
||||
{
|
||||
PR_Wait(tMon, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
PR_ExitMonitor(tMon);
|
||||
PR_DestroyMonitor(tMon);
|
||||
|
||||
return;
|
||||
} /* end Stress() */
|
||||
|
||||
/*
|
||||
** EvaluateResults()
|
||||
** uses failed_already to display results and set program
|
||||
** exit code.
|
||||
*/
|
||||
static PRIntn EvaluateResults(void)
|
||||
{
|
||||
PRIntn rc = 0;
|
||||
|
||||
if ( failed_already == PR_TRUE )
|
||||
{
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("FAIL\n"));
|
||||
rc =1;
|
||||
}
|
||||
else
|
||||
{
|
||||
PR_LOG( tLM, PR_LOG_DEBUG, ("PASS\n"));
|
||||
}
|
||||
return(rc);
|
||||
} /* EvaluateResults() */
|
||||
|
||||
void Help( void )
|
||||
{
|
||||
printf("arena [options]\n");
|
||||
printf("where options are:\n");
|
||||
printf("-p <n> minimum size of an arena pool. Default(%d)\n", poolMin);
|
||||
printf("-P <n> maximum size of an arena pool. Default(%d)\n", poolMax);
|
||||
printf("-a <n> minimum size of an arena allocation. Default(%d)\n", arenaMin);
|
||||
printf("-A <n> maximum size of an arena allocation. Default(%d)\n", arenaMax);
|
||||
printf("-i <n> number of iterations in a stress thread. Default(%d)\n", stressIterations);
|
||||
printf("-s <n> maximum allocation for a single stress thread. Default(%d)\n", maxAlloc);
|
||||
printf("-t <n> number of stress threads. Default(%d)\n", stressThreads );
|
||||
printf("-d enable debug mode\n");
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
PRIntn main(PRIntn argc, char *argv[])
|
||||
{
|
||||
PLOptStatus os;
|
||||
PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
|
||||
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
|
||||
{
|
||||
if (PL_OPT_BAD == os) continue;
|
||||
switch (opt->option)
|
||||
{
|
||||
case 'a': /* arena Min size */
|
||||
arenaMin = atol( opt->value );
|
||||
break;
|
||||
case 'A': /* arena Max size */
|
||||
arenaMax = atol( opt->value );
|
||||
break;
|
||||
case 'p': /* pool Min size */
|
||||
poolMin = atol( opt->value );
|
||||
break;
|
||||
case 'P': /* pool Max size */
|
||||
poolMax = atol( opt->value );
|
||||
break;
|
||||
case 'i': /* Iterations in stress tests */
|
||||
stressIterations = atol( opt->value );
|
||||
break;
|
||||
case 's': /* storage to get per iteration */
|
||||
maxAlloc = atol( opt->value );
|
||||
break;
|
||||
case 't': /* Number of stress threads to create */
|
||||
stressThreads = atol( opt->value );
|
||||
break;
|
||||
case 'd': /* debug mode */
|
||||
debug_mode = 1;
|
||||
break;
|
||||
case 'h': /* help */
|
||||
default:
|
||||
Help();
|
||||
} /* end switch() */
|
||||
} /* end while() */
|
||||
PL_DestroyOptState(opt);
|
||||
|
||||
srand( (unsigned)time( NULL ) ); /* seed random number generator */
|
||||
tLM = PR_NewLogModule("testcase");
|
||||
|
||||
|
||||
#if 0
|
||||
ArenaAllocate();
|
||||
ArenaGrow();
|
||||
#endif
|
||||
|
||||
MarkAndRelease();
|
||||
|
||||
Stress();
|
||||
|
||||
return(EvaluateResults());
|
||||
} /* end main() */
|
||||
|
||||
/* arena.c */
|
3047
libs/js/nsprpub/lib/tests/base64t.c
Normal file
3047
libs/js/nsprpub/lib/tests/base64t.c
Normal file
File diff suppressed because it is too large
Load Diff
3116
libs/js/nsprpub/lib/tests/string.c
Normal file
3116
libs/js/nsprpub/lib/tests/string.c
Normal file
File diff suppressed because it is too large
Load Diff
4
libs/js/nsprpub/lib/tests/windows/CVS/Entries
Normal file
4
libs/js/nsprpub/lib/tests/windows/CVS/Entries
Normal file
@@ -0,0 +1,4 @@
|
||||
/makefile/1.9/Wed Nov 23 06:35:20 2005//
|
||||
/readme.1st/1.1/Tue Feb 23 23:09:10 1999//
|
||||
/winevent.c/1.6/Sun Apr 25 15:00:46 2004//
|
||||
D
|
1
libs/js/nsprpub/lib/tests/windows/CVS/Repository
Normal file
1
libs/js/nsprpub/lib/tests/windows/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
mozilla/nsprpub/lib/tests/windows
|
1
libs/js/nsprpub/lib/tests/windows/CVS/Root
Normal file
1
libs/js/nsprpub/lib/tests/windows/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
|
84
libs/js/nsprpub/lib/tests/windows/makefile
Normal file
84
libs/js/nsprpub/lib/tests/windows/makefile
Normal file
@@ -0,0 +1,84 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1998-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#! gmake
|
||||
|
||||
|
||||
|
||||
MOD_DEPTH = ../../..
|
||||
|
||||
include $(MOD_DEPTH)/config/config.mk
|
||||
|
||||
INCLUDES = -I$(DIST)/include
|
||||
|
||||
CSRCS = winevent.c
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
ifeq ($(OS_TARGET), WIN16)
|
||||
LIBPR = $(DIST)/lib/nspr$(MOD_VERSION).lib
|
||||
LIBPLC= $(DIST)/lib/plc$(MOD_VERSION).lib
|
||||
LIBPLDS= $(DIST)/lib/plds$(MOD_VERSION).lib
|
||||
else
|
||||
LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
|
||||
ifeq ($(OS_TARGET), WIN95)
|
||||
LIBPR = $(DIST)/lib/nspr$(MOD_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLC= $(DIST)/lib/plc$(MOD_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLDS= $(DIST)/lib/plds$(MOD_VERSION).lib
|
||||
else
|
||||
LIBPR = $(DIST)/lib/libnspr$(MOD_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLC= $(DIST)/lib/libplc$(MOD_VERSION).$(LIB_SUFFIX)
|
||||
LIBPLDS= $(DIST)/lib/libplds$(MOD_VERSION).lib
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
TARGETS = $(OBJDIR)/winevent.exe
|
||||
OS_CFLAGS = $(OS_EXE_CFLAGS)
|
||||
LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
|
||||
LDFLAGS += -DEBUG
|
||||
LIBPR += $(LIBPLDS)
|
||||
LIBPR += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
|
||||
|
||||
include $(MOD_DEPTH)/config/rules.mk
|
||||
|
||||
$(OBJDIR)/winevent.exe: $(OBJS)
|
||||
link $(LDOPTS) $< $(LIBPLC) $(LIBPR) wsock32.lib -out:$@
|
||||
|
||||
export:: $(TARGETS)
|
||||
|
||||
clean::
|
||||
rm -rf $(TARGETS)
|
37
libs/js/nsprpub/lib/tests/windows/readme.1st
Normal file
37
libs/js/nsprpub/lib/tests/windows/readme.1st
Normal file
@@ -0,0 +1,37 @@
|
||||
readme.1st.
|
||||
|
||||
The files in the lib/tests/WinGUI directory are taken
|
||||
from "Programming Windows 3.1" by Charles Petzold,
|
||||
specifically, the programs in chapter 14 related
|
||||
to the "poppad4" sample application.
|
||||
|
||||
These programs are compiled with nspr20 to test nspr 2.0
|
||||
and to demostrate the use of nspr in a gui application.
|
||||
|
||||
Library (DLL) PLDSxx.lib PLDSxx.dll is required to be
|
||||
linked with this test case. Functions in this dll are
|
||||
in the source ns/nspr20/lib/ds/plevent.* files.
|
||||
|
||||
Permission to use.
|
||||
|
||||
The source for poppad.c are used under license from
|
||||
Petzold. The license to use is stated in the book.
|
||||
The following paragraph of the license grants that
|
||||
use.
|
||||
|
||||
5. SAMPLE CODE. If the SOFTWARE includes Sample Code, then
|
||||
Microsoft grants you a royalty-free right to reproduce and
|
||||
distribute the sample code of the SOFTWARE provided that you:
|
||||
(a) distribute the sample code only in conjunction with and
|
||||
as part of your software product; (b) do not use Microsoft's
|
||||
or its authors' names, logos, or trademarks to market your
|
||||
software product; (c) include the copyright notice that appears
|
||||
on the SOFTWARE on your product label and as a part of the
|
||||
sign-on message for your software product; and (d) agree to
|
||||
idemnify, hold harmless, and defend Microsoft and its authors
|
||||
from and against any claims or lawsuits, including attorneys'
|
||||
fees, that arise or result from the use or distribution of
|
||||
your software product.
|
||||
|
||||
lth. 9/24/97.
|
||||
|
348
libs/js/nsprpub/lib/tests/windows/winevent.c
Normal file
348
libs/js/nsprpub/lib/tests/windows/winevent.c
Normal file
@@ -0,0 +1,348 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1998-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
** File: winevent.c
|
||||
** Description: Test functions in plevent.c using Windows
|
||||
**
|
||||
** The winevent test exercises the PLEvent library in a maner
|
||||
** similar to how the Mozilla (or NGLayout) Client will use
|
||||
** it in a Windows environment.
|
||||
**
|
||||
** This test is based on ideas taken from Charles Petzold's
|
||||
** book "Programming Windows 3.1". License to use is in the
|
||||
** book. It has been ported to Win32.
|
||||
**
|
||||
** Operation:
|
||||
** The initialization is a standard Windows GUI application
|
||||
** setup. When the main window receives its WM_CREATE
|
||||
** message, a child window is created, a edit control is
|
||||
** instantiated in that window.
|
||||
**
|
||||
** A thread is created; this thread runs in the function:
|
||||
** TimerThread(). The new thread sends a message every second
|
||||
** via the PL_PostEvent() function. The event handler
|
||||
** HandlePadEvent() sends a windows message to the edit
|
||||
** control window; these messages are WM_CHAR messages that
|
||||
** cause the edit control to place a single '.' character in
|
||||
** the edit control.
|
||||
**
|
||||
** After a deterministic number of '.' characters, the
|
||||
** TimerThread() function is notified via a global variable
|
||||
** that it's quitting time.
|
||||
**
|
||||
** TimerThread() callse TestEvents(), an external function
|
||||
** that tests additional function of PLEvent.
|
||||
**
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "plevent.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
|
||||
#define ID_EDIT 1
|
||||
|
||||
/*
|
||||
** Declarations for NSPR customization
|
||||
**
|
||||
*/
|
||||
typedef struct PadEvent
|
||||
{
|
||||
PLEvent plEvent;
|
||||
int unused;
|
||||
} PadEvent;
|
||||
|
||||
static void PR_CALLBACK TimerThread( void *arg);
|
||||
static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent );
|
||||
static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent );
|
||||
|
||||
static PRThread *tThread;
|
||||
static PLEventQueue *padQueue;
|
||||
static long ThreadSleepTime = 1000; /* in milli-seconds */
|
||||
static long timerCount = 0;
|
||||
static HWND hDlgModeless ;
|
||||
static HWND hwndEdit ;
|
||||
static PRBool testFinished = PR_FALSE;
|
||||
static HWND hwnd ;
|
||||
|
||||
LRESULT CALLBACK WinProc (HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
TCHAR appName[] = TEXT ("WinEvent") ;
|
||||
|
||||
int WINAPI WinMain(
|
||||
HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
PSTR szCmdLine,
|
||||
int iCmdShow
|
||||
)
|
||||
{
|
||||
MSG msg ;
|
||||
WNDCLASS wndclass ;
|
||||
HANDLE hAccel ;
|
||||
|
||||
PR_Init(0, 0, 0);
|
||||
|
||||
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wndclass.lpfnWndProc = WinProc;
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = 0;
|
||||
wndclass.hInstance = hInstance;
|
||||
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
|
||||
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
|
||||
wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
|
||||
wndclass.lpszMenuName = NULL;
|
||||
wndclass.lpszClassName = appName;
|
||||
|
||||
if ( !RegisterClass( &wndclass ))
|
||||
{
|
||||
MessageBox( NULL,
|
||||
TEXT( "This program needs Win32" ),
|
||||
appName,
|
||||
MB_ICONERROR );
|
||||
return 0;
|
||||
}
|
||||
|
||||
hwnd = CreateWindow( appName,
|
||||
appName,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL);
|
||||
|
||||
ShowWindow( hwnd, iCmdShow );
|
||||
UpdateWindow( hwnd );
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ))
|
||||
{
|
||||
if ( GetMessage( &msg, NULL, 0, 0 ))
|
||||
{
|
||||
if ( hDlgModeless == NULL || !IsDialogMessage( hDlgModeless, &msg ))
|
||||
{
|
||||
if ( !TranslateAccelerator( hwnd, hAccel, &msg ))
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
} /* end if !TranslateAccelerator */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
} /* end if GetMessage() */
|
||||
}
|
||||
else /* !PeekMessage */
|
||||
{
|
||||
PR_Sleep(50);
|
||||
}/* end if PeekMessage() */
|
||||
} /* end for() */
|
||||
|
||||
PR_JoinThread( tThread );
|
||||
PL_DestroyEventQueue( padQueue );
|
||||
PR_Cleanup();
|
||||
return msg.wParam ;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WinProc(
|
||||
HWND hwnd,
|
||||
UINT message,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam
|
||||
)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_CREATE :
|
||||
hwndEdit = CreateWindow(
|
||||
TEXT( "edit" ),
|
||||
NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
|
||||
WS_BORDER | ES_LEFT | ES_MULTILINE |
|
||||
ES_AUTOHSCROLL | ES_AUTOVSCROLL,
|
||||
0, 0, 0, 0,
|
||||
hwnd,
|
||||
(HMENU)ID_EDIT,
|
||||
((LPCREATESTRUCT)lParam)->hInstance,
|
||||
NULL);
|
||||
|
||||
/* Initialize Event Processing for NSPR
|
||||
** Retrieve the event queue just created
|
||||
** Create the TimerThread
|
||||
*/
|
||||
|
||||
/*
|
||||
PL_InitializeEventsLib( "someName" );
|
||||
padQueue = PL_GetMainEventQueue();
|
||||
*/
|
||||
padQueue = PL_CreateEventQueue("MainQueue", PR_GetCurrentThread());
|
||||
PR_ASSERT( padQueue != NULL );
|
||||
tThread = PR_CreateThread( PR_USER_THREAD,
|
||||
TimerThread,
|
||||
NULL,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_LOCAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0 );
|
||||
return 0 ;
|
||||
|
||||
case WM_SETFOCUS :
|
||||
SetFocus( hwndEdit );
|
||||
return 0;
|
||||
|
||||
case WM_SIZE :
|
||||
MoveWindow( hwndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE );
|
||||
return 0 ;
|
||||
|
||||
case WM_COMMAND :
|
||||
if ( LOWORD(wParam) == ID_EDIT )
|
||||
if ( HIWORD(wParam ) == EN_ERRSPACE ||
|
||||
HIWORD( wParam ) == EN_MAXTEXT )
|
||||
|
||||
MessageBox( hwnd, TEXT( "Edit control out of space." ),
|
||||
appName, MB_OK | MB_ICONSTOP );
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY :
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProc( hwnd, message, wParam, lParam );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** TimerThread() -- The Main function of the timer pop thread
|
||||
**
|
||||
*/
|
||||
static void PR_CALLBACK TimerThread( void *arg )
|
||||
{
|
||||
PRIntn rc;
|
||||
|
||||
do {
|
||||
PadEvent *ev;
|
||||
|
||||
/*
|
||||
** Create and Post the event the event
|
||||
*/
|
||||
PL_ENTER_EVENT_QUEUE_MONITOR( padQueue );
|
||||
ev = (PadEvent *) PR_NEW( PadEvent );
|
||||
PL_InitEvent( &ev->plEvent, NULL,
|
||||
(PLHandleEventProc)HandlePadEvent,
|
||||
(PLDestroyEventProc)DestroyPadEvent );
|
||||
PL_PostEvent( padQueue, &ev->plEvent );
|
||||
PL_EXIT_EVENT_QUEUE_MONITOR( padQueue );
|
||||
|
||||
PR_Sleep( PR_MillisecondsToInterval(ThreadSleepTime) );
|
||||
} while( testFinished == PR_FALSE );
|
||||
|
||||
PR_Sleep( PR_SecondsToInterval(4) );
|
||||
|
||||
/*
|
||||
** All done now. This thread can kill the main thread by sending
|
||||
** WM_DESTROY message to the main window.
|
||||
*/
|
||||
SendMessage( hwnd, WM_DESTROY, 0, 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
static char *startMessage = "Poppad: NSPR Windows GUI and event test program.\n"
|
||||
"Every 1 second gets a '.'.\n"
|
||||
"The test self terminates in less than a minute\n"
|
||||
"You should be able to type in the window.\n\n";
|
||||
|
||||
static char *stopMessage = "\n\nIf you saw a series of dots being emitted in the window\n"
|
||||
" at one second intervals, the test worked.\n\n";
|
||||
|
||||
/*
|
||||
** HandlePadEvent() -- gets called because of PostEvent
|
||||
*/
|
||||
static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent )
|
||||
{
|
||||
char *cp;
|
||||
static const long lineLimit = 10; /* limit on number of '.' per line */
|
||||
static const long timerLimit = 25; /* limit on timer pop iterations */
|
||||
|
||||
if ( timerCount++ == 0 )
|
||||
{
|
||||
|
||||
for ( cp = startMessage; *cp != 0 ; cp++ )
|
||||
{
|
||||
SendMessage( hwndEdit, WM_CHAR, *cp, 1 );
|
||||
}
|
||||
}
|
||||
/*
|
||||
** Send a WM_CHAR event the edit Window
|
||||
*/
|
||||
SendMessage( hwndEdit, WM_CHAR, '.', 1 );
|
||||
|
||||
/*
|
||||
** Limit the number of characters sent via timer pop to lineLimit
|
||||
*/
|
||||
if ( (timerCount % lineLimit) == 0)
|
||||
{
|
||||
SendMessage( hwndEdit, WM_CHAR, '\n', 1 );
|
||||
}
|
||||
|
||||
if ( timerCount >= timerLimit )
|
||||
{
|
||||
for ( cp = stopMessage; *cp != 0 ; cp++ )
|
||||
{
|
||||
SendMessage( hwndEdit, WM_CHAR, *cp, 1 );
|
||||
}
|
||||
testFinished = PR_TRUE;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** DestroyPadEvent() -- Called after HandlePadEvent()
|
||||
*/
|
||||
static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent )
|
||||
{
|
||||
PR_Free( padevent );
|
||||
return;
|
||||
}
|
Reference in New Issue
Block a user