kerneltest/e32test/buffer/t_buf.cpp
changeset 247 d8d70de2bd36
parent 109 b3a1d9898418
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
    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> 
    77 
    78 
    78 #ifdef __VC32__
    79 #ifdef __VC32__
    79     // Solve compilation problem caused by non-English locale
    80     // Solve compilation problem caused by non-English locale
    80     #pragma setlocale("english")
    81     #pragma setlocale("english")
    81 #endif
    82 #endif
   297 	a.Justify(b,10,ELeft,' ');
   298 	a.Justify(b,10,ELeft,' ');
   298 	b.Fill('A',2);
   299 	b.Fill('A',2);
   299 	a.Zero();
   300 	a.Zero();
   300 	a.AppendJustify(_TL("AB"),10,ELeft,' ');
   301 	a.AppendJustify(_TL("AB"),10,ELeft,' ');
   301 	a.AppendJustify(b,10,ELeft,' ');
   302 	a.AppendJustify(b,10,ELeft,' ');
       
   303 	a.AppendJustify(b,10,KDefaultJustifyWidth,ELeft,' ');
       
   304 	a.AppendJustify(b.Ptr(),10,ELeft,' ');
       
   305 	
   302 	TInt v1=10;
   306 	TInt v1=10;
   303 	a.Num(v1);
   307 	a.Num(v1);
   304 	a.AppendNum(v1);
   308 	a.AppendNum(v1);
   305 	TInt v2=10;
   309 	TInt v2=10;
   306 	a.Num((TUint)v2,EHex);
   310 	a.Num((TUint)v2,EHex);
   307 	a.AppendNum((TUint)v2,EHex);
   311 	a.AppendNum((TUint)v2,EHex);
   308 	a.NumUC((TUint)v2,EHex);
   312 	a.NumUC((TUint)v2,EHex);
   309 	a.AppendNumUC((TUint)v2,EHex);
   313 	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 	
   310 	TReal v3=10.0;
   333 	TReal v3=10.0;
   311 	TRealFormat ff;
   334 	TRealFormat ff;
   312 	ff.iType=KRealFormatFixed;
   335 	ff.iType=KRealFormatFixed;
   313 	ff.iWidth=10;
   336 	ff.iWidth=10;
   314 	ff.iPlaces=2;
   337 	ff.iPlaces=2;
  1893 	test(err == KErrNone);
  1916 	test(err == KErrNone);
  1894 	
  1917 	
  1895 	lang = User::Language();
  1918 	lang = User::Language();
  1896 	test(lang == defaultLang);
  1919 	test(lang == defaultLang);
  1897 	}
  1920 	}
       
  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 
  1898 #ifndef _DEBUG
  2049 #ifndef _DEBUG
  1899 #pragma warning( disable : 4702) //Unreachable code
  2050 #pragma warning( disable : 4702) //Unreachable code
  1900 #pragma warning( disable : 4710) //Function not expanded
  2051 #pragma warning( disable : 4710) //Function not expanded
  1901 #endif
  2052 #endif
  1902 GLDEF_C TInt E32Main()
  2053 GLDEF_C TInt E32Main()
  1928 	test.Next(_L("Test Format ignore overflow handler"));
  2079 	test.Next(_L("Test Format ignore overflow handler"));
  1929 	testAppendFormatIgnoreOverflow();
  2080 	testAppendFormatIgnoreOverflow();
  1930 
  2081 
  1931 	test.Next(_L("INC061330"));
  2082 	test.Next(_L("INC061330"));
  1932 	INC061330();
  2083 	INC061330();
       
  2084 	
       
  2085 	test.Next(_L("Surrogate aware version"));
       
  2086 	SurrogateAware1();
       
  2087 	    
       
  2088 	test.Next(_L("Surrogate aware version"));
       
  2089 	SurrogateAware7();
  1933 
  2090 
  1934 	test.End();
  2091 	test.End();
  1935 
  2092 
  1936 	return(KErrNone);
  2093 	return(KErrNone);
  1937     }
  2094     }