зеркало из https://github.com/mozilla/pjs.git
Incremental changes. These files are still not part of the build.
This commit is contained in:
Родитель
09052fa5c9
Коммит
33a17a2d6c
Двоичные данные
xpcom/tests/StringFactoringTests/StringTest.mcp
Двоичные данные
xpcom/tests/StringFactoringTests/StringTest.mcp
Двоичный файл не отображается.
|
@ -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
|
||||
|
|
|
@ -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<CharT>& 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<CharT>)
|
|||
|
||||
|
||||
template <class CharT, class TraitsT, class AllocatorT>
|
||||
const char*
|
||||
const void*
|
||||
basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::Implementation() const
|
||||
{
|
||||
static const char* implementation = "nsStdStringWrapper";
|
||||
|
@ -202,7 +209,10 @@ basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::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<CharT>::Assign(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
template <class CharT, class TraitsT, class AllocatorT>
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <string>
|
||||
#include <iomanip>
|
||||
|
||||
#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 <class T>
|
||||
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<N; ++i )
|
||||
len += TotalLength( s1 + s2 + s3 + s1 + s2 + s3 );
|
||||
}
|
||||
cout << "TotalLength( s1 + s2 + s3 + s1 + s2 + s3 )" << endl;
|
||||
|
@ -111,7 +119,7 @@ test_concat()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
len += TotalLength( s1 + s2 );
|
||||
}
|
||||
cout << "TotalLength( s1 + s2 )" << endl;
|
||||
|
@ -139,14 +147,14 @@ test_concat_and_assign()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
s4 = s1 + s2 + s3 + s1 + s2 + s3;
|
||||
}
|
||||
cout << "s4 = s1 + s2 + s3 + s1 + s2 + s3" << endl;
|
||||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
s4 = s1 + s2;
|
||||
}
|
||||
cout << "s4 = s1 + s2" << endl;
|
||||
|
@ -159,13 +167,13 @@ static
|
|||
int
|
||||
test_compare()
|
||||
{
|
||||
nsCString s1("This is a reasonable length string with some text in it and it is good.");
|
||||
nsCString s2("This is a reasonable length string with some text in it and it is bad.");
|
||||
nsCString s1("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxThis is a reasonable length string with some text in it and it is good.");
|
||||
nsCString s2("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxThis is a reasonable length string with some text in it and it is bad.");
|
||||
|
||||
int count = 0;
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
if ( s1 > s2 )
|
||||
++count;
|
||||
}
|
||||
|
@ -173,7 +181,7 @@ test_compare()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
if ( s1 == s1 )
|
||||
++count;
|
||||
}
|
||||
|
@ -197,7 +205,7 @@ test_countchar()
|
|||
PRUint32 total = 0;
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
total += s1.CountChar('e');
|
||||
}
|
||||
cout << "s1.CountChar('e')" << endl;
|
||||
|
@ -216,7 +224,7 @@ test_append_string()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
{
|
||||
nsCString s3;
|
||||
s3.Append(s1);
|
||||
|
@ -240,7 +248,7 @@ test_repeated_append_string()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<1000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
{
|
||||
nsCString s3;
|
||||
for ( int j=0; j<100; ++j )
|
||||
|
@ -264,7 +272,7 @@ test_repeated_append_char()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<1000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
{
|
||||
nsCString s1;
|
||||
for ( int j=0; j<1000; ++j )
|
||||
|
@ -289,7 +297,7 @@ test_insert_string()
|
|||
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
{
|
||||
nsCString s2("This is another string that I will use in the concatenation test.");
|
||||
s2.Insert(s1, 3);
|
||||
|
@ -312,7 +320,7 @@ test_find_string()
|
|||
PRUint32 position = 0;
|
||||
{
|
||||
TestTimer timer;
|
||||
for ( int i=0; i<100000; ++i )
|
||||
for ( int i=0; i<N; ++i )
|
||||
position = Find(text, pattern);
|
||||
}
|
||||
cout << "text.Find(pattern)" << endl;
|
||||
|
@ -321,9 +329,37 @@ test_find_string()
|
|||
}
|
||||
#endif
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
Profiler()
|
||||
{
|
||||
#if 0
|
||||
ProfilerInit(collectDetailed, bestTimeBase, 100, 32);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Dump( const unsigned char* output_name )
|
||||
{
|
||||
#if 0
|
||||
ProfilerDump(output_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
~Profiler()
|
||||
{
|
||||
#if 0
|
||||
ProfilerDump(mOutputName);
|
||||
ProfilerTerm();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
cout << "String performance profiling. Compiled " __DATE__ " " __TIME__ << endl;
|
||||
#ifdef TEST_STD_STRING
|
||||
cout << "Testing std::string." << endl;
|
||||
|
@ -335,6 +371,8 @@ main()
|
|||
|
||||
int tests_failed = 0;
|
||||
|
||||
Profiler profiler;
|
||||
|
||||
tests_failed += test_concat();
|
||||
tests_failed += test_concat_and_assign();
|
||||
tests_failed += test_compare();
|
||||
|
@ -345,6 +383,14 @@ main()
|
|||
tests_failed += test_insert_string();
|
||||
// tests_failed += test_find_string();
|
||||
|
||||
#ifdef TEST_STD_STRING
|
||||
profiler.Dump("\pStandard String.prof");
|
||||
#elif defined(NEW_STRING_APIS)
|
||||
profiler.Dump("\pFactored String.prof");
|
||||
#else
|
||||
profiler.Dump("\pRaw String.prof");
|
||||
#endif
|
||||
|
||||
if ( tests_failed )
|
||||
cout << "One or more tests FAILED. Measurements may be invalid." << endl;
|
||||
|
||||
|
|
|
@ -3,58 +3,47 @@ using namespace std;
|
|||
|
||||
#include "nsString.h"
|
||||
#include "nsStdStringWrapper.h"
|
||||
#include "nsLiteralString.h"
|
||||
|
||||
#define NS_USE_WCHAR_T
|
||||
|
||||
#if 0
|
||||
static
|
||||
void
|
||||
Call_ToLowerCase( const nsAReadableCString& aSource, nsAWritableCString& aResult )
|
||||
{
|
||||
aSource.ToLowerCase(aResult);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
Call_ToUpperCase( const nsAReadableCString& aSource, nsAWritableCString& aResult )
|
||||
{
|
||||
aSource.ToUpperCase(aResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
static
|
||||
ostream&
|
||||
print_string( const nsAReadableString& s, ostream& os = std::cout )
|
||||
print_string( const nsAReadableString& s )
|
||||
{
|
||||
struct PRUnichar_to_char
|
||||
{
|
||||
char operator()( PRUnichar c ) { return char(c); }
|
||||
};
|
||||
|
||||
transform(s.Begin(), s.End(), ostream_iterator<char>(os), PRUnichar_to_char());
|
||||
return os;
|
||||
transform(s.Begin(), s.End(), ostream_iterator<char>(cout), PRUnichar_to_char());
|
||||
return cout;
|
||||
}
|
||||
|
||||
|
||||
template <class CharT>
|
||||
basic_nsLiteralString<CharT>
|
||||
make_a_hello_string( CharT* )
|
||||
literal_hello( CharT* )
|
||||
{
|
||||
}
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
basic_nsLiteralString<char>
|
||||
make_a_hello_string( char* )
|
||||
literal_hello( char* )
|
||||
{
|
||||
return basic_nsLiteralString<char>("Hello");
|
||||
}
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
basic_nsLiteralString<PRUnichar>
|
||||
make_a_hello_string( PRUnichar* )
|
||||
literal_hello( PRUnichar* )
|
||||
{
|
||||
#ifdef NS_USE_WCHAR_T
|
||||
return basic_nsLiteralString<PRUnichar>(L"Hello");
|
||||
#else
|
||||
static PRUnichar constant_unicode[] = { 'H', 'e', 'l', 'l', 'o', PRUnichar() };
|
||||
return basic_nsLiteralString<PRUnichar>(constant_unicode);
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -68,128 +57,15 @@ CallCMid( nsAWritableCString& aResult, const nsAReadableCString& aSource, PRUint
|
|||
|
||||
template <class CharT>
|
||||
int
|
||||
readable_hello_tests( const basic_nsAReadableString<CharT>& str, ostream& os = std::cout )
|
||||
{
|
||||
int tests_failed = 0;
|
||||
test_multifragment_iterators( const basic_nsAReadableString<CharT>& 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<CharT>::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<CharT>::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<CharT>::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 <class CharT>
|
||||
int
|
||||
test_goofy_iterators( const basic_nsAReadableString<CharT>& 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<CharT>::ConstIterator ConstIterator;
|
||||
|
||||
|
@ -204,13 +80,196 @@ test_goofy_iterators( const basic_nsAReadableString<CharT>& 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 <class CharT>
|
||||
int
|
||||
test_deprecated_GetBufferGetUnicode( const basic_nsAReadableString<CharT>& 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<char>& 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<PRUnichar>& 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 <class CharT>
|
||||
int
|
||||
test_readable_hello( const basic_nsAReadableString<CharT>& 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<CharT>::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<CharT>::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<CharT>::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 <class CharT>
|
||||
int
|
||||
test_writable( basic_nsAWritableString<CharT>& 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<nsAReadableCString>(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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче