56 @SYMTestPriority Medium |
53 @SYMTestPriority Medium |
57 @SYMTestActions Tests for CnvUtfConverter::ConvertToUnicodeFromUtf7() function |
54 @SYMTestActions Tests for CnvUtfConverter::ConvertToUnicodeFromUtf7() function |
58 @SYMTestExpectedResults Test must not fail |
55 @SYMTestExpectedResults Test must not fail |
59 @SYMREQ REQ0000 |
56 @SYMREQ REQ0000 |
60 */ |
57 */ |
61 GLDEF_C TInt E32Main() |
58 void CT_COMP7::TestCOMP7() |
62 { |
59 { |
63 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0565 Comparing behaviour with the Unicode CD-ROM UTF-7 sample code ")); |
60 INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0565 Comparing behaviour with the Unicode CD-ROM UTF-7 sample code ")); |
64 TDes16* originalUnicode=new TBuf16<512>; |
61 TDes16* originalUnicode=new TBuf16<512>; |
65 TDes8* generatedUtf7=new TBuf8<1024>; |
62 TDes8* generatedUtf7=new TBuf8<1024>; |
66 TDes8* otherGeneratedUtf7=new TBuf8<1024>; |
63 TDes8* otherGeneratedUtf7=new TBuf8<1024>; |
67 TDes16* generatedUnicode=new TBuf16<512>; |
64 TDes16* generatedUnicode=new TBuf16<512>; |
68 TDes16* otherGeneratedUnicode=new TBuf16<512>; |
65 TDes16* otherGeneratedUnicode=new TBuf16<512>; |
83 EUtf7FlagOtherOptional =0x00000002, |
80 EUtf7FlagOtherOptional =0x00000002, |
84 EUtf7FlagOtherVerbose =0x00000004, |
81 EUtf7FlagOtherVerbose =0x00000004, |
85 EUtf7FlagCrossOver =0x00000008, |
82 EUtf7FlagCrossOver =0x00000008, |
86 EUtf7FlagDone =0x00000010 |
83 EUtf7FlagDone =0x00000010 |
87 }; |
84 }; |
88 TheTest.Next(_L("Round-trips via UTF-7")); |
85 INFO_PRINTF1(_L("Round-trips via UTF-7")); |
89 for (TInt i=0; ~i&EUtf7FlagDone; ++i) |
86 for (TInt i=0; ~i&EUtf7FlagDone; ++i) |
90 { |
87 { |
91 TEST(CnvUtfConverter::ConvertFromUnicodeToUtf7(*generatedUtf7, *originalUnicode, i&EUtf7FlagOptional)==0); |
88 test(CnvUtfConverter::ConvertFromUnicodeToUtf7(*generatedUtf7, *originalUnicode, i&EUtf7FlagOptional)==0); |
92 {__ASSERT_ALWAYS(originalUnicode->Length()<originalUnicode->MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer1)); |
89 {__ASSERT_ALWAYS(originalUnicode->Length()<originalUnicode->MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer1)); |
93 TUint16* sourceStart=CONST_CAST(TUint16*, originalUnicode->Ptr()); |
90 TUint16* sourceStart=CONST_CAST(TUint16*, originalUnicode->Ptr()); |
94 TUint16* sourceEnd=sourceStart+originalUnicode->Length(); |
91 TUint16* sourceEnd=sourceStart+originalUnicode->Length(); |
95 char* targetStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr())); |
92 char* targetStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr())); |
96 char* targetEnd=targetStart+(otherGeneratedUtf7->MaxLength()-1); |
93 char* targetEnd=targetStart+(otherGeneratedUtf7->MaxLength()-1); |
97 TEST(ConvertUCS2toUTF7(&sourceStart, sourceEnd, &targetStart, targetEnd, i&EUtf7FlagOtherOptional, i&EUtf7FlagOtherVerbose)==ok); |
94 test(ConvertUCS2toUTF7(&sourceStart, sourceEnd, &targetStart, targetEnd, i&EUtf7FlagOtherOptional, i&EUtf7FlagOtherVerbose)==ok); |
98 otherGeneratedUtf7->SetLength(targetStart-REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr())));} |
95 otherGeneratedUtf7->SetLength(targetStart-REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherGeneratedUtf7->Ptr())));} |
99 TDes8& sourceForReturnTrip=(i&EUtf7FlagCrossOver)? *otherGeneratedUtf7: *generatedUtf7; |
96 TDes8& sourceForReturnTrip=(i&EUtf7FlagCrossOver)? *otherGeneratedUtf7: *generatedUtf7; |
100 TDes8& otherSourceForReturnTrip=(i&EUtf7FlagCrossOver)? *generatedUtf7: *otherGeneratedUtf7; |
97 TDes8& otherSourceForReturnTrip=(i&EUtf7FlagCrossOver)? *generatedUtf7: *otherGeneratedUtf7; |
101 TEST(CnvUtfConverter::ConvertToUnicodeFromUtf7(*generatedUnicode, sourceForReturnTrip, state)==0); |
98 test(CnvUtfConverter::ConvertToUnicodeFromUtf7(*generatedUnicode, sourceForReturnTrip, state)==0); |
102 TEST(state==CnvUtfConverter::KStateDefault); |
99 test(state==CnvUtfConverter::KStateDefault); |
103 {__ASSERT_ALWAYS(otherSourceForReturnTrip.Length()<otherSourceForReturnTrip.MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer2)); |
100 {__ASSERT_ALWAYS(otherSourceForReturnTrip.Length()<otherSourceForReturnTrip.MaxLength(), Panic(EPanicNoFreeSpaceAtEndOfBuffer2)); |
104 char* sourceStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherSourceForReturnTrip.Ptr())); |
101 char* sourceStart=REINTERPRET_CAST(char*, CONST_CAST(TUint8*, otherSourceForReturnTrip.Ptr())); |
105 char* sourceEnd=sourceStart+otherSourceForReturnTrip.Length(); |
102 char* sourceEnd=sourceStart+otherSourceForReturnTrip.Length(); |
106 TUint16* targetStart=CONST_CAST(TUint16*, otherGeneratedUnicode->Ptr()); |
103 TUint16* targetStart=CONST_CAST(TUint16*, otherGeneratedUnicode->Ptr()); |
107 TUint16* targetEnd=targetStart+(otherGeneratedUnicode->MaxLength()-1); |
104 TUint16* targetEnd=targetStart+(otherGeneratedUnicode->MaxLength()-1); |
108 TEST(ConvertUTF7toUCS2(&sourceStart, sourceEnd, &targetStart, targetEnd)==ok); |
105 test(ConvertUTF7toUCS2(&sourceStart, sourceEnd, &targetStart, targetEnd)==ok); |
109 otherGeneratedUnicode->SetLength(targetStart-otherGeneratedUnicode->Ptr());} |
106 otherGeneratedUnicode->SetLength(targetStart-otherGeneratedUnicode->Ptr());} |
110 TEST(*generatedUnicode==*originalUnicode); |
107 test(*generatedUnicode==*originalUnicode); |
111 TEST(*generatedUnicode==*otherGeneratedUnicode); |
108 test(*generatedUnicode==*otherGeneratedUnicode); |
112 } |
109 } |
113 // |
110 // |
114 delete originalUnicode; |
111 delete originalUnicode; |
115 delete generatedUtf7; |
112 delete generatedUtf7; |
116 delete otherGeneratedUtf7; |
113 delete otherGeneratedUtf7; |
117 delete generatedUnicode; |
114 delete generatedUnicode; |
118 delete otherGeneratedUnicode; |
115 delete otherGeneratedUnicode; |
119 |
116 |
120 TheTest.End(); |
|
121 TheTest.Close(); |
|
122 |
|
123 return KErrNone; |
|
124 } |
117 } |
125 |
118 |
|
119 CT_COMP7::CT_COMP7() |
|
120 { |
|
121 SetTestStepName(KTestStep_T_COMP7); |
|
122 } |
|
123 |
|
124 TVerdict CT_COMP7::doTestStepL() |
|
125 { |
|
126 SetTestStepResult(EFail); |
|
127 |
|
128 __UHEAP_MARK; |
|
129 |
|
130 TRAPD(error1, TestCOMP7()); |
|
131 |
|
132 __UHEAP_MARKEND; |
|
133 |
|
134 if(error1 == KErrNone ) |
|
135 { |
|
136 SetTestStepResult(EPass); |
|
137 } |
|
138 |
|
139 return TestStepResult(); |
|
140 } |