public void CompareTo() { Substring tss= new Substring(); // null string comparison String nullString= null; UT_TRUE( tss.CompareTo( nullString) == 0 ); UT_TRUE( tss.Equals( nullString) ); tss.Set( "" ); UT_TRUE( tss.CompareTo( nullString) != 0 ); UT_TRUE( !tss.Equals( nullString) ); tss.SetNull(); UT_TRUE( tss.CompareTo( nullString) == 0 ); UT_TRUE( tss.Equals( nullString) ); String t= "abcde"; tss= new Substring("01"+t+"234", 2, t.Length ); int result, resSys; result= tss.CompareTo( t ); UT_EQ( t.CompareTo( t ), result ); result= tss.CompareTo( t + "x" ); UT_EQ( t.CompareTo( t + "x" ), result ); result= tss.CompareTo( t.Substring (0, t.Length -1 ) ); UT_EQ( t.CompareTo( t.Substring (0, t.Length -1 ) ), result ); result= tss.CompareTo( "pad" + t, Case.Sensitive, 3 ); UT_EQ( 0, result ); result= tss.CompareTo( "pad" + t, Case.Sensitive, 3, 2 ); UT_EQ( 1, result ); // greater/smaller strings { String greater= "x"; String greater2= "abcdef"; String smaller= "aaa"; String smaller2= "abcd"; result= tss.CompareTo( greater ); resSys= t.CompareTo( greater ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); String ut= t.ToUpper(); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } { AString greater= new AString( "x" ); AString greater2= new AString( "abcdef" ); AString smaller= new AString( "aaa" ); AString smaller2= new AString( "abcd" ); result= tss.CompareTo( greater ); resSys= t.CompareTo( greater .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); AString ut= new AString (t.ToUpper()); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } { Substring greater= new Substring( "123x" , 3 ); Substring greater2= new Substring( "123abcdef" , 3 ); Substring smaller= new Substring( "123aaa" , 3 ); Substring smaller2= new Substring( "123abcd" , 3 ); result= tss.CompareTo( greater ); resSys= t.CompareTo( greater .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); Substring ut= new Substring( t.ToUpper() ); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } }