LOCAL_C void TestAssignmentOperatorL() { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4007")); test.Next(_L("Assignment operator")); TBUF tdes(_TS("Modifiable descriptor")); TBUFC tdesc(_TS("Non-modifiable descriptor")); LSTRING lStr(32); LSTRING lStr2(32); lStr2.CopyL(_TS("Buffer descriptor"), 17); lStr = tdesc; test(lStr == tdesc); lStr = tdes; test(lStr == tdes); lStr = lStr2; test(lStr == lStr2); LSTRING lStr3(tdes); lStr = lStr3.PtrZL(); test(lStr == tdes); test.Next(_L("operator=(char/wchar_t* aCharStr) method")); LSTRING lStr4(_CS("123456")); LSTRING lStr5 = _CS("123456"); test(lStr4 == lStr5); LSTRING lStr6; lStr6 = _CS("123456"); test(lStr4 == lStr6); }
LOCAL_C void TestSwapL(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4006")); LSTRING lStr1, lStr2; TBUF des1(_TS("12")); TBUF des2 (_TS("345678")); TBUF des3 (_TS("12345678")); TBUF swap_des = des2; test.Next(_L("Swap(LString_& aLString) method")); // assignment operation; implies deep copying lStr1 = des1; lStr2 = des2; // swap LStrings with TDes // lStr1 should grow to accommodate swap_des lStr1.SwapL(swap_des); test(lStr1==des2); test(swap_des==des1); // swap two LStrings // lStr2 should grow to accommodate lStr1 lStr1 = des3; lStr1.SwapL(lStr2); test(lStr1==des2); test(lStr2==des3); }
LOCAL_C void TestReadFromStreamL() { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4010")); test.Next(_L("Test creating LString from a stream")); RFs fs; fs.Connect() OR_LEAVE; LSTRING outString = _TS("This is a test string written to a stream"); //Create a buffer to contain the stream CBufFlat* buf = CBufFlat::NewL(outString.MaxLength()); //Create a write stream RBufWriteStream outStream; outStream.Open(*buf); //write some data to the stream outStream << outString; outStream.CommitL(); //Open a readstream RBufReadStream inStream; inStream.Open(*buf); //Create an LString from the stream LSTRING inString; inString.CreateL(inStream,outString.Length()); test(inString == outString); delete buf; }
LOCAL_C void TestAssign(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4002")); TBUF des (_TS("123456")); LSTRING lStr2(des); TTEXT* heap = NULL; RBUF buf; test.Next(_L("Assign(const LString_& aLString) method")); LSTRING lStr; lStr.Assign(lStr2); // the assignment clears lStr2 so the two strings should be unequal test(lStr != lStr2); test.Next(_L("Assign(TUint* aHeapCell, TInt aLength, TInt aMaxLength ) method")); heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16 lStr.Assign(heap, 12,24); test(lStr.Length() == 12); test(lStr.MaxLength() >= 24); heap = NULL; lStr.Assign(heap, 0,0); test(lStr.Length() == 0); test(lStr.MaxLength() == 0); test.Next(_L("Assign(TUint* aHeapCell, TInt aMaxLength ) method")); heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16 lStr.Assign(heap, 24); test(lStr.Length() == 0); test(lStr.MaxLength() >= 24); test.Next(_L("Assign(HBufC_* aHBuf) method")); HBUF* hBuf = HBUF::NewMax(11); lStr.Assign(hBuf); //Create LString as EBufCPtr type test(lStr.Length() == 11); test(lStr.MaxLength() >= 11); //There could me more allocated memory - see HBufC8::Des() HBUF* hBuf2 = HBUF::NewMax(5); lStr = hBuf2; //Create LString as EBufCPtr type test(lStr.Length() == 5); test(lStr.MaxLength() >= 5); //There could me more allocated memory - see HBufC8::Des() test.Next(_L("Assign(const RBuf_& aRBuf) method")); buf.Create(des); lStr.Assign(buf); // the assignment trasnfers buf so the two strings should be equal test(lStr == des); test(lStr != buf); }
void checkdel(void *symtbl, type_kv t, ...) { va_list ap; int n; double d; char *p; list_symtbl_t *st = (list_symtbl_t *)symtbl; va_start(ap, t); switch(t) { case TKVINT: n = va_arg(ap, int); st->del(st, _TI(n)); assert(NULL == st->get(st, _TI(n))); break; case TKVDOUBLE: d = va_arg(ap, double); st->del(st, _TD(d)); assert(NULL == st->get(st, _TD(d))); break; case TKVSTRING: p = va_arg(ap, char *); st->del(st, _TS(p)); assert(NULL == st->get(st, _TS(p))); break; case TKVOBJECT: case TKVNULL: default: ROHERE("not supported type in test."); exit(1); break; } }
LOCAL_C void TestCapacityChangesL(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4008")); test.Next(_L("Test capacity growth and compression on LString")); LSTRING lStr(_TS("0123456")); test(lStr.Length()==7); test(lStr.MaxLength() >=7); lStr.SetMaxLengthL(10); test(lStr.Length()==7); test(lStr.MaxLength() >=10); lStr.SetMaxLengthL(6); test(lStr.Length()==6); test(lStr.MaxLength() >=6); lStr.SetMaxLengthL(10); test(lStr.Length()==6); test(lStr.MaxLength() >=10); //Call the same thing again to check the condition //that required length is already set lStr.SetMaxLengthL(10); test(lStr.Length()==6); test(lStr.MaxLength() >=10); lStr.Compress(); test(lStr.Length()==6); test(lStr.MaxLength() >= 6); //Call the same thing again to check the condition //that the string is already compressed lStr.Compress(); test(lStr.Length()==6); test(lStr.MaxLength() >= 6); lStr.ReserveFreeCapacityL(15); test(lStr.Length()==6); test(lStr.MaxLength() >= 32); lStr.Reset(); test(lStr.Length()==0); test(lStr.MaxLength() == 0); }
LOCAL_C void TestReAllocLeaving(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4005")); test.Next(_L("ReAllocL(TInt aMaxLength) method")); TBUF des(_TS("01")); LSTRING lStr(des); TRAPD(ret, lStr.ReAllocL(6)); //ReAlloc buffer test(KErrNone == ret); #if defined(_DEBUG) __UHEAP_FAILNEXT(1); TRAP(ret, lStr.ReAllocL(100)); //Realloc buffer. This should fail. test(KErrNoMemory == ret); #endif //(_DEBUG) test(lStr.MaxLength() >=6); //Check LString is the same as before ... test(lStr.Length()==2); //... ReAlloc that failed. test(lStr[0] == (TTEXT)('0')); test(lStr[1] == (TTEXT)('1')); }
void AudacityLogger::DoLogText(const wxString & str) { if (!wxIsMainThread()) { wxMutexGuiEnter(); } if (mBuffer.IsEmpty()) { wxString stamp; TimeStamp(&stamp); mBuffer << stamp << _TS("Audacity ") << AUDACITY_VERSION_STRING << wxT("\n"); } mBuffer << str << wxT("\n"); mUpdated = true; Flush(); if (!wxIsMainThread()) { wxMutexGuiLeave(); } }
void checkvalue(void *symtbl, type_kv tkv, ...) { va_list ap; int n; double d; char *p; list_symtbl_t *st = (list_symtbl_t *)symtbl; va_start(ap, tkv); kv_t *kv; switch(tkv) { case TKVINT: n = va_arg(ap, int); kv = st->get(st, _TI(n)); break; case TKVDOUBLE: d = va_arg(ap, double); kv = st->get(st, _TD(d)); break; case TKVSTRING: p = va_arg(ap, char *); kv = st->get(st, _TS(p)); break; case TKVOBJECT: case TKVNULL: default: ROHERE("not supported type in test."); exit(1); break; } tkv = va_arg(ap, int); assert(kv->t == tkv); switch(tkv) { case TKVNULL: break; case TKVINT: n = va_arg(ap, int); break; case TKVDOUBLE: d = va_arg(ap, double); break; case TKVSTRING: p = va_arg(ap, char *); break; case TKVOBJECT: default: ROHERE("not supported type in test."); exit(1); break; } if (NULL == kv && TKVNULL == tkv) return; switch(tkv) { case TKVNULL: break; case TKVINT: assert(kv->o.dint == n); break; case TKVDOUBLE: assert(kv->o.ddouble == d); break; case TKVSTRING: assert(0 == strcmp(kv->o.dstring, p)); break; case TKVOBJECT: default: ROHERE("not supported type in test."); exit(1); break; } return; }
LOCAL_C void TestConstructors(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4001")); test.Next(_L("LString_(const TDesC& aDes) constructor")); const TBUF des (_TS("123456")); const LSTRING lStr(des); test(lStr.Length() == 6); test(lStr.MaxLength() >= 6); test.Next(_L("LString_(const LString16& aDes) constructor")); LSTRING lStr1(lStr); test(lStr1.Length() == 6); test(lStr1.MaxLength() >= 6); test.Next(_L("LString_(const TUInt16* aString) constructor")); LSTRING lStr2(lStr1.PtrZL()); test(lStr2.Length() == 6); test(lStr2.MaxLength() >= 6); test.Next(_L("LString_(HBufC_* aHBuf) constructor")); HBUF* hBuf = HBUF::NewMax(12); //Create LString as EBufCPtr LSTRING lStr3(hBuf); test(lStr3.Length() == 12); test(lStr3.MaxLength() >= 12); hBuf = HBUF::NewMax(0); LSTRING lStr4(hBuf); //The length of aHBuf is zero test(lStr4.Length() == 0); hBuf = NULL; //aHBuf is NULL LSTRING lStr5((HBUF*)hBuf); test(lStr5.Length() == 0); test(lStr5.MaxLength() == 0); test.Next(_L("LString_(TUInt16* aHeapCell, TInt aLength, TInt aMaxLength) constructor")); TTEXT* heap = NULL; heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16 LSTRING lStr6(heap, 12,24); test(lStr6.Length() == 12); test(lStr6.MaxLength() >= 24); test.Next(_L("LString_(TUint* aHeapCell, TInt aMaxLength ) method")); heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16 LSTRING lStr7(heap, 24); test(lStr7.Length() == 0); test(lStr7.MaxLength() >= 24); test.Next(_L("LString_(char/wchar_t * aCharStr) constructor")); LSTRING lStr8(_CS("0123456789")); test(lStr8.Length() == 10); test(lStr8.MaxLength() >= 10); LSTRING lStr9(_CS("01234567890")); test(lStr9.Length() == 11); test(lStr9.MaxLength() >= 11); }
LOCAL_C void TestCharacterStringSupport_Modifiers(LSTRING*) { test.Next (_L ("@SYMTestCaseID:BASESRVCS-EUSERHL-UT-4068")); // 1. test Constructor // Constructs LString object from the supplied null terminated // character string test.Next(_L("LString_(char/wchar_t * aCharStr) constructor")); LSTRING lStr(_CS("0123456789")); test(lStr.Length() == 10); test(lStr.MaxLength() >= 10); test(lStr.Compare(_CS("0123456789")) == 0 ); // try strings ending with 0 LSTRING lStr1(_CS("01234567890")); test(lStr1.Length() == 11); test(lStr1.MaxLength() >= 11); test(lStr1.Compare(_CS("01234567890")) == 0 ); // 2. test '=' operator LSTRING lTestStr; // Assign new string to the constructed LString object test.Next(_L("LString_ operator '=' ")); lTestStr = _CS("Try a New String"); test(lTestStr.Compare(_CS("Try a New String")) == 0 ); test(lTestStr.Length() == 16); test(lTestStr.MaxLength() >= 16); // 3. test '+=' operator // Appends data onto the end of this LString object's data. // The length of this descriptor is incremented to reflect the new content. test.Next(_L("LString_ operator '+=' ")); lTestStr += _CS("!!!"); test(lTestStr.Compare(_CS("Try a New String!!!")) == 0 ); test(lTestStr.Length() == 19); test(lTestStr.MaxLength() >= 19); // 4.Test "Copy()" Variants LSTRING lTestStr1; LSTRING lTestStr2; // Copy new data into the LString object, replacing any existing // data, and expanding its heap buffer to accommodate if necessary. test.Next(_L("LString_ CopyL ")); lTestStr1.CopyL(_TS("Try a New String")); test(lTestStr1.Compare(_TS("Try a New String")) == 0 ); test(lTestStr1.Length() == 16); test(lTestStr1.MaxLength() >= 16); // Copy folded(normalized) content test.Next(_L("LString_ CopyFL ")); lTestStr1.CopyFL(_CS("Some RaNDom STRING")); lTestStr2.CopyFL(_CS("SOME RaNDom string")); test(lTestStr1.Compare(lTestStr2) == 0); // Copy contents in Lower case test.Next(_L("LString_ CopyLCL ")); lTestStr1.CopyLCL(_CS("SOME STRING IN UPPER CASE")); test(lTestStr1 == _CS("some string in upper case")); // Copy contents in Upper case test.Next(_L("LString_ CopyUCL ")); lTestStr1.CopyUCL(_CS("some string in lower case")); test(lTestStr1 == _CS("SOME STRING IN LOWER CASE")); // Copy Capitalized contents test.Next(_L("LString_ CopyCPL ")); lTestStr1.CopyCPL(_CS("some string in lower case")); test(lTestStr1 == _CS("Some string in lower case")); // 5. Test Insert() LSTRING lTestStr3; // Insert contents into a string test.Next(_L("LString_ InsertL ")); lTestStr3 = _CS("Some Content Can Be Into This String"); lTestStr3.InsertL(20,_CS("Inserted ")); test(lTestStr3 == _CS("Some Content Can Be Inserted Into This String")); // 6. Test Replace() LSTRING lTestStr4; // Replace contents form the string test.Next(_L("LString_ ReplaceL ")); lTestStr4 = _CS("Some Content Can Be Decalper"); lTestStr4.ReplaceL(20,8,_CS("Replaced")); test(lTestStr4 == _CS("Some Content Can Be Replaced")); // 7. Test Append() LSTRING lTestStr5; //Append data of specified length, to the end of the LString object. test.Next(_L("LString_ AppendL(src,length)")); lTestStr5.CopyL( _CS("Try appending ")); lTestStr5.AppendL(_CS("Try appending some more"),3); test(lTestStr5 == _CS("Try appending Try")); //Append data , to the end of the LString object. test.Next(_L("LString_ AppendL(src)")); lTestStr5.CopyL( _CS("Try appending ")); lTestStr5.AppendL(_CS("Try appending some more")); test(lTestStr5 == _CS("Try appending Try appending some more")); // 8. Test Justify() LSTRING lTestStr6; //Copy data into this descriptor and justifies it, replacing any existing data test.Next(_L("LString_ JustifyL ")); lTestStr6.CopyL(_CS("Justified")); lTestStr6.JustifyL(_CS("Just"),9,ERight,*(_TS("x"))); test(lTestStr6 == _CS("xxxxxJust")); // 9. Test AppendJustify variants LSTRING lTestStr7; // Append data to the end of the LString object and justify it. test.Next(_L("LString_ AppendJustifyL(const char*,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)")); lTestStr7.CopyL(_CS("One ")); lTestStr7.AppendJustifyL(_CS("Two "),KDefaultJustifyWidth,ERight,*(_TS("x"))); test(lTestStr7 == _TS("One Two ")); lTestStr7.CopyL(_CS("One ")); lTestStr7.AppendJustifyL(_CS("Two Three"),3,7,ERight,*(_TS("x"))); test(lTestStr7 == _CS("One xxxxTwo") ); // Append data to the end of the LString object and justify it. test.Next(_L("LString_ AppendJustifyL(const char* aCharStr,TInt aWidth,TAlign anAlignment,TChar aFill)")); lTestStr7.CopyL(_CS("One ")); lTestStr7.AppendJustifyL(_CS("Two Three"),KDefaultJustifyWidth,ERight,*(_TS("x"))); test(lTestStr7 == _TS("One Two Three")); lTestStr7.CopyL(_CS("One ")); lTestStr7.AppendJustifyL(_CS("Two Three"),13,ERight,*(_TS("x"))); test(lTestStr7 == _CS("One xxxxTwo Three") ); }
LOCAL_C void TestReAllocL(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4004")); test.Next(_L("ReAlloc(TInt aMaxLength) method")); TBUF des (_TS("0123456")); //reallocate EPtr type - decrease memory LSTRING lStr(des); lStr.SetLengthL(3); test(lStr.ReAlloc(3)==KErrNone); //ReAlloc to EPtr test(lStr.MaxLength()>=3); test(lStr.Length()==3); test(lStr[0] == (TTEXT)('0')); test(lStr[2] == (TTEXT)('2')); //reallocate EBufCPtr type - decrease memory HBUF* hBuf = HBUF::NewMax(9); *hBuf = _TS("012345678"); lStr.Assign(hBuf); //Create as EBufCPtr lStr.SetLengthL(5); test(lStr.ReAlloc(5)==KErrNone); //ReAlloc to EBufCPtr test(lStr.MaxLength()>=5);//There could be more allocated memory - see HBufC8::Des() test(lStr.Length()==5); test(lStr[0] == (TTEXT)('0')); test(lStr[4] == (TTEXT)('4')); //reallocate EBufCPtr type - increase memory hBuf = HBUF::NewMax(9); *hBuf = _TS("012345678"); lStr.Assign(hBuf); //Create as EBufCPtr test(lStr.ReAlloc(15)==KErrNone); //ReAlloc to EBufCPtr test(lStr.MaxLength()>=15);//There could be more allocated memory - see HBufC8::Des() test(lStr.Length()==9); test(lStr[0] == (TTEXT)('0')); test(lStr[8] == (TTEXT)('8')); //reallocate EPtr type - to zero-length lStr = des; lStr.SetLengthL(0); test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr test(lStr.MaxLength()==0); test(lStr.Length()==0); //reallocate EBufCPtr type to zero-length hBuf = HBUF::NewMax(9); *hBuf = _TS("012345678"); lStr.Assign(hBuf); //Create as EBufCPtr lStr.SetLengthL(0); test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr test(lStr.MaxLength()==0); test(lStr.Length()==0); //reallocate from zero-length lStr.Reset(); test(lStr.ReAlloc(9)==KErrNone); //ReAlloc to EPtr test(lStr.MaxLength() >=9); test(lStr.Length()==0); //reallocate from zero-length to zero-length lStr.Reset(); test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr test(lStr.Length() == 0); test(lStr.MaxLength() == 0); }
LOCAL_C void TestAppendL(LSTRING*) { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4003")); LSTRING lStr; LSTRING lStr2; TBUF des(_TS("123456")); TBUF des2(_TS("123456A")); test.Next(_L("AppendL(const TDesc_& aDes) method")); lStr.AppendL(des); test(lStr == des); test.Next(_L("AppendL(const TUint16* aBuf, TInt aLength) method")); lStr2 = des; lStr.Reset(); lStr.AppendL(lStr2.PtrZL(),lStr2.Length()); test(lStr == des); test.Next(_L("AppendL(TChar aChar) method")); TChar c = 'A'; lStr = des; lStr.AppendL(c); test(lStr == des2); test.Next(_L("ZeroTerminateL() method")); lStr = des; lStr.ZeroTerminateL(); test(lStr == des); test.Next(_L("AppendL(char/wchar_t* aCharStr) method")); LSTRING lStr3(_CS("0123456789")); test(lStr3.Length() == 10); test(lStr3.MaxLength() >= 10); LSTRING lStr4(_CS("01234567890")); test(lStr4.Length() == 11); test(lStr4.MaxLength() >= 11); lStr3.AppendL(_CS("0"),1); test(lStr3 == lStr4); lStr4.AppendL(_CS("0123456789"),10); test(lStr4.Length() == 21); test(lStr4.MaxLength() >= 21); test.Next(_L("operator + (char/wchar_t* aCharStr) method")); LSTRING lStr5(_CS("0123456789")); test(lStr5.Length() == 10); test(lStr5.MaxLength() >= 10); LSTRING lStr6(_CS("01234567890")); test(lStr6.Length() == 11); test(lStr6.MaxLength() >= 11); lStr5+=_CS("0"); test(lStr5 == lStr6); lStr6 +=_CS("0123456789"); test(lStr6.Length() == 21); test(lStr6.MaxLength() >= 21); }