From ae6cee7e1d14d1f792c4d7b0a0f4b6ae58701a08 Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Wed, 22 Mar 2000 08:22:28 +0000 Subject: [PATCH] Incremental changes. These files are still not part of the build. git-svn-id: svn://10.0.0.236/trunk@63730 18797224-902f-48f8-a5cc-f745e15eee43 --- .../tests/StringFactoringTests/StringTest.mcp | Bin 183178 -> 209102 bytes .../xpcom/tests/StringFactoringTests/ToDo.doc | 33 +- .../StringFactoringTests/nsStdStringWrapper.h | 20 +- .../StringFactoringTests/profile_main.cpp | 78 ++- .../tests/StringFactoringTests/test_main.cc | 494 ++++++++++-------- 5 files changed, 370 insertions(+), 255 deletions(-) diff --git a/mozilla/xpcom/tests/StringFactoringTests/StringTest.mcp b/mozilla/xpcom/tests/StringFactoringTests/StringTest.mcp index 9510dfe086e29ea13190552c3c3ad318c07baaa4..c80e6fad3d162d14eaeef28094f42cc0b5c7c4f3 100644 GIT binary patch delta 3763 zcmcIndvH|M89(RjE4v9x$deczHza6CBo7he1R4^;BMFJwk{C$nB;>J#h3v!K4G*hH z#A>5cbuUM9ZM7g)t;{f0x#+d^m0*a9h*2}tR!6Zqt)g`ttrd`({?5HiSZZhbSI^9M z?(h7*@4UYAo$u`4sl=c7Fkx1w-`_(BF%d#@i76$Gm{Q9K$&8?V`IEDz(*+ZRuv3Jz zohM`?4A}%(6bg40mw5d?_s&4CuQS}%u@j02chMK=Jv@Q^hTh8$vd3p|u(v|uAR8bu z?=oFs-VMa*xuPHK0eFxQ`#C}q0EuYV8j#cxhoH!H5G+k+_3z<-?H?m#+t+HKI+@8X zGrz*BE=+@kWJU!k!bfjg03cIsE837EZg*t!JliHpRN1zIIS7NI2C|2LXkWnN9BV1z zvTZh|v+!FSsbbs+pW(>lPdFBSo#Knmmq))vd@|8{d8oX-(_7#Vb`xSdJT4X&Emq&wqL8P=Xz`7XnRZGk4uKNN zpPdor&g@M7dUDEi0#cW#<%2n?a|*>qV~XBFM`1^)+L|_v@?|+4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FactoringTests/ToDo.doc b/mozilla/xpcom/tests/StringFactoringTests/ToDo.doc index 90c731c1e49..b54be378110 100644 --- a/mozilla/xpcom/tests/StringFactoringTests/ToDo.doc +++ b/mozilla/xpcom/tests/StringFactoringTests/ToDo.doc @@ -1,31 +1,34 @@ // To Do... -Add test for |Replace|... + . Implement chunky iterators -Add tests for Find and RFind + . Get "nsAReadableString.h" and "nsAWritableString.h" to added to the MANIFEST, etc. -Implement the Find and RFind signatures + - Get "nsAReadableString.h" and "nsAWritableString.h" to compile everywhere -Fix Truncate / SetLength confusion (make SetLength the real function in |nsString|) + - Add test for |Replace|... -Write tests for Strip..., Trim?, CompressSet? + - Add tests for Find and RFind -Write non-member functions for Strip..., Trim?, CompressSet? + - Implement the Find and RFind signatures -Chop out conflicting |ns[C]String| operators + . Fix Truncate / SetLength confusion (make SetLength the real function in |nsString|) -Figure out how if we can make PRUnichar be wchar_t, so we get the cheap constructors, - ...and ensure the cheap constructors can be made to work everywhere + . Chop out conflicting |ns[C]String| operators -Add tests for |nsShared[C]String| + . Figure out how if we can make PRUnichar be wchar_t, so we get the cheap constructors, + ...and ensure the cheap constructors can be made to work everywhere -Implement |nsShared[C]String| + - Try the |static const unsigned long kLeftString = 1 - 1; /* because VC++ doesn't like =0 */| hack -Add tests for the shared string smart pointer + - Add tests for |nsShared[C]String| -Implement the shared string smart pointer + - Implement |nsShared[C]String| -Figure out why StdStringWrapper isn't as good as raw std::string + - Add tests for the shared string smart pointer -Implement a smart allocator for StdStringWrapper + - Implement the shared string smart pointer + . Figure out why StdStringWrapper isn't as good as raw std::string + + - Implement a smart allocator for StdStringWrapper diff --git a/mozilla/xpcom/tests/StringFactoringTests/nsStdStringWrapper.h b/mozilla/xpcom/tests/StringFactoringTests/nsStdStringWrapper.h index 3e75e433639..4aa331aeaee 100644 --- a/mozilla/xpcom/tests/StringFactoringTests/nsStdStringWrapper.h +++ b/mozilla/xpcom/tests/StringFactoringTests/nsStdStringWrapper.h @@ -69,23 +69,28 @@ class basic_nsStdStringWrapper static const size_type npos = size_type(-1); protected: - virtual const char* Implementation() const; + virtual const void* Implementation() const; virtual const CharT* GetConstFragment( ConstFragment&, FragmentRequest, PRUint32 ) const; virtual CharT* GetFragment( Fragment&, FragmentRequest, PRUint32 ); public: + basic_nsStdStringWrapper() { } + +#if 0 explicit basic_nsStdStringWrapper( const AllocatorT& a = AllocatorT() ) : mRawString(a) { } +#endif basic_nsStdStringWrapper( const basic_nsAReadableString& str ) - : mRawString(str.Begin(), str.End()) { + Assign(str); } +#if 0 basic_nsStdStringWrapper( const basic_string_t& str, size_type pos = 0, size_type n = npos ) : mRawString(str, pos, n) { @@ -95,6 +100,7 @@ class basic_nsStdStringWrapper : mRawString(str, pos, n, a) { } +#endif basic_nsStdStringWrapper( const CharT* s, size_type n, const AllocatorT& a = AllocatorT() ) : mRawString(s, n, a) @@ -106,11 +112,12 @@ class basic_nsStdStringWrapper { } +#if 0 basic_nsStdStringWrapper( size_type n, CharT c, const AllocatorT& a = AllocatorT() ) : mRawString(n, c, a) { } - +#endif virtual PRUint32 @@ -147,7 +154,7 @@ NS_DEF_STRING_COMPARISONS(basic_nsStdStringWrapper) template -const char* +const void* basic_nsStdStringWrapper::Implementation() const { static const char* implementation = "nsStdStringWrapper"; @@ -202,7 +209,10 @@ basic_nsStdStringWrapper::Assign( const basic_nsARea if ( rhs.Implementation() == Implementation() ) mRawString = NS_STATIC_CAST(this_t, rhs).mRawString; else - mRawString.assign(rhs.Begin(), rhs.End()); + { + mRawString.reserve(rhs.Length()); + basic_nsAWritableString::Assign(rhs); + } } template diff --git a/mozilla/xpcom/tests/StringFactoringTests/profile_main.cpp b/mozilla/xpcom/tests/StringFactoringTests/profile_main.cpp index bfc8dc37113..c77700cfff7 100644 --- a/mozilla/xpcom/tests/StringFactoringTests/profile_main.cpp +++ b/mozilla/xpcom/tests/StringFactoringTests/profile_main.cpp @@ -6,6 +6,8 @@ #include #include +#include "Profiler.h" + #ifndef TEST_STD_STRING #include "nsString.h" #else @@ -18,6 +20,12 @@ typedef nsStdCString nsCString; static const int kTestSucceeded = 0; static const int kTestFailed = 1; +#if 0 +#define N 1000 +#else +#define N 100000 +#endif + template inline @@ -27,7 +35,7 @@ TotalLength( const T& s ) return s.Length(); } -template <> +NS_SPECIALIZE_TEMPLATE inline PRUint32 TotalLength( const string& s ) @@ -43,7 +51,7 @@ Find( const T& text, const T& pattern ) return text.Find(pattern); } -template <> +NS_SPECIALIZE_TEMPLATE inline PRUint32 Find( const string& text, const string& pattern ) @@ -103,7 +111,7 @@ test_concat() { TestTimer timer; - for ( int i=0; i<100000; ++i ) + for ( int i=0; i s2 ) ++count; } @@ -173,7 +181,7 @@ test_compare() { TestTimer timer; - for ( int i=0; i<100000; ++i ) + for ( int i=0; i(os), PRUnichar_to_char()); - return os; + transform(s.Begin(), s.End(), ostream_iterator(cout), PRUnichar_to_char()); + return cout; } template basic_nsLiteralString -make_a_hello_string( CharT* ) +literal_hello( CharT* ) { } NS_SPECIALIZE_TEMPLATE basic_nsLiteralString -make_a_hello_string( char* ) +literal_hello( char* ) { return basic_nsLiteralString("Hello"); } NS_SPECIALIZE_TEMPLATE basic_nsLiteralString -make_a_hello_string( PRUnichar* ) +literal_hello( PRUnichar* ) { +#ifdef NS_USE_WCHAR_T + return basic_nsLiteralString(L"Hello"); +#else static PRUnichar constant_unicode[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() }; return basic_nsLiteralString(constant_unicode); +#endif } static @@ -68,128 +57,15 @@ CallCMid( nsAWritableCString& aResult, const nsAReadableCString& aSource, PRUint template int -readable_hello_tests( const basic_nsAReadableString& str, ostream& os = std::cout ) - { - int tests_failed = 0; +test_multifragment_iterators( const basic_nsAReadableString& aString ) + /* + ...this tests a problem that was present in |nsPromiseConcatenation| where, + because it originally stored some iteration state in the object itself, rather than + in the fragment, the iterators could get confused if used out of sequence. - if ( str.Length() != 5 ) - { - os << "Length() FAILED" << endl; - ++tests_failed; - } - - if ( str.First() != CharT('H') ) - { - cout << "|First()| FAILED" << endl; - ++tests_failed; - } - - if ( str.Last() != CharT('o') ) - { - cout << "|Last()| FAILED" << endl; - ++tests_failed; - } - - if ( str[3] != CharT('l') ) - { - cout << "|operator[]()| FAILED" << endl; - ++tests_failed; - } - - if ( str.CountChar( CharT('l') ) != 2 ) - { - cout << "|CountChar()| FAILED" << endl; - ++tests_failed; - } - - basic_nsAReadableString::ConstIterator iter = str.Begin(); - if ( *iter != CharT('H') ) - { - cout << "iterator FAILED: didn't start out pointing at the right thign or couldn't be dereferenced." << endl; - ++tests_failed; - } - - ++iter; - - if ( *iter != CharT('e') ) - { - cout << "iterator FAILED: couldn't be incremented, or else couldn't be dereferenced." << endl; - ++tests_failed; - } - - iter = str.End(); - --iter; - if ( *iter != CharT('o') ) - { - cout << "iterator FAILED: couldn't be set to End(), or else couldn't be decremented, or else couldn't be dereferenced." << endl; - ++tests_failed; - } - - basic_nsAReadableString::ConstIterator iter1 = str.Begin(3); - if ( *iter1 != CharT('l') ) - { - cout << "iterator FAILED: couldn't be set to Begin(n), or else couldn't be dereferenced." << endl; - ++tests_failed; - } - - basic_nsAReadableString::ConstIterator iter2 = str.End(2); - if ( *iter2 != CharT('l') ) - { - cout << "iterator FAILED: couldn't be set to End(n), or else couldn't be dereferenced." << endl; - ++tests_failed; - } - - if ( iter1 != iter2 ) - { - cout << "iterator comparison with != FAILED" << endl; - ++tests_failed; - } - - if ( !(iter1 == iter2) ) - { - cout << "iterator comparison with == FAILED" << endl; - ++tests_failed; - } - - typedef CharT* CharT_ptr; - - if ( str != make_a_hello_string( CharT_ptr() ) ) - { - cout << "comparison with hello string FAILED" << endl; - ++tests_failed; - } - - return tests_failed; - } - -static -inline -bool -compare_equals( const nsAReadableCString& lhs, const nsAReadableCString& rhs ) - { - return bool(lhs == rhs); - } - -static -inline -bool -compare_equals( const nsLiteralCString& lhs, const nsAReadableCString& rhs ) - { - return bool(lhs == rhs); - } - -static -inline -bool -compare_equals( const nsAReadableCString& lhs, const nsLiteralCString& rhs ) - { - return bool(lhs == rhs); - } - - -template -int -test_goofy_iterators( const basic_nsAReadableString& aString ) + This test should be run on any multi-fragment implementation to verify that it + does not have the same bug. Make sure the first fragment is only one character long. + */ { typedef typename basic_nsAReadableString::ConstIterator ConstIterator; @@ -204,13 +80,196 @@ test_goofy_iterators( const basic_nsAReadableString& aString ) ++iter1; ++iter1; if ( iter1 != iter2 ) { - cout << "goofy iterator test FAILED" << endl; + cout << "FAILED in |test_multifragment_iterators|" << endl; ++tests_failed; } return tests_failed; } +template +int +test_deprecated_GetBufferGetUnicode( const basic_nsAReadableString& aReadable ) + { + int tests_failed = 0; + + if ( aReadable.GetBuffer() || aReadable.GetUnicode() ) + { + cout << "FAILED |test_deprecated_GetBufferGetUnicode()|: non-zero result." << endl; + ++tests_failed; + } + + return tests_failed; + } + +NS_SPECIALIZE_TEMPLATE +int +test_deprecated_GetBufferGetUnicode( const basic_nsAReadableString& aReadable ) + { + int tests_failed = 0; + + if ( !aReadable.GetBuffer() ) + { + cout << "FAILED |test_deprecated_GetBufferGetUnicode()|: |GetBuffer()| returned 0." << endl; + ++tests_failed; + } + + if ( aReadable.GetUnicode() ) + { + cout << "FAILED |test_deprecated_GetBufferGetUnicode()|: |GetUnicode()| returned a non-zero result." << endl; + ++tests_failed; + } + + return tests_failed; + } + +NS_SPECIALIZE_TEMPLATE +int +test_deprecated_GetBufferGetUnicode( const basic_nsAReadableString& aReadable ) + { + int tests_failed = 0; + + if ( aReadable.GetBuffer() ) + { + cout << "FAILED |test_deprecated_GetBufferGetUnicode()|: |GetBuffer()| returned a non-zero result." << endl; + ++tests_failed; + } + + if ( !aReadable.GetUnicode() ) + { + cout << "FAILED |test_deprecated_GetBufferGetUnicode()|: |GetUnicode()| returned 0." << endl; + ++tests_failed; + } + + return tests_failed; + } + +template +int +test_readable_hello( const basic_nsAReadableString& aReadable ) + { + int tests_failed = 0; + + if ( aReadable.Length() != 5 ) + { + cout << "FAILED |test_readable_hello|: |Length()| --> " << aReadable.Length() << endl; + ++tests_failed; + } + + if ( aReadable.First() != CharT('H') ) + { + cout << "FAILED |test_readable_hello|: |First()| --> '" << aReadable.First() << "'" << endl; + ++tests_failed; + } + + if ( aReadable.Last() != CharT('o') ) + { + cout << "FAILED |test_readable_hello|: |Last()| --> '" << aReadable.Last() << "'" << endl; + ++tests_failed; + } + + if ( aReadable[3] != CharT('l') ) + { + cout << "FAILED |test_readable_hello|: |operator[]| --> '" << aReadable[3] << "'" << endl; + ++tests_failed; + } + + if ( aReadable.CountChar( CharT('l') ) != 2 ) + { + cout << "FAILED |test_readable_hello|: |CountChar('l')| --> " << aReadable.CountChar(CharT('l')) << endl; + ++tests_failed; + } + + basic_nsAReadableString::ConstIterator iter = aReadable.Begin(); + if ( *iter != CharT('H') ) + { + cout << "FAILED |test_readable_hello|: didn't start out pointing to the right thing, or else couldn't be dereferenced. --> '" << *iter << "'" << endl; + ++tests_failed; + } + + ++iter; + + if ( *iter != CharT('e') ) + { + cout << "FAILED |test_readable_hello|: iterator couldn't be incremented, or else couldn't be dereferenced. --> '" << *iter << "'" << endl; + ++tests_failed; + } + + iter = aReadable.End(); + --iter; + if ( *iter != CharT('o') ) + { + cout << "FAILED |test_readable_hello|: iterator couldn't be set to |End()|, or else couldn't be decremented, or else couldn't be dereferenced. --> '" << *iter << "'" << endl; + ++tests_failed; + } + + basic_nsAReadableString::ConstIterator iter1 = aReadable.Begin(3); + if ( *iter1 != CharT('l') ) + { + cout << "FAILED |test_readable_hello|: iterator couldn't be set to |Begin(n)|, or else couldn't be dereferenced. --> '" << *iter1 << "'" << endl; + ++tests_failed; + } + + basic_nsAReadableString::ConstIterator iter2 = aReadable.End(2); + if ( *iter2 != CharT('l') ) + { + cout << "FAILED |test_readable_hello|: iterator couldn't be set to |End(n)|, or else couldn't be dereferenced. --> '" << *iter2 << "'" << endl; + ++tests_failed; + } + + if ( iter1 != iter2 ) + { + cout << "FAILED |test_readable_hello|: iterator comparison with !=." << endl; + ++tests_failed; + } + + if ( !(iter1 == iter2) ) + { + cout << "FAILED |test_readable_hello|: iterator comparison with ==." << endl; + ++tests_failed; + } + + typedef CharT* CharT_ptr; + if ( aReadable != literal_hello(CharT_ptr()) ) + { + cout << "FAILED |test_readable_hello|: comparison with \"Hello\"" << endl; + ++tests_failed; + } + + tests_failed += test_multifragment_iterators(aReadable); + tests_failed += test_deprecated_GetBufferGetUnicode(aReadable); + + return tests_failed; + } + + + + + +template +int +test_writable( basic_nsAWritableString& aWritable ) + { + int tests_failed = 0; + // ... + + + { + typedef CharT* CharT_ptr; + aWritable = literal_hello(CharT_ptr()); + + if ( aWritable != literal_hello(CharT_ptr()) ) + { + cout << "FAILED assignment and/or comparison in |test_writable|." << endl; + ++tests_failed; + } + + tests_failed += test_readable_hello(aWritable); + } + + return tests_failed; + } + typedef void* void_ptr; @@ -222,49 +281,85 @@ main() cout << "String unit tests. Compiled " __DATE__ " " __TIME__ << endl; - // - // |nsLiteralString| - // - - - PRUnichar constant_unicode[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() }; - nsLiteralString aLiteralString(constant_unicode); - tests_failed += readable_hello_tests(aLiteralString); - - cout << "\""; - print_string(aLiteralString) << "\"" << endl; - { - const PRUnichar* buffer = aLiteralString.GetUnicode(); - if ( !buffer ) - { - cout << "|nsLiteralString::GetUnicode()| FAILED: should have returned non-|0|" << endl; - ++tests_failed; - } +#ifdef NS_USE_WCHAR_T + nsLiteralString s0(L"Hello"); +#else + PRUnichar b0[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() }; + nsLiteralString s0(b0); +#endif + tests_failed += test_readable_hello(s0); - const char* cbuffer = aLiteralString.GetBuffer(); - if ( cbuffer ) - { - cout << "|nsLiteralString::GetBuffer()| FAILED: should have returned |0|" << endl; - ++tests_failed; - } + nsLiteralCString s1("Hello"); + tests_failed += test_readable_hello(s1); } { - nsCString aCString("Hello"); - tests_failed += readable_hello_tests(aCString); +#ifdef NS_USE_WCHAR_T + nsString s3(L"Hello"); +#else + PRUnichar b3[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() }; + nsString s3(b3); +#endif + tests_failed += test_readable_hello(s3); + tests_failed += test_writable(s3); + + nsCString s4("Hello"); + tests_failed += test_readable_hello(s4); + tests_failed += test_writable(s4); } { - nsStdCString aCString("Hello"); - tests_failed += readable_hello_tests(aCString); +#ifdef NS_USE_WCHAR_T + nsStdString s5(L"Hello"); +#else + PRUnichar b5[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() }; + nsStdString s5(b5); +#endif + tests_failed += test_readable_hello(s5); + tests_failed += test_writable(s5); + + nsStdCString s6("Hello"); + tests_failed += test_readable_hello(s6); + tests_failed += test_writable(s6); } { - nsLiteralCString aLiteralCString("Hello"); - tests_failed += readable_hello_tests(aLiteralCString); +#ifdef NS_USE_WCHAR_T + nsLiteralString s7(L"He"); + nsString s8(L"l"); + nsStdString s9(L"lo"); +#else + PRUnichar b7[] = { 'H', 'e', PRUnichar() }; + PRUnichar b8[] = { 'l', PRUnichar() }; + PRUnichar b9[] = { 'l', 'o', PRUnichar() }; + + nsLiteralString s7(b7); + nsString s8(b8); + nsStdString s9(b9); +#endif + + tests_failed += test_readable_hello(s7+s8+s9); + + nsString s13( s7 + s8 + s9 ); + tests_failed += test_readable_hello(s13); + + nsStdString s14( s7 + s8 + s9 ); + tests_failed += test_readable_hello(s14); + + // nsSharedString s15( s7 + s8 + s9 ); + // tests_failed += test_readable_hello(s15); + + nsCString s10("He"); + nsLiteralCString s11("l"); + nsStdCString s12("lo"); + + tests_failed += test_readable_hello(s10+s11+s12); + + } + { nsLiteralCString str1("Hello"); nsStdCString str2("Hello"); @@ -296,14 +391,7 @@ main() } } - nsLiteralCString part1("He"), part2("llo"); - tests_failed += readable_hello_tests(part1+part2); - - nsLiteralCString part2a("l"), part2b("lo"); - tests_failed += readable_hello_tests(part1+part2a+part2b); - - cout << "The summed string is \"" << part1 + part2a + part2b << "\"" << endl; - +#if 0 nsStdCString extracted_middle("XXXXXXXXXX"); CallCMid(extracted_middle, part1+part2a+part2b, 1, 3); @@ -316,36 +404,12 @@ main() ++tests_failed; } - // - // |nsLiteralCString| - // - - - nsLiteralCString aLiteralCString("Goodbye"); - cout << "\"" << aLiteralCString << "\"" << endl; - if ( aLiteralCString.Length() == 7 ) - cout << "|nsLiteralCString::Length()| OK" << endl; - else - cout << "|nsLiteralCString::Length()| FAILED" << endl; - cout << aLiteralCString << endl; - - const char* cbuffer = aLiteralCString.GetBuffer(); - cout << "GetBuffer()-->" << showbase << void_ptr(cbuffer) << endl; - cout << "GetUnicode()-->" << void_ptr( aLiteralCString.GetUnicode() ) << endl; - cout << "The length of the string \"" << aLiteralCString << "\" is " << aLiteralCString.Length() << endl; // // |nsStdStringWrapper|, i.e., |nsStdCString| // - - nsStdCString aCString("Hello"); - if ( aCString.Length() == 5 ) - cout << "|nsStdCString::Length()| OK" << endl; - else - cout << "|nsStdCString::Length()| FAILED" << endl; - { nsStdCString extracted_middle; CallCMid(extracted_middle, part1+part2a+part2b, 1, 3); @@ -360,15 +424,7 @@ main() } } - cbuffer = aCString.GetBuffer(); - cout << "GetBuffer()-->" << showbase << void_ptr(cbuffer) << endl; - cout << "GetUnicode()-->" << void_ptr( aCString.GetUnicode() ) << endl; - // cout << "The length of the string \"" << static_cast(aCString) << "\" is " << aCString.Length() << endl; - - - nsLiteralCString source("This is a string long enough to be interesting."); - cout << source << endl; nsStdCString leftString; source.Left(leftString, 9); @@ -376,16 +432,16 @@ main() - tests_failed += test_goofy_iterators(part1+part2a+part2b); - + tests_failed += test_multifragment_iterators(part1+part2a+part2b); +#endif - cout << "End of string unit tests. "; + cout << "End of string unit tests." << endl; if ( !tests_failed ) - cout << "All tests OK." << endl; + cout << "OK, all tests passed." << endl; else - cout << "One or more tests FAILED." << endl; + cout << "FAILED one or more tests." << endl; return 0; }