kerneltest/e32test/buffer/t_buf.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
    72 #include <e32math.h>
    72 #include <e32math.h>
    73 #include <hal.h>
    73 #include <hal.h>
    74 #include <hal_data.h>
    74 #include <hal_data.h>
    75 #include <hal_data.h>
    75 #include <hal_data.h>
    76 #include <e32svr.h>
    76 #include <e32svr.h>
    77 #include <collate.h> 
       
    78 
    77 
    79 #ifdef __VC32__
    78 #ifdef __VC32__
    80     // Solve compilation problem caused by non-English locale
    79     // Solve compilation problem caused by non-English locale
    81     #pragma setlocale("english")
    80     #pragma setlocale("english")
    82 #endif
    81 #endif
   298 	a.Justify(b,10,ELeft,' ');
   297 	a.Justify(b,10,ELeft,' ');
   299 	b.Fill('A',2);
   298 	b.Fill('A',2);
   300 	a.Zero();
   299 	a.Zero();
   301 	a.AppendJustify(_TL("AB"),10,ELeft,' ');
   300 	a.AppendJustify(_TL("AB"),10,ELeft,' ');
   302 	a.AppendJustify(b,10,ELeft,' ');
   301 	a.AppendJustify(b,10,ELeft,' ');
   303 	a.AppendJustify(b,10,KDefaultJustifyWidth,ELeft,' ');
       
   304 	a.AppendJustify(b.Ptr(),10,ELeft,' ');
       
   305 	
       
   306 	TInt v1=10;
   302 	TInt v1=10;
   307 	a.Num(v1);
   303 	a.Num(v1);
   308 	a.AppendNum(v1);
   304 	a.AppendNum(v1);
   309 	TInt v2=10;
   305 	TInt v2=10;
   310 	a.Num((TUint)v2,EHex);
   306 	a.Num((TUint)v2,EHex);
   311 	a.AppendNum((TUint)v2,EHex);
   307 	a.AppendNum((TUint)v2,EHex);
   312 	a.NumUC((TUint)v2,EHex);
   308 	a.NumUC((TUint)v2,EHex);
   313 	a.AppendNumUC((TUint)v2,EHex);
   309 	a.AppendNumUC((TUint)v2,EHex);
   314 	
       
   315 	//Converts the specified unsigned integer into a fixed width character representation
       
   316 	//based on the specified number system and copies the conversion into this descriptor,
       
   317 	//replacing any existing data. The length of this descriptor is set to reflect the new data.
       
   318 	a.NumFixedWidth(v1,EBinary,4); 
       
   319 	a.NumFixedWidth(v1,EOctal,3);
       
   320 	a.NumFixedWidth(v1,EDecimal,2);
       
   321 	a.NumFixedWidth(v1,EHex,1);
       
   322 	//When a hexadecimal conversion is specified, hexadecimal characters are in upper case.
       
   323 	a.NumFixedWidthUC(v1,EBinary,4);
       
   324 	a.NumFixedWidthUC(v1,EOctal,3);
       
   325 	a.NumFixedWidthUC(v1,EDecimal,2);
       
   326 	a.NumFixedWidthUC(v1,EHex,1);
       
   327 	//Appends the conversion onto the end of this descriptor's data.
       
   328 	a.AppendNumFixedWidthUC(v1,EBinary,4);
       
   329 	a.AppendNumFixedWidthUC(v1,EOctal,3);
       
   330 	a.AppendNumFixedWidthUC(v1,EDecimal,2);
       
   331 	a.AppendNumFixedWidthUC(v1,EHex,1); 
       
   332 	
       
   333 	TReal v3=10.0;
   310 	TReal v3=10.0;
   334 	TRealFormat ff;
   311 	TRealFormat ff;
   335 	ff.iType=KRealFormatFixed;
   312 	ff.iType=KRealFormatFixed;
   336 	ff.iWidth=10;
   313 	ff.iWidth=10;
   337 	ff.iPlaces=2;
   314 	ff.iPlaces=2;
  1380 
  1357 
  1381 // Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
  1358 // Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
  1382 #if !(defined(__GCC32__) && defined(__X86__))
  1359 #if !(defined(__GCC32__) && defined(__X86__))
  1383 	const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E");
  1360 	const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E");
  1384 	const TInt dummyParameter=0;
  1361 	const TInt dummyParameter=0;
  1385 #ifdef __ARMCC__
       
  1386 #pragma push
       
  1387 #pragma diag_suppress 1446 
       
  1388 #endif
       
  1389 	Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd);
  1362 	Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd);
  1390 #ifdef __ARMCC__
       
  1391 #pragma pop
       
  1392 #endif
       
  1393 #endif
  1363 #endif
  1394 
  1364 
  1395 	test.Next(_L("Print some numbers"));
  1365 	test.Next(_L("Print some numbers"));
  1396 	TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u);
  1366 	TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u);
  1397 	test.Printf(_L("    %%ld: %ld\n"),TI64);
  1367 	test.Printf(_L("    %%ld: %ld\n"),TI64);
  1596 	aa.Format(_L("x%5.1fx"), 1.99);
  1566 	aa.Format(_L("x%5.1fx"), 1.99);
  1597 	test(aa==_L("x  2.0x"));
  1567 	test(aa==_L("x  2.0x"));
  1598 
  1568 
  1599 // Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
  1569 // Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
  1600 #if !(defined(__GCC32__) && defined(__X86__))
  1570 #if !(defined(__GCC32__) && defined(__X86__))
  1601 #ifdef __ARMCC__
       
  1602 #pragma push
       
  1603 #pragma diag_suppress 1446 
       
  1604 #endif
       
  1605 	aa.Format(_L("x%- 5Fx"), TRealX(6.2345678));
  1571 	aa.Format(_L("x%- 5Fx"), TRealX(6.2345678));
  1606 	test(aa==_L("x6.234568x"));
  1572 	test(aa==_L("x6.234568x"));
  1607 	aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678));
  1573 	aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678));
  1608 	test(aa==_L("x6.234568x"));
  1574 	test(aa==_L("x6.234568x"));
  1609 	aa.Format(_L("x% 5Fx"), TRealX(6.2345678));
  1575 	aa.Format(_L("x% 5Fx"), TRealX(6.2345678));
  1630 	test(aa==_L("x12,345,352,342.545000x"));
  1596 	test(aa==_L("x12,345,352,342.545000x"));
  1631 	aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789));
  1597 	aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789));
  1632 	test(aa==_L("x         1.012345679x"));
  1598 	test(aa==_L("x         1.012345679x"));
  1633 	aa.Format(_L("x%5.1Fx"), TRealX(1.99));
  1599 	aa.Format(_L("x%5.1Fx"), TRealX(1.99));
  1634 	test(aa==_L("x  2.0x"));
  1600 	test(aa==_L("x  2.0x"));
  1635 #ifdef __ARMCC__	
       
  1636 #pragma pop
       
  1637 #endif
       
  1638 #endif
  1601 #endif
  1639 
  1602 
  1640 	aa.Format(_L("x%- 5ex"), 6.2345678);
  1603 	aa.Format(_L("x%- 5ex"), 6.2345678);
  1641 	test(aa==_L("x6.234568E+00x"));
  1604 	test(aa==_L("x6.234568E+00x"));
  1642 	aa.Format(_L("x%+ 5ex"), 6.2345678);
  1605 	aa.Format(_L("x%+ 5ex"), 6.2345678);
  1916 	test(err == KErrNone);
  1879 	test(err == KErrNone);
  1917 	
  1880 	
  1918 	lang = User::Language();
  1881 	lang = User::Language();
  1919 	test(lang == defaultLang);
  1882 	test(lang == defaultLang);
  1920 	}
  1883 	}
  1921 
       
  1922 // Test the surrogate aware version functions of the class. 
       
  1923 GLDEF_C void SurrogateAware1()
       
  1924     {
       
  1925     test.Start(_L("Constructors"));
       
  1926     TBuf16<0x50> a;
       
  1927     TBuf16<0x50> b;
       
  1928     TBuf16<0x50> c;
       
  1929     TBuf16<0x50> d;
       
  1930     
       
  1931     a=_L("ABCD");
       
  1932     b=_L("abcd");
       
  1933     // Cannot define these on GCC (X86).
       
  1934 	#if !(defined(__GCC32__) && defined(__X86__))
       
  1935     c=_L("àáâãäåçèéêëìíîïñòóôõöùúûüý");
       
  1936     d=_L("ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ");
       
  1937     #else
       
  1938     c=_L("aaaaaaceeeeiiiinooooouuuuy");
       
  1939     d=_L("AAAAAACEEEEIIIINOOOOOUUUUY");
       
  1940     #endif
       
  1941  
       
  1942     test.Next(_L("Fill2"));
       
  1943     TInt maxBufLength=a.MaxLength();
       
  1944     a.Fill2(' ');
       
  1945     a.Fill2(' ',maxBufLength);
       
  1946     a.Fill2('z');
       
  1947     a.Fill2('*',maxBufLength);
       
  1948     a=c;
       
  1949     b=d;
       
  1950     a.Swap(b);
       
  1951     test(a==d);
       
  1952 
       
  1953     test.Next(_L("Conversion 2"));
       
  1954     a.Fold2();
       
  1955     b.Collate2();
       
  1956     a.UpperCase2();
       
  1957     a.LowerCase2();
       
  1958     a.Capitalize2();
       
  1959     b.Capitalize2();
       
  1960     
       
  1961     test.Next(_L("Locating"));
       
  1962     a=_L("ABCDabcd");
       
  1963     test(a.Locate('A')==0);
       
  1964     test(a.LocateF('b')==1);
       
  1965     test(a.LocateReverse('A')==0);
       
  1966     test(a.LocateReverse('a')==4);
       
  1967     test(a.LocateReverse('b')==5);
       
  1968 
       
  1969     test.Next(_L("Copying"));
       
  1970     a.Copy(b); // Copies a 16 bit descriptor
       
  1971     a.Copy(_L("AB")); 
       
  1972     a.Copy(b.Ptr(),3); // Copies aLength characters from the aBuf pointer
       
  1973     a.CopyF2(c); // Copies and folds
       
  1974     a.CopyF2(_L("AB"));
       
  1975     a.CopyC2(d); // Copies and collates
       
  1976     a.CopyC2(_L("AB"));
       
  1977     a.CopyLC(d); // Copies and converts the text to lower case
       
  1978     a.CopyLC(_L("AB"));
       
  1979     a.CopyUC2(c); // Copies and converts the text to upper case
       
  1980     a.CopyUC2(_L("AB"));
       
  1981     a.CopyCP2(b); // Copies and capitalizes the text
       
  1982     a.CopyCP2(_L("AB"));
       
  1983     
       
  1984     test.Next(_L("Finding"));
       
  1985     a=_L("ABCDabcd");
       
  1986     b=_L("bc");
       
  1987     test(a.Find(b)==5);
       
  1988     test(a.Find(_L("ab"))==4);
       
  1989     test(a.FindF(b)==1);
       
  1990     test(a.FindF(_L("ab"))==0);
       
  1991     test(a.FindC(b)==1);
       
  1992     test(a.FindC(_L("AB"))==0);
       
  1993     test(a.FindC(b.Ptr(), b.Length(), 3)==1);
       
  1994     test(a.FindC(b.Ptr(), b.Length(), 2)==1);
       
  1995     test(a.FindC(b.Ptr(), b.Length(), 1)==1);
       
  1996     test(a.FindC(b.Ptr(), b.Length(), 0)==1); 
       
  1997     test(a.FindF(b.Ptr(), b.Length())==1);
       
  1998     
       
  1999     test.Next(_L("Formating"));
       
  2000     TInt width = 10;
       
  2001     a.Justify2(_L("AB"),width,ELeft,' ');
       
  2002     a.Justify2(b,10,ELeft,' ');
       
  2003     b.Fill2('A',2);
       
  2004     a.Zero();
       
  2005     a.AppendJustify2(_L("AB"),width,ELeft,' ');
       
  2006     a.AppendJustify2(b,width,ELeft,' ');
       
  2007     a=_L("ABCDE");
       
  2008     b=_L("abcde");
       
  2009     a.AppendJustify2(b,width,ELeft,'*');
       
  2010     a.AppendJustify2(b.Ptr(),width,ELeft,'*');
       
  2011     // Append and justify with explicit length
       
  2012     TInt length = 5;
       
  2013     a.AppendJustify2(b,length,KDefaultJustifyWidth,ELeft,'*');
       
  2014     a.AppendJustify2(b.Ptr(),length,KDefaultJustifyWidth,ELeft,'*');
       
  2015     
       
  2016     TCollationMethod cm = *Mem::CollationMethodByIndex( 0 ); // default collation method
       
  2017     cm.iFlags |= TCollationMethod::EIgnoreNone;
       
  2018     TDesC::TPrefix prefix = a.HasPrefixC(a, 0, &cm);
       
  2019     test(prefix==TDesC16::EIsPrefix);
       
  2020     test.End();
       
  2021     }
       
  2022 
       
  2023 // Test the surrogate aware versions of conversion operators (test7) 
       
  2024 // 
       
  2025 void SurrogateAware7()
       
  2026     {
       
  2027     test.Start(_L("Fold2, Collate2 ..."));
       
  2028     TBuf16<0x50> a;
       
  2029     TBuf16<0x50> b;
       
  2030     a=_L("abc AbC");
       
  2031     b=_L("ABC ABC");
       
  2032     a.Fold2();
       
  2033     b.Fold2();
       
  2034     test(a==b);
       
  2035     a=_L("abc AbC");
       
  2036     b=_L("ABC ABC");
       
  2037     a.Collate2();
       
  2038     b.Collate2();
       
  2039     test(a==b);
       
  2040     a.UpperCase2();
       
  2041     test(a==_L("ABC ABC"));
       
  2042     a.LowerCase2();
       
  2043     test(a==_L("abc abc"));
       
  2044     a.Capitalize2();
       
  2045     test(a==_L("Abc abc"));
       
  2046     test.End();
       
  2047     }
       
  2048 
       
  2049 #ifndef _DEBUG
  1884 #ifndef _DEBUG
  2050 #pragma warning( disable : 4702) //Unreachable code
  1885 #pragma warning( disable : 4702) //Unreachable code
  2051 #pragma warning( disable : 4710) //Function not expanded
  1886 #pragma warning( disable : 4710) //Function not expanded
  2052 #endif
  1887 #endif
  2053 GLDEF_C TInt E32Main()
  1888 GLDEF_C TInt E32Main()
  2079 	test.Next(_L("Test Format ignore overflow handler"));
  1914 	test.Next(_L("Test Format ignore overflow handler"));
  2080 	testAppendFormatIgnoreOverflow();
  1915 	testAppendFormatIgnoreOverflow();
  2081 
  1916 
  2082 	test.Next(_L("INC061330"));
  1917 	test.Next(_L("INC061330"));
  2083 	INC061330();
  1918 	INC061330();
  2084 	
       
  2085 	test.Next(_L("Surrogate aware version"));
       
  2086 	SurrogateAware1();
       
  2087 	    
       
  2088 	test.Next(_L("Surrogate aware version"));
       
  2089 	SurrogateAware7();
       
  2090 
  1919 
  2091 	test.End();
  1920 	test.End();
  2092 
  1921 
  2093 	return(KErrNone);
  1922 	return(KErrNone);
  2094     }
  1923     }