From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- src/libs/xpcom18a4/xpcom/tests/windows/.cvsignore | 1 + src/libs/xpcom18a4/xpcom/tests/windows/Makefile.in | 60 + src/libs/xpcom18a4/xpcom/tests/windows/TestCOM.cpp | 181 ++ .../xpcom/tests/windows/TestHelloXPLoop.cpp | 177 ++ .../xpcom18a4/xpcom/tests/windows/nsStringTest.cpp | 33 + .../xpcom18a4/xpcom/tests/windows/nsStringTest.h | 2277 ++++++++++++++++++++ .../xpcom18a4/xpcom/tests/windows/nsStringTest2.h | 444 ++++ 7 files changed, 3173 insertions(+) create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/.cvsignore create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/Makefile.in create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/TestCOM.cpp create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/TestHelloXPLoop.cpp create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.cpp create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.h create mode 100644 src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest2.h (limited to 'src/libs/xpcom18a4/xpcom/tests/windows') diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/.cvsignore b/src/libs/xpcom18a4/xpcom/tests/windows/.cvsignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/Makefile.in b/src/libs/xpcom18a4/xpcom/tests/windows/Makefile.in new file mode 100644 index 00000000..8bd782c8 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/Makefile.in @@ -0,0 +1,60 @@ +# +# ***** 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 2001 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = xpcom + +REQUIRES = string + +CPPSRCS = TestCOM.cpp +#TestHelloXPLoop.cpp nsStringTest.cpp + +SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX)) + +include $(topsrcdir)/config/config.mk + +include $(topsrcdir)/config/rules.mk + +OS_LIBS = $(call EXPAND_LIBNAME,rpcrt4 uuid) + +LIBS = $(XPCOM_LIBS) $(NSPR_LIBS) diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/TestCOM.cpp b/src/libs/xpcom18a4/xpcom/tests/windows/TestCOM.cpp new file mode 100644 index 00000000..b76eccb4 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/TestCOM.cpp @@ -0,0 +1,181 @@ +/* -*- 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Pierre Phaneuf + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 ***** */ + +#include +#include +#include +#include "nsISupports.h" +#include "nsIFactory.h" + +// unknwn.h is needed to build with WIN32_LEAN_AND_MEAN +#include + +// {5846BA30-B856-11d1-A98A-00805F8A7AC4} +#define NS_ITEST_COM_IID \ +{ 0x5846ba30, 0xb856, 0x11d1, \ + { 0xa9, 0x8a, 0x0, 0x80, 0x5f, 0x8a, 0x7a, 0xc4 } } + +class nsITestCom: public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITEST_COM_IID) + NS_IMETHOD Test() = 0; +}; + +/* + * nsTestCom + */ + +class nsTestCom: public nsITestCom { + NS_DECL_ISUPPORTS + +public: + nsTestCom() { + } + + NS_IMETHOD Test() { + printf("Accessed nsITestCom::Test() from COM\n"); + return NS_OK; + } + +private: + ~nsTestCom() { + printf("nsTestCom instance successfully deleted\n"); + } +}; + +NS_IMPL_QUERY_INTERFACE1(nsTestCom, nsITestCom) + +nsrefcnt nsTestCom::AddRef() +{ + nsrefcnt res = ++mRefCnt; + NS_LOG_ADDREF(this, mRefCnt, "nsTestCom", sizeof(*this)); + printf("nsTestCom: Adding ref = %d\n", res); + return res; +} + +nsrefcnt nsTestCom::Release() +{ + nsrefcnt res = --mRefCnt; + NS_LOG_RELEASE(this, mRefCnt, "nsTestCom"); + printf("nsTestCom: Releasing = %d\n", res); + if (res == 0) { + delete this; + } + return res; +} + +class nsTestComFactory: public nsIFactory { + NS_DECL_ISUPPORTS +public: + nsTestComFactory() { + } + + NS_IMETHOD CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock) { + printf("nsTestComFactory: "); + printf("%s", (aLock == PR_TRUE ? "Locking server" : "Unlocking server")); + printf("\n"); + return S_OK; + } +}; + +NS_IMPL_ISUPPORTS1(nsTestComFactory, nsIFactory) + +nsresult nsTestComFactory::CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult) +{ + if (aOuter != NULL) { + return NS_ERROR_NO_AGGREGATION; + } + + nsTestCom *t = new nsTestCom(); + + if (t == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(t); + nsresult res = t->QueryInterface(aIID, aResult); + NS_RELEASE(t); + + if (NS_SUCCEEDED(res)) { + printf("nsTestComFactory: successfully created nsTestCom instance\n"); + } + + return res; +} + +/* + * main + */ + +int main(int argc, char *argv[]) +{ + nsTestComFactory *inst = new nsTestComFactory(); + IClassFactory *iFactory; + inst->QueryInterface(NS_GET_IID(nsIFactory), (void **) &iFactory); + + IUnknown *iUnknown; + nsITestCom *iTestCom; + + nsresult res; + iFactory->LockServer(TRUE); + res = iFactory->CreateInstance(NULL, + IID_IUnknown, + (void **) &iUnknown); + iFactory->LockServer(FALSE); + + GUID testGUID = NS_ITEST_COM_IID; + HRESULT hres; + hres= iUnknown->QueryInterface(testGUID, + (void **) &iTestCom); + + iTestCom->Test(); + + iUnknown->Release(); + iTestCom->Release(); + iFactory->Release(); + + return 0; +} + diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/TestHelloXPLoop.cpp b/src/libs/xpcom18a4/xpcom/tests/windows/TestHelloXPLoop.cpp new file mode 100644 index 00000000..fdfa1218 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/TestHelloXPLoop.cpp @@ -0,0 +1,177 @@ +/* -*- 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 Mozilla browser. + * + * The Initial Developer of the Original Code is + * Netscape Communications, Inc. + * Portions created by the Initial Developer are Copyright (C) 1999 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 ***** */ + +#include "nsIServiceManager.h" +#include "nsCOMPtr.h" +#include "nsCNativeApp.h" +#include "nsIEventLoop.h" +#include + +static NS_DEFINE_CID(kNativeAppCID, NS_NATIVE_APP_CID); + +LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); + +void ErrorBox(LPSTR text) +{ + MessageBox(NULL, text, "XP Event Loop", MB_OK | MB_ICONSTOP); +} + +void InfoBox(LPSTR text) +{ + MessageBox(NULL, text, "XP Event Loop", MB_OK | MB_ICONINFORMATION); +} + +int WINAPI WinMain(HINSTANCE inst, + HINSTANCE prevInstance, + LPSTR lpszCmdLine, + int nShowCmd) +{ + char* lpszAppName = "HelloWorld"; + HWND wnd; + WNDCLASSEX wndclass; + int retCode; + + { // Needed to scope all nsCOMPtr within XPCOM Init and Shutdown + nsresult rv; + nsCOMPtr servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if(NS_FAILED(rv)) + { + ErrorBox("Failed to initalize xpcom."); + return -1; + } + + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + registrar->AutoRegister(nsnull); + + nsCOMPtr nativeAppService(do_GetService(kNativeAppCID, &rv)); + + if(NS_FAILED(rv)) + { + ErrorBox("Failed to get nativeAppService"); + return -1; + } + wndclass.cbSize = sizeof(wndclass); + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = inst; + wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = lpszAppName; + wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + RegisterClassEx(&wndclass) ; + + wnd = CreateWindow(lpszAppName, "The Hello World", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, inst, NULL); + + ShowWindow(wnd, nShowCmd); + UpdateWindow(wnd); + + nsCOMPtr eventLoop; + + if(NS_FAILED(nativeAppService->CreateEventLoop(L"_MainLoop", + nsEventLoopTypes::MainAppLoop, getter_AddRefs(eventLoop)))) + { + ErrorBox("Failed to create event Loop"); + return 0; + } + + eventLoop->Run(nsnull, nsnull, nsnull, &retCode); + eventLoop = nsnull; // Clear out before Shutting down XPCOM + + InfoBox("Hello World app is out of loop"); + } + NS_ShutdownXPCOM(nsnull); + InfoBox("Hello World app is exiting"); + return retCode; +} + +LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HDC hdc; + PAINTSTRUCT ps; + RECT rect; + + switch(msg) + { + case WM_PAINT: + hdc = BeginPaint(wnd, &ps); + + GetClientRect(wnd, &rect); + + DrawText(hdc, "Hello, XP Event Loop!", -1, &rect, + DT_SINGLELINE | DT_CENTER | DT_VCENTER); + + EndPaint(wnd, &ps); + return 0; + + case WM_DESTROY: + { + nsresult rv; + nsCOMPtr nativeAppService = + do_GetService(kNativeAppCID, &rv); + if(NS_FAILED(rv)) + { + ErrorBox("Could not get NativeAppService"); + return 0; + } + nsCOMPtr eventLoop; + + if(NS_FAILED(nativeAppService->FindEventLoop(L"_MainLoop", + getter_AddRefs(eventLoop)))) + { + ErrorBox("Failed to find event Loop"); + return 0; + } + eventLoop->Exit(0); + } + return 0; + } + + return DefWindowProc(wnd, msg, wParam, lParam); +} diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.cpp b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.cpp new file mode 100644 index 00000000..6719ed38 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.cpp @@ -0,0 +1,33 @@ + +#include +#include "nsStr.h" +#include "nsStringTest2.h" +#include "nsString.h" +#include "nsReadableUtils.h" + +int main(){ + + nsString temp("\t\t\n\r\n\r25,* \t \n\n \t"); + temp.CompressWhitespace(); + + nsString temp1("\t\t\n\r\n\r25,* \t \n\n \t"); + temp1.CompressSet("\t\n\r ",' ',false,false); + + nsString temp3(""); + char* s = ToNewCString(temp3); + delete s; + + char* f = ToNewCString(nsAutoString("")); + char* f1 = ToNewCString(nsCAutoString("")); + delete f; + delete f1; + + + CStringTester gStringTester; + + gStringTester.TestI18nString(); + + return 0; +} + + diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.h b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.h new file mode 100644 index 00000000..8244a5a1 --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest.h @@ -0,0 +1,2277 @@ +/******************************************************************************************** + * + * MODULES NOTES: + * + * This file is designed to help test the new nsString classes. + * + * Contributor(s): + * Rick Gessner + * + * History: + * + * 02.29.2000: Original files (rickg) + * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) + * + ********************************************************************************************/ + +#ifndef _STRINGTEST +#define _STRINGTEST + + +#include "nsString.h" +#include "nsReadableUtils.h" +#include + +#define USE_STL + +#ifdef USE_STL +#include +using namespace std; +#endif + +#define USE_WIDE 1 +#ifdef USE_WIDE + #define stringtype nsString + #define astringtype nsAutoString + #define chartype PRUnichar +#else + #define stringtype nsCString + #define astringtype nsCAutoString + #define chartype char +#endif + + +#include + + + +static const char* kConstructorError = "constructor error"; +static const char* kComparisonError = "Comparision error!"; +static const char* kEqualsError = "Equals error!"; + +static char* kNumbers[]={"0123456789","0\01\02\03\04\05\06\07\08\09\0\0\0"}; +static char* kLetters[]={"abcdefghij","a\0b\0c\0d\0e\0f\0g\0h\0i\0j\0\0\0"}; +static char* kAAA[]={"AAA","A\0A\0A\0\0\0"}; +static char* kBBB[]={"BBB","B\0B\0B\0\0\0"}; +static char* kHello[]={"hello","h\0e\0l\0l\0o\0\0\0"}; +static char* kWSHello[]={" hello "," \0 \0h\0e\0l\0l\0o\0 \0 \0\0\0"}; + + + +/******************************************************** + + This class's only purpose in life is to test the + netscape string library. We exercise the string + API's here, and do a bit of performance testing + against the standard c++ library string (from STL). + + ********************************************************/ +class CStringTester { +public: + CStringTester() { + TestConstructors(); + TestAutoStrings(); + TestAppend(); + TestAssignAndAdd(); + TestInsert(); + TestDelete(); + TestTruncate(); + TestLogical(); + TestLexomorphic(); + TestCreators(); + TestNumerics(); + TestExtractors(); + TestSearching(); + TestSubsumables(); + TestRandomOps(); + TestReplace(); + TestRegressions(); + TestStringPerformance(); + TestWideStringPerformance(); + } +protected: + int TestConstructors(); + int TestLogical(); + int TestAutoStrings(); + int TestAppend(); + int TestAssignAndAdd(); + int TestInsert(); + int TestDelete(); + int TestTruncate(); + int TestLexomorphic(); + int TestCreators(); + int TestNumerics(); + int TestExtractors(); + int TestSearching(); + int TestSubsumables(); + int TestRandomOps(); + int TestReplace(); + int TestStringPerformance(); + int TestWideStringPerformance(); + int TestRegressions(); +}; + + +class Stopwatch { +public: + Stopwatch() { + start=clock(); + } + + void Stop() { + stop=clock(); + } + + double Elapsed() { + return (double)(stop - start) / CLOCKS_PER_SEC; + } + + void Print(const char* msg= "") { + printf("%s %f\n",msg,Elapsed()); + } + + clock_t start,stop; +}; + +/** + * + * @update gess10/30/98 + * @param + * @return + */ +int CStringTester::TestSearching(){ + int result=0; + + + + PRUnichar pbuf[10]={'e','f','g',0}; + PRUnichar pbuf2[10]={'a','b','c',0}; + + + //Since there is so much ground to cover with searching, we use a typedef to + //allow you to vary the string type being searched... + + + stringtype theDest("abcdefghijkabc"); + nsString s1("ijk"); + nsCString c1("ijk"); + + PRInt32 pos=theDest.Find(pbuf); + NS_ASSERTION(pos==4,"Error: Find routine"); + + pos=theDest.Find(pbuf2,PR_FALSE,-1); + NS_ASSERTION(pos==0,"Error: Find routine"); + + pos=theDest.Find(pbuf2,PR_FALSE,pos+1); + NS_ASSERTION(pos==11,"Error: Find routine"); + + pos=theDest.FindChar('a'); + NS_ASSERTION(pos==0,"Error: Find routine"); + + pos=theDest.FindChar('a',PR_FALSE,pos+1); + NS_ASSERTION(pos==11,"Error: Find routine"); + + pos=theDest.Find("efg"); + NS_ASSERTION(pos==4,"Error: Find routine"); + + pos=theDest.Find("EFG",PR_TRUE); + NS_ASSERTION(pos==4,"Error: Find routine"); + + pos=theDest.FindChar('d'); + NS_ASSERTION(pos==3,"Error: Find char routine"); + + pos=theDest.Find(s1); + NS_ASSERTION(pos==8,"Error: Find char routine"); + + pos=theDest.FindCharInSet("12k"); + NS_ASSERTION(pos==10,"Error: Findcharinset routine"); + + pos=theDest.FindCharInSet(pbuf); + NS_ASSERTION(pos==4,"Error: Findcharinset routine"); + + pos=theDest.FindCharInSet(s1); + NS_ASSERTION(pos==8,"Error: Findcharinset routine"); + + pos=theDest.Find("efg",PR_FALSE,2); + NS_ASSERTION(pos==4,"Error: Find routine"); + + pos=theDest.RFindCharInSet("12k"); + NS_ASSERTION(pos==10,"Error: RFindcharinset routine"); + + pos=theDest.RFindCharInSet("xyz"); + NS_ASSERTION(pos==-1,"Error: RFindcharinset routine"); + + pos=theDest.RFindCharInSet(pbuf); + NS_ASSERTION(pos==6,"Error: RFindcharinset routine"); + + pos=theDest.RFindCharInSet(s1); + NS_ASSERTION(pos==10,"Error: RFindcharinset routine"); + + pos=theDest.RFind("efg"); + NS_ASSERTION(pos==4,"Error: RFind routine"); + + pos=theDest.RFind("xxx"); + NS_ASSERTION(pos==-1,"Error: RFind routine"); //this should fail + + pos=theDest.RFind(""); + NS_ASSERTION(pos==-1,"Error: RFind routine"); //this too should fail. + + pos=theDest.RFindChar('a',PR_FALSE,4); + NS_ASSERTION(pos==-1,"Error: RFind routine"); + + + //now try searching with FindChar using offset and count... + { + stringtype s1("hello there rick"); + + PRInt32 pos=s1.FindChar('r'); //this will search from the beginning, and for the length of the string. + NS_ASSERTION(pos==9,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('r',PR_FALSE,0,5); //this will search from the front using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('r',PR_FALSE,0,10); //this will search from the front using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==9,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('i',PR_FALSE,5,5); //this will search from the middle using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('i',PR_FALSE,5,10); //this will search from the middle using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==13,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('k',PR_FALSE,10,2); //this will search from near the end using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('k',PR_FALSE,10,7); //this will search from near the end using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==15,"Error: FindChar() with offset and count"); + + //now let's try a few with bad data... + + pos=s1.FindChar('k',PR_FALSE,100,2); //this will search from a bad offset. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('k',PR_FALSE,10,0); //this will search for a bad count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('k',PR_FALSE,10,20); //this will search for a bad count. THIS WILL SUCCEED! + NS_ASSERTION(pos==15,"Error: FindChar() with offset and count"); + + pos=s1.FindChar('k',PR_FALSE,10,4); //this will search for a bad count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: FindChar() with offset and count"); + + pos=10; + } + + //now try searching with RFindChar using offset and count... + { + stringtype s1("hello there rick"); + + PRInt32 pos=s1.RFindChar('o'); //this will search from the end, and for the length of the string. + NS_ASSERTION(pos==4,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('i'); //this will search from the end, and for the length of the string. + NS_ASSERTION(pos==13,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar(' ',PR_FALSE,-1,4); //this will search from the end, and for the length of the string. + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); //THIS WILL FAIL + + pos=s1.RFindChar(' ',PR_FALSE,12,1); //this will search from the middle, and for the length of 1. + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); //THIS WILL FAIL + + pos=s1.RFindChar(' ',PR_FALSE,12,2); //this will search from the middle, and for the length of 2. + NS_ASSERTION(pos==11,"Error: RFindChar() with offset and count"); //THIS WILL SUCCEED + + pos=s1.RFindChar('o',PR_FALSE,-1,5); //this will search from the end using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('o',PR_FALSE,-1,12); //this will search from the front using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==4,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('l',PR_FALSE,8,2); //this will search from the middle using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('l',PR_FALSE,8,7); //this will search from the middle using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==3,"Error: RFindChar() with offset and count"); + +//*** + + pos=s1.RFindChar('h',PR_FALSE,3,2); //this will search from near the end using count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('h',PR_FALSE,3,7); //this will search from near the end using count. THIS WILL SUCCEED! + NS_ASSERTION(pos==0,"Error: RFindChar() with offset and count"); + + //now let's try a few with bad data... + + pos=s1.RFindChar('k',PR_FALSE,100,2); //this will search from a bad offset. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); + + pos=s1.RFindChar('k',PR_FALSE,10,0); //this will search for a bad count. THIS WILL FAIL! + NS_ASSERTION(pos==-1,"Error: RFindChar() with offset and count"); + + pos=10; + } + + //now try searching with Find() using offset and count... + { + stringtype s1("hello there rick"); + + PRInt32 pos= s1.Find("there",PR_FALSE,0,4); //first search from front using offset + NS_ASSERTION(pos==-1,"Error: Find() with offset and count"); //THIS WILL FAIL + + pos= s1.Find("there",PR_FALSE,0,8); //first search from front using count + NS_ASSERTION(pos==6,"Error: Find) with offset and count"); //THIS WILL SUCCEED + + pos= s1.Find("there",PR_FALSE,4,1); //first search from front using count + NS_ASSERTION(pos==-1,"Error: Find() with offset and count"); //THIS WILL FAIL + + pos= s1.Find("there",PR_FALSE,5,2); //first search from front using count + NS_ASSERTION(pos==6,"Error: Find() with offset and count"); //THIS WILL SUCCEED + + pos= s1.Find("there",PR_FALSE,6,1); //first search from front using count + NS_ASSERTION(pos==6,"Error: Find() with offset and count"); //THIS WILL SUCCEED + + pos= s1.Find("there",PR_FALSE,6,0); //first search from front using a bogus count + NS_ASSERTION(pos==-1,"Error: Find() with offset and count"); //THIS WILL FAIL + + pos= s1.Find("k",PR_FALSE,15,1); //first search from end using a count + NS_ASSERTION(pos==15,"Error: Find() with offset and count"); //THIS WILL SUCCEED + + pos= s1.Find("k",PR_FALSE,15,10); //first search from end using a LARGE count + NS_ASSERTION(pos==15,"Error: Find() with offset and count"); //THIS WILL SUCCEED + + pos= s1.Find("k",PR_FALSE,25,10); //first search from bogus offset using a LARGE count + NS_ASSERTION(pos==-1,"Error: Find() with offset and count"); //THIS WILL FAIL + + pos=10; + } + + //now try substringsearching with RFind() using offset and count... + { + nsString s1("abcdefghijklmnopqrstuvwxyz"); + + PRInt32 pos= s1.RFind("ghi"); //first search from end using count + NS_ASSERTION(pos==6,"Error: RFind() with offset and count"); //THIS WILL SUCCEED! + + pos= s1.RFind("nop",PR_FALSE,-1,4); //first search from end using count + NS_ASSERTION(pos==-1,"Error: RFind() with offset and count"); //THIS WILL FAIL + + pos= s1.RFind("nop",PR_FALSE,-1,15); //first search from end using count + NS_ASSERTION(pos==13,"Error: RFind() with offset and count"); //THIS WILL SUCCEED + + pos= s1.RFind("nop",PR_FALSE,16,3); //first search from middle using count + NS_ASSERTION(pos==-1,"Error: RFind() with offset and count"); //THIS WILL FAIL + + pos= s1.RFind("nop",PR_FALSE,16,7); //first search from middle using count + NS_ASSERTION(pos==13,"Error: RFind() with offset and count"); //THIS WILL SUCCEED + + pos= s1.RFind("nop",PR_FALSE,0,1); //first search from front using count + NS_ASSERTION(pos==-1,"Error: RFind() with offset and count"); //THIS WILL FAIL + + pos= s1.RFind("abc",PR_FALSE,0,1); //first search from middle using count + NS_ASSERTION(pos==0,"Error: RFind() with offset and count"); //THIS WILL SUCCEED + + pos= s1.RFind("foo",PR_FALSE,10,100); //first search from front using bogus count + NS_ASSERTION(pos==-1,"Error: RFind() with offset and count"); //THIS WILL FAIL + + pos= s1.RFind("ghi",PR_FALSE,30,1); //first search from middle using bogus offset + NS_ASSERTION(pos==-1,"Error: RFind() with offset and count"); //THIS WILL FAIL + + pos=10; + } + + //Various UNICODE tests... + { + //do some searching against chinese unicode chars... + + PRUnichar chinese[] = {0x4e41,0x4e42, 0x4e43, 0x0000}; // 3 chinese unicode + + nsString T2(chinese); + nsString T2copy(chinese); + + pos = T2.FindCharInSet("A"); + NS_ASSERTION(kNotFound==pos,"Error in FindCharInSet"); + + pos=T2.RFindCharInSet("A",2); + NS_ASSERTION(kNotFound==pos,"Error in RFindCharInSet"); + + pos=T2.Find("A", PR_FALSE, 0, 1); + NS_ASSERTION(kNotFound==pos,"Error in Find"); + + pos=T2.RFind("A", PR_FALSE, 2, 1); + NS_ASSERTION(kNotFound==pos,"Error in RFind"); + + T2.ReplaceChar("A",' '); + NS_ASSERTION(T2==T2copy,"Error in ReplaceChar"); + + //Here's the 3rd FTang unicode test... + + static char test4[]="ABCDEF"; + static char test4b[]=" BCDEF"; + + PRUnichar test5[]={0x4e41, 0x0000}; + PRUnichar test6[]={0x0041, 0x0000}; + + nsCString T4(test4); + nsCString T4copy(test4); + nsCString T4copyb(test4b); + nsCString T5(test5); + nsCString T6(test6); + + pos = T4.FindCharInSet(T5.get()); + NS_ASSERTION(0==pos,"Error in FindcharInSet"); //This should succeed. + + pos = T4.FindCharInSet(T6.get()); + NS_ASSERTION(kNotFoundtemp8.Compare(bbbb),kComparisonError); + NS_ASSERTION(0>temp8.Compare(temp9),kComparisonError); + NS_ASSERTION(0=temp8)),kComparisonError); + + NS_ASSERTION(((temp9>temp8) && (temp8<=temp9)),kComparisonError); + NS_ASSERTION(temp9>aaaa,kComparisonError); + + NS_ASSERTION(temp8<=temp8,kComparisonError); + NS_ASSERTION(temp8<=temp9,kComparisonError); + NS_ASSERTION(temp8<=bbbb,kComparisonError); + + NS_ASSERTION(((temp9>=temp8) && (temp8=temp8,kComparisonError); + NS_ASSERTION(temp9>=aaaa,kComparisonError); + + NS_ASSERTION(temp8.Equals(temp8),kEqualsError); + NS_ASSERTION(temp8.Equals(aaaa),kEqualsError); + + stringtype temp10(temp8); + ToUpperCase(temp10); + NS_ASSERTION(temp8.Equals(temp10,PR_TRUE),kEqualsError); + NS_ASSERTION(temp8.Equals("AAAA",PR_TRUE),kEqualsError); + + + //now test the new string Equals APIs.. + { + nsCString s1("hello there"); + NS_ASSERTION(s1.Equals("hello there"),kEqualsError); + NS_ASSERTION(s1.Equals("hello rick",PR_FALSE,5),kEqualsError); + NS_ASSERTION(!s1.Equals("hello rick",PR_FALSE-1),kEqualsError); + + nsCString s2(""); + NS_ASSERTION(s2.Equals(""),kEqualsError); + + nsCString s3("view-source:"); + NS_ASSERTION(s3.Equals("VIEW-SOURCE:",PR_TRUE,12),kEqualsError); + } + + //now test the count argument... + { + nsString s1("rickgessner"); + nsString s2("rickricardo"); + PRInt32 result=s1.Compare(s2); //assume no case conversion, and full-length comparison... + result=s1.Compare(s2,PR_FALSE,4); + result=s1.Compare(s2,PR_FALSE,5); + + PRBool b=s1.Equals(s2); + b=s1.Equals("rick",PR_FALSE,4); + b=s1.Equals("rickz",PR_FALSE,5); + + result=10; + + nsString s3("view"); + +#define kString "view-source" + + b=s3.Equals(kString); + result=10; + } + + return result; +} + +/** + * + * @update gess10/30/98 + * @param + * @return + */ +int CStringTester::TestAssignAndAdd(){ + int result=0; + + static const char* s1="hello"; + static const char* s2="world"; + static const PRUnichar pbuf[] = {' ','w','o','r','l','d',0}; + + nsString ns1("I'm an nsString"); + nsCString nc1("I'm an nsCString"); + + nsAutoString as1("nsAutoString source"); + nsCAutoString ac1("nsCAutoString source"); + + + { + //**** Test assignments to nsCString... + + nsCString theDest; + theDest.Assign(theDest); //assign nsString to itself + theDest.Assign(ns1); //assign an nsString to an nsString + NS_ASSERTION(theDest==ns1,"Assignment error"); + + theDest.Assign(nc1); //assign an nsCString to an nsString + NS_ASSERTION(theDest==nc1,"Assignment error"); + + theDest.Assign(as1); //assign an nsAutoString to an nsString +// NS_ASSERTION(theDest==as1,"Assignment error"); + + theDest.Assign(ac1); //assign an nsCAutoString to an nsString +// NS_ASSERTION(theDest==ac1,"Assignment error"); + + theDest.Assign("simple char*"); //assign a char* to an nsString + NS_ASSERTION(theDest=="simple char*","Assignment error"); + + theDest.Assign(pbuf); //assign a PRUnichar* to an nsString + NS_ASSERTION(theDest==pbuf,"Assignment error"); + + theDest.Assign('!'); //assign a char to an nsString + NS_ASSERTION(theDest=="!","Assignment error"); + + theDest.Assign(PRUnichar('$')); //assign a char to an nsString + NS_ASSERTION(theDest=="$","Assignment error"); + + theDest=ns1; + NS_ASSERTION(theDest==ns1,"Assignment error"); + + theDest=nc1; + NS_ASSERTION(theDest==nc1,"Assignment error"); + + theDest='a'; + NS_ASSERTION(theDest=="a","Assignment error"); + + theDest=PRUnichar('a'); + NS_ASSERTION(theDest=="a","Assignment error"); + + theDest=s1; + NS_ASSERTION(theDest==s1,"Assignment error"); + + theDest=pbuf; + NS_ASSERTION(theDest==pbuf,"Assignment error"); + + } + + //test operator+()... + { + + /* NOT WORKING YET... + nsString s1("hello"); + nsString s2(" world"); + nsCString c1(" world"); + + stringtype theDest; + + theDest=s1+s2; + NS_ASSERTION(theDest=="hello world","Assignment error"); + + theDest=s1+c1; + NS_ASSERTION(theDest=="hello world","Assignment error"); + + theDest=s1+" world"; + NS_ASSERTION(theDest=="hello world","Assignment error"); + + theDest=s1+pbuf; + NS_ASSERTION(theDest=="hello world","Assignment error"); + + theDest=s1+'!'; + NS_ASSERTION(theDest=="hello!","Assignment error"); + + theDest=s1+PRUnichar('!'); + NS_ASSERTION(theDest=="hello!","Assignment error"); +*/ + + } + + return result; +} + + +/** + * + * @update gess10/30/98 + * @param + * @return + */ +int CStringTester::TestAppend(){ + int result=0; + + + static const char* s1="hello"; + static const char* s2="world"; + static const PRUnichar pbuf[] = {' ','w','o','r','l','d',0}; + static const PRUnichar pbuf1[] = {'a','b','c','d','l','d'}; + + + stringtype theDest; + theDest.Append((float)100.100); + NS_ASSERTION(theDest=="100.1","Append(float) error"); + + theDest.Truncate(); + theDest.Append(12345); + NS_ASSERTION(theDest=="12345","Append(int) error"); + + theDest.Truncate(); + theDest.Append(pbuf1,1); + NS_ASSERTION(theDest=="a","Append(PRUnichar*,count) error"); + + theDest.Truncate(); + theDest.Append('a'); + NS_ASSERTION(theDest=="a","Append(char) error"); + + + static const PRUnichar pbuf2[] = {'w','h','a','t','s',' ','u','p',' ','d','o','c','?',0}; + + theDest.Truncate(); + theDest.Append(pbuf,20); //try appending more chars than actual length of pbuf + NS_ASSERTION(theDest!=pbuf,"Append(PRUnichar*) error"); + //(NOTE: if you tell me to append X chars, I'll assume you really have X chars, and the length + // get's set accordingly. This test really is correct; it just seems odd. + + theDest.Truncate(0); + theDest.Append(pbuf,5); //try appending fewer chars than actual length of pbuf + NS_ASSERTION(theDest==" worl","Append(PRUnichar*) error"); + + theDest.Truncate(0); + theDest.Append(pbuf); //try appending all of pbuf + NS_ASSERTION(theDest==pbuf,"Append(PRUnichar*) error"); + + char* ss=0; + theDest.Truncate(); + theDest.Append(ss); //try appending NULL + NS_ASSERTION(theDest=="","Append(nullstr) error"); + + theDest.Append(pbuf,0); //try appending nothing + NS_ASSERTION(theDest=="","Append(nullstr) error"); + + + { + //test improvement to unichar appends... + stringtype s1("hello"); + char c='!'; + s1+=c; + NS_ASSERTION(s1=="hello!","operator+=() error"); + + c=(char)0xfa; + s1+=c; + s1.Append(c); + + PRUnichar theChar='f'; + s1+=theChar; + + char theChar2='g'; + s1+=theChar2; + +// long theLong= 1234; +// s1+=theLong; + + } + + { + //this just proves we can append nulls in our buffers... + stringtype c("hello"); + stringtype s(" there"); + c.Append(s); + char buf[]={'a','b',0,'d','e'}; + s.Append(buf,5); + } + + + stringtype temp2("there"); + + theDest.Append(temp2); + theDest.Append(" xxx "); + theDest.Append(pbuf); + theDest.Append('4'); + theDest.Append(PRUnichar('Z')); + + stringtype a(s1); + stringtype b(s2); + + theDest.Truncate(); + temp2.Truncate(); + +/* NOT WORKING YET... + theDest=a+b; + temp2=a+"world!"; + temp2=a+pbuf; + stringtype temp3; + temp3=temp2+'!'; +*/ + return result; +} + + +/** + * + * @update gess10/30/98 + * @param + * @return + */ +int CStringTester::TestExtractors(){ + int result=0; + + //first test the 2 byte version... + + + { + nsString temp1("hello there rick"); + nsString temp2; + + temp1.Left(temp2,10); + NS_ASSERTION(temp2=="hello ther","Left() error"); + + temp1.Mid(temp2,6,5); + NS_ASSERTION(temp2=="there","Mid() error"); + + temp1.Right(temp2,4); + NS_ASSERTION(temp2=="rick","Right() error"); + + //Now test the character accessor methods... + nsString theString("hello"); + PRUint32 len=theString.Length(); + PRUnichar theChar; + for(PRUint32 i=0;i2) { + pos=theString.Length()/2; + theSTLString.insert(pos,str[index],4); + theString.Insert(str[index],pos); + } + break; + + case 6: + case 7: + case 8: + case 9: + theOp=eDelete; + if(theString.Length()>10) { + len=theString.Length()/2; + pos=theString.Length()/4; + theSTLString.erase(pos,len); + theString.Cut(pos,len); + } + break; + + default: + theOp=eNOP; + + } //for + + if(eNOP300) { + theString.Truncate(); + theSTLString.erase(); + } +#endif + thePrevString=theString; + } + } +#endif + return result; +} + + +/** + * + * @update gess10/30/98 + * @param + * @return + */ +int CStringTester::TestReplace(){ + int result=0; + + const char* find=".."; + const char* rep= "+"; + + const char* s1="hello..there..rick..gessner."; + const char* s2="hello+there+rick+gessner."; + + nsCString s(s1); + s.ReplaceSubstring(find,rep); + NS_ASSERTION(s==s2,"ReplaceSubstring error"); + + s.ReplaceSubstring(rep,find); + NS_ASSERTION(s==s1,"ReplaceSubstring error"); + + return result; +} + + +/** + * This method tests the performance of various methods. + * + * + * @return + */ +int CStringTester::TestWideStringPerformance() { + + printf("Widestring performance tests...\n"); + + char* libname[] = {"STL","nsString",0}; + + + //************************************************** + //Test Construction against STL::wstring... + //************************************************** + { + nsString theConst; + for(int z=0;z<10;z++){ + theConst.Append("0123456789"); + } + + Stopwatch watch1; + int i; + for(i=0;i<1000000;i++){ + nsString s(theConst); + } + watch1.Stop(); + + wchar_t wbuf[] = {'a','b','c','d','e','f','g','h','i','j',0}; + wstring theConst2; + for(int w=0;w<10;w++){ + theConst2.append(wbuf); + } + + Stopwatch watch2; +#ifdef USE_STL + for(i=0;i<1000000;i++){ + wstring s(theConst2); + } +#endif + watch2.Stop(); + + printf("Construct(abcde) NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + } + + + //************************************************** + //Test append("abcde") against STL::wstring... + //************************************************** + { + + PRUnichar pbuf[10]={'a','b','c','d','e',0}; + + Stopwatch watch1; + int i; + for(i=0;i<1000;i++){ + nsString s; + for(int j=0;j<200;j++){ + s.Append("abcde"); + } + } + watch1.Stop(); + + wchar_t wbuf[10] = {'a','b','c','d','e',0}; + + Stopwatch watch2; +#ifdef USE_STL + for(i=0;i<1000;i++){ + wstring s; + for(int j=0;j<200;j++){ + s.append(wbuf); + } + } +#endif + watch2.Stop(); + + printf("Append(abcde) NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + } + + //************************************************** + //Test append(char) against STL::wstring + //************************************************** + { + + Stopwatch watch1; + int i; + for(i=0;i<500;i++){ + nsString s; + for(int j=0;j<200;j++){ + s.Append('a'); + } + } + watch1.Stop(); + + + Stopwatch watch2; +#ifdef USE_STL + for(i=0;i<500;i++){ + wstring s; + wchar_t theChar('a'); + for(int j=0;j<200;j++){ + s.append('a',1); + } + } +#endif + watch2.Stop(); + + printf("Append('a') NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + int x=0; + } + + //************************************************** + //Test insert("123") against STL::wstring + //************************************************** + { + + PRUnichar pbuf1[10]={'a','b','c','d','e','f',0}; + PRUnichar pbuf2[10]={'1','2','3',0}; + + Stopwatch watch1; + int i; + for(i=0;i<1000;i++){ + nsString s("abcdef"); + int inspos=3; + for(int j=0;j<100;j++){ + s.Insert(pbuf2,inspos); + inspos+=3; + } + } + watch1.Stop(); + + + wchar_t wbuf1[10] = {'a','b','c','d','e','f',0}; + wchar_t wbuf2[10] = {'1','2','3',0}; + + Stopwatch watch2; +#ifdef USE_STL + for(i=0;i<1000;i++){ + wstring s(wbuf1); + int inspos=3; + for(int j=0;j<100;j++){ + s.insert(inspos,wbuf2); + inspos+=3; + } + } +#endif + watch2.Stop(); + + printf("Insert(123) NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + int x=0; + } + + //************************************************** + //Let's test substring searching performance... + //************************************************** + { + PRUnichar pbuf1[] = {'a','a','a','a','a','a','a','a','a','a','b',0}; + PRUnichar pbuf2[] = {'a','a','b',0}; + + nsString s(pbuf1); + nsString target(pbuf2); + + Stopwatch watch1; + int i; + for(i=-1;i<200000;i++) { + PRInt32 result=s.Find(target,PR_FALSE); + } + watch1.Stop(); + + Stopwatch watch2; +#ifdef USE_STL + wchar_t wbuf1[] = {'a','a','a','a','a','a','a','a','a','a','b',0}; + wchar_t wbuf2[] = {'a','a','b',0}; + wstring ws(wbuf1); + wstring wtarget(wbuf2); + + for(i=-1;i<200000;i++) { + PRInt32 result=ws.find(wtarget); + } +#endif + watch2.Stop(); + + printf("Find(aab) NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + } + + //************************************************** + //Now let's test comparisons... + //************************************************** + { + nsString s("aaaaaaaaaaaaaaaaaaab"); + PRUnichar target[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','b',0}; + size_t theLen=(sizeof(target)-1)/2; + + Stopwatch watch1; + int result=0; + int i; + for(i=-1;i<1000000;i++) { + result=s.Compare(target,PR_FALSE,theLen); + result++; + } + watch1.Stop(); + + Stopwatch watch2; +#ifdef USE_STL + wchar_t buf[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','b',0}; + wstring ws(buf); + wchar_t wtarget[]={'a','a','a','a','a','a','a','a','a','a','a','a','a','b',0}; + + for(i=-1;i<1000000;i++) { + result=ws.compare(0,theLen,wtarget); + result++; + } +#endif + watch2.Stop(); + + printf("Compare(aaaaaaaab) NSString: %f STL: %f\n",watch1.Elapsed(),watch2.Elapsed()); + + } + + //************************************************** + //Now lets test string deletions... + //************************************************** + { + + int strcount=6000; + int outerIter=100; + int innerIter=100; + + PRUnichar pbuf[] = {'1','2','3','4','5','6','7','8','9','0',0}; + nsString source1; //build up our target string... + int i; + for(i=0;i"); + PRInt32 result=s.Find("",PR_TRUE); + + //this was a known bug... + { + nsString s0(""); + PRInt32 pos=s0.RFind("-->"); + nsString s1("debug"); + pos=s1.RFind("b"); + pos=s1.RFind("de",PR_FALSE,1); + pos=10; + } + + //this was a known bug... + { + nsString s0("RDF:RDF"); + PRInt32 pos=s0.Find(":"); + pos=10; + } + + return result; +} + +#endif + diff --git a/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest2.h b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest2.h new file mode 100644 index 00000000..16ffc11a --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest2.h @@ -0,0 +1,444 @@ +/******************************************************************************************** + * + * MODULES NOTES: + * + * This file is designed to help test the new nsString classes. + * + * Contributor(s): + * Rick Gessner + * + * History: + * + * 02.29.2000: Original files (rickg) + * 03.02.2000: Flesh out the interface to be compatible with old library (rickg) + * + ********************************************************************************************/ + +#ifndef _STRINGTEST2 +#define _STRINGTEST2 + + +#include "nsString.h" +#include + +#define USE_STL + +#ifdef USE_STL +#include +using namespace std; +#endif + +#define USE_WIDE 1 +#ifdef USE_WIDE + #define stringtype nsString + #define astringtype nsAutoString + #define chartype PRUnichar +#else + #define stringtype nsCString + #define astringtype nsCAutoString + #define chartype char +#endif + +#include +const double gTicks = 1.0e-7; + + + + + +/******************************************************** + + This class's only purpose in life is to test the + netscape string library. We exercise the string + API's here, and do a bit of performance testing + against the standard c++ library string (from STL). + + ********************************************************/ +class CStringTester { + +public: + + int TestI18nString(); + +}; + + + + +//test 1: unicode char is stripped correctly using StripChars() +void nsStringTest1(){ + PRUnichar test[]={0x0041,0x0051,0x0052,0x0000}; + nsString T(test); + PRUnichar result[]={0x0051,0x0052,0x0000}; + nsString R(result); + T.StripChars("ABC"); + NS_ASSERTION(T.Equals(R), "Test 1: Unicode comparison error"); +} +//test 2: unicode char is not matched and stripped when high-order byte is not 0x00 +void nsStringTest2(){ + PRUnichar test[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.StripChars("ABC"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} + //test 3: unicode char is not matched and stripped when high-order byte is 0xFF +void nsStringTest3(){ + + PRUnichar test[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(test); + T.StripChars("ABC"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest4(){ + //test 4: unicode char is matched and stripped correctly using StripChar() + PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x0051,0x0052,0x0000}; + nsAutoString R(result); + T.StripChar('A'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest5(){ + //test 5: unicode char is not matched and stripped when high-order byte is not 0x00 + + PRUnichar test[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.StripChar('A'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest6(){ + //test 6: unicode char is not matched and stripped when high-order byte is 0xFF + + PRUnichar test[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.StripChar('A'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest7(){ + //test 7: unicode char is matched and replaced correctly using ReplaceChar() + + PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x0050,0x0051,0x0052,0x0000}; + nsAutoString R(result); + T.ReplaceChar('A',0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest8(){ + //test 8: unicode char is not matched or replaced when high-order byte != 0x00 + + PRUnichar test[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.ReplaceChar('A',0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest9(){ + //test 9: unicode char is not matched or replaced when high-order byte matches search char + + PRUnichar test[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.ReplaceChar('A',0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest10(){ + //test 10: unicode char is not matched or replaced when high-order byte == 0xFF + + PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.ReplaceChar('A',0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} + +void nsStringTest11(){ + //test 11: unicode char is correctly replaced when parameter 1 is a string + + PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x0050,0x0051,0x0052,0x0000}; + nsAutoString R(result); + T.ReplaceChar("ABC",0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest12(){ + //test 12: unicode char is not replaced when high-order byte != 0x00 + + PRUnichar test[] = {0x4e41,0x0051,0x0052,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4e41,0x0051,0x0052,0x0000}; + nsAutoString R(result); + T.ReplaceChar("ABC",0x50); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); + +} +void nsStringTest13(){ + //test 13: unicode char is not replaced when high-order byte matches char in search string + PRUnichar test[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.ReplaceChar("ABC",'T'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); + +} +void nsStringTest14(){ + PRUnichar test[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.ReplaceChar("ABC",'T'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest15(){ + PRUnichar test[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + PRUnichar s = 0xc2; //compiler error on this line + T.ReplaceChar(s,'T'); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} + +void nsStringTest16(){ + /* TESTS for ReplaceSubstring()*/ + + PRUnichar test[] = {0x0041,0x0042,0x0043,0x0044,0x0045,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x0044,0x0045,0x0046,0x0044,0x0045}; + nsAutoString R(result); + T.ReplaceSubstring("ABC","DEF"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); + +} +void nsStringTest17(){ + + PRUnichar test[] = {0x0041,0x4e42,0x0043,0x0044,0x0045,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x0041,0x4e42,0x0043,0x0044,0x0045,0x0000}; + nsAutoString R(result); + T.ReplaceSubstring("ABC","DEF"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest18(){ + /*TESTS for Trim()*/ + + PRUnichar test[] = {0x0041,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R (result); + T.Trim("ABC"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest19(){ + PRUnichar test[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString R(result); + T.Trim("ABC"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +} +void nsStringTest22(){ + PRUnichar test[] = {0x4e51,0x4e52,0x4e53,0x4e41,0x0000}; + nsAutoString T(test); + PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x4e41,0x0000}; + nsAutoString R(result); + T.Trim("ABC"); + NS_ASSERTION(T.Equals(R), "Unicode comparison error"); + +} +//void nsStringTest23(){ +// PRUnichar test[] = {0x4e51,0x4e52,0x4e53,0x4e22,0x0000}; +// nsAutoString T(test); +// PRUnichar s(0x4e22); +// PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x0000}; +// nsAutoString R(result); +// T.Trim(s,PR_TRUE,PR_TRUE,PR_FALSE); +// NS_ASSERTION(T.Equals(R), "Unicode comparison error"); +//} +void nsStringTest24(){ + /*TESTS for Find()*/ + PRUnichar test[] = {0x0041,0x0042,0x0043,0x0051,0x0052,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.Find("ABC") == 0, "Unicode comparison error"); + +} +void nsStringTest25(){ + PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.Find("ABC") == -1, "Unicode comparison error"); + +} +void nsStringTest26(){ + PRUnichar test[] = {0xFFc1,0x0051,0x0052,0x0053,0x0000}; + nsAutoString T(test); + PRUnichar str[] = {0xc1,0x51,0x52}; + nsAutoString S(str); + NS_ASSERTION(T.Find(S) == -1, "Unicode comparison error"); +} +void nsStringTest27(){ + /*TESTS for FindChar()*/ + + PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindChar('A') == 0, "Unicode comparison error"); +} +void nsStringTest28(){ + PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindChar('A') == -1, "Unicode comparison error"); +} +void nsStringTest29(){ + PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindChar(0xc1) == -1, "Unicode comparison error"); + +} +void nsStringTest30(){ + PRUnichar test[] = {0x4132,0x0051,0x0052,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindChar('A1') == -1, "Unicode comparison error"); +} + /*TESTS for FindCharInSet()*/ +void nsStringTest31(){ + PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindCharInSet("ABC") == 0, "Unicode comparison error"); +} +void nsStringTest32(){ + PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindCharInSet("ABC") == -1, "Unicode comparison error"); + +} +void nsStringTest33(){ + PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar str[] = {0xc1,0x51,0x52}; + nsAutoString s(str); + NS_ASSERTION(T.FindCharInSet(s) == -1, "Unicode comparison error"); +} +void nsStringTest34(){ + PRUnichar test[] = {0x4132,0x5132,0x5232,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.FindCharInSet("ABC") == -1, "Unicode comparison error"); +} + /*TESTS for RFind()*/ +void nsStringTest35(){ + + PRUnichar test[] = {0x0051,0x0052,0x0041,0x0042,0x0043,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.RFind("ABC") == 2, "Unicode comparison error"); +} +void nsStringTest36(){ + PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.RFind("ABC") == -1, "Unicode comparison error"); +} +void nsStringTest37(){ + PRUnichar test[] = {0xFFc1,0xFFc2,0xFFc3,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar str[] = {0xc1,0xc2,0xc3}; + nsAutoString s(str); + NS_ASSERTION(T.RFind(s) == -1, "Unicode comparison error"); +} + /*TESTS for RFindCharInSet*/ +void nsStringTest38(){ + + PRUnichar test[] = {0x0041,0x0042,0x0043,0x0000}; + nsAutoString T(test); + int res = T.RFindCharInSet("ABC"); + NS_ASSERTION(res==0, "Unicode comparison error"); +} +void nsStringTest39(){ + PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.RFindCharInSet("ABC") == -1, "Unicode comparison error"); +} +void nsStringTest40(){ + PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000}; + nsAutoString T(test); + PRUnichar str[] = {0xc1,0xc2,0xc3}; + nsAutoString s(str); + NS_ASSERTION(T.RFindCharInSet(s) == -1, "Unicode comparison error"); +} +void nsStringTest41(){ + PRUnichar test[] = {0x4132,0x0051,0x0052,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.RFindCharInSet("ABC") == -1, "Unicode comparison error"); +} + /* TESTS for Compare() */ +void nsStringTest42(){ + PRUnichar test[] = {0x0041,0x0042,0x0043,0x0000}; + nsAutoString T(test); + NS_ASSERTION(T.Compare("ABC") == 0, "Unicode comparison error"); +} +void nsStringTest43(){ + PRUnichar test[] = {0xc341,0xc342,0xc343}; + nsAutoString T(test); + NS_ASSERTION(T.Compare("ABC") == 1, "Unicode comparison error"); +} + + +int CStringTester::TestI18nString(){ + nsStringTest1(); + nsStringTest2(); + nsStringTest3(); + nsStringTest4(); + nsStringTest5(); + nsStringTest6(); + nsStringTest7(); + nsStringTest8(); + nsStringTest9(); + nsStringTest10(); + nsStringTest11(); + nsStringTest12(); + nsStringTest13(); + nsStringTest14(); + nsStringTest15(); + nsStringTest16(); + nsStringTest17(); + nsStringTest18(); + nsStringTest19(); + //nsStringTest20(); + //nsStringTest21(); + nsStringTest22(); + //nsStringTest23(); + nsStringTest24(); + nsStringTest25(); + nsStringTest26(); + nsStringTest27(); + nsStringTest28(); + nsStringTest29(); + nsStringTest30(); + nsStringTest31(); + nsStringTest32(); + nsStringTest33(); + nsStringTest34(); + nsStringTest35(); + nsStringTest36(); + nsStringTest37(); + nsStringTest38(); + nsStringTest39(); + nsStringTest40(); + nsStringTest41(); + nsStringTest42(); + nsStringTest43(); + + return 0; +} + +#endif + -- cgit v1.2.3