diff options
Diffstat (limited to 'src/tests/xb_test_string.cpp')
-rwxr-xr-x | src/tests/xb_test_string.cpp | 176 |
1 files changed, 113 insertions, 63 deletions
diff --git a/src/tests/xb_test_string.cpp b/src/tests/xb_test_string.cpp index 2f01e51..9dd48af 100755 --- a/src/tests/xb_test_string.cpp +++ b/src/tests/xb_test_string.cpp @@ -188,6 +188,19 @@ int main( int argCnt, char **av = NULL ) s2 = "!@#"; rc += TestMethod( po, "s1.Append( '!@#' )", s1.Append( s2 ), "ABCDEFGZ999!@#", 14 ); + xbString sAppend1; + sAppend1.Append( "abc123", 6 ); + rc += TestMethod( po, "Append", sAppend1, "abc123", 6 ); + + xbString sAppend2; + sAppend2.Append( "abc123", 8 ); + rc += TestMethod( po, "Append", sAppend2, "abc123", 6 ); + + xbString sAppend3; + sAppend3.Append( "abc123", 3 ); + rc += TestMethod( po, "Append", sAppend3, "abc", 3 ); + + rc += TestMethod( po, "s1.Assign( 'ABCDE', 3, 2 )", s1.Assign( "ABCDE", 3, 2 ), "CD", 2 ); rc += TestMethod( po, "s1.Assign( 'ABCDE', 2, 7 )", s1.Assign( "ABCDE", 2, 7 ), "BCDE", 4 ); rc += TestMethod( po, "s1.Assign( 'ABCDE', 1, 4 )", s1.Assign( "ABCDE", 1, 4 ), "ABCD", 4 ); @@ -222,10 +235,24 @@ int main( int argCnt, char **av = NULL ) s1.CvtHexString( s2 ); rc += TestMethod( po, "CvtHexString() ", s2, "abcde", 5 ); - s1 = "123"; - s2 = "ABC"; - rc += TestMethod( po, "HasAlphaChars()", s1.HasAlphaChars(), 0 ); - rc += TestMethod( po, "HasAlphaChars()", s2.HasAlphaChars(), 1 ); + s1.ExtractElement( "aaaa|bbbb|cccc|dddd", '|', 2, 0 ); + rc += TestMethod( po, "ExtractElement() ", s1, "bbbb", 4 ); + + s1.ExtractElement( "aaaa|b'bb|c'ccc|dddd", '|', 3, 1 ); + rc += TestMethod( po, "ExtractElement() ", s1, "dddd", 4 ); + + s1 = "aaaa|bbbb|cccc|dddd"; + s2.ExtractElement( s1, '|', 2, 0 ); + rc += TestMethod( po, "ExtractElement() ", s2, "bbbb", 4 ); + + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'b' ), 8 ); + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'x' ), 9 ); + s1 = "abcabcabx"; + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( '$' ), 0 ); + rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( "ab" ), 7 ); + s1 = "\\ABC\\XYZ"; rc += TestMethod( po, "GetPathSeparator()", s1.GetPathSeparator(), '\\' ); @@ -233,14 +260,36 @@ int main( int argCnt, char **av = NULL ) s1 = "/ABC/XYZ"; rc += TestMethod( po, "GetPathSeparator()", s1.GetPathSeparator(), '/' ); + + s1 = "123"; + s2 = "ABC"; + rc += TestMethod( po, "HasAlphaChars()", s1.HasAlphaChars(), 0 ); + rc += TestMethod( po, "HasAlphaChars()", s2.HasAlphaChars(), 1 ); + + s2 = ""; rc += TestMethod( po, "IsEmpty()", s2.IsEmpty(), 1 ); + + s1.SetNum( (long) 123456 ); + + s1 = "abcZZZ123"; + s1.Left( 4 ); + rc += TestMethod( po, "Left(4) ", s1, "abcZ", 4 ); + + s1.Left( 1 ); + rc += TestMethod( po, "Left(1) ", s1, "a", 1 ); + + s1.Left( 0 ); + rc += TestMethod( po, "Left(0) ", s1, "", 0 ); + // trim tests s1 = " ABC "; rc += TestMethod( po, "Ltrim()", s1.Ltrim(), "ABC ", 6 ); + s1 = " ABC "; rc += TestMethod( po, "Rtrim()", s1.Rtrim(), " ABC", 6 ); + s1 = " ABC "; rc += TestMethod( po, "Trim() ", s1.Trim(), "ABC", 3 ); @@ -253,6 +302,20 @@ int main( int argCnt, char **av = NULL ) s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; rc += TestMethod( po, "Mid(4,5) ", s1.Mid(4,5), "DEFGH", 5 ); + s1 = "123"; + s1.PadLeft( '0', 9 ); + rc += TestMethod( po, "PadLeft() ", s1, "000000123", 9 ); + + s1 = "abc"; + s1.PadRight( 'Z', 9 ); + rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + + s1.PadRight( 'Z', 4 ); + rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + + + + s1 = "DEFGHI"; rc += TestMethod( po, "Pos('G') ", (xbInt32) s1.Pos( 'G' ), 4 ); rc += TestMethod( po, "Pos(\"EFG\") ", (xbInt32) s1.Pos( "EFG" ), 2 ); @@ -269,48 +332,32 @@ int main( int argCnt, char **av = NULL ) s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; rc += TestMethod( po, "Remove(3,5) ", s1.Remove( 3, 5 ), "ABHIJKLMNOPQRSTUVWXYZ", 21 ); + s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + rc += TestMethod( po, "Remove(22,5) ", s1.Remove( 22, 5 ), "ABCDEFGHIJKLMNOPQRSTU", 21 ); + s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + rc += TestMethod( po, "Remove(24,5) ", s1.Remove( 24, 5 ), "ABCDEFGHIJKLMNOPQRSTUVW", 23 ); - s1 = "ABCABCABZ"; - s1.SwapChars( 'A', '9' ); - rc += TestMethod( po, "SwapChars() ", s1, "9BC9BC9BZ", 9 ); - - s1.ToLowerCase(); - rc += TestMethod( po, "ToLowerCase() ", s1, "9bc9bc9bz", 9 ); - - s1.ToUpperCase(); - rc += TestMethod( po, "ToUpperCase() ", s1, "9BC9BC9BZ", 9 ); - - s1.ZapChar( '9' ); - rc += TestMethod( po, "ZapChar('9') ", s1, "BCBCBZ", 6 ); - - s1.ZapLeadingChar( 'B' ); - rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCBZ", 5 ); - - s1.ZapTrailingChar( 'Z' ); - rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCB", 4 ); - - s1.ExtractElement( "aaaa|bbbb|cccc|dddd", '|', 2, 0 ); - rc += TestMethod( po, "ExtractElement() ", s1, "bbbb", 4 ); - - s1.ExtractElement( "aaaa|b'bb|c'ccc|dddd", '|', 3, 1 ); - rc += TestMethod( po, "ExtractElement() ", s1, "dddd", 4 ); - - s1 = "123"; - s1.PadLeft( '0', 9 ); - rc += TestMethod( po, "PadLeft() ", s1, "000000123", 9 ); - - s1 = "abc"; - s1.PadRight( 'Z', 9 ); - rc += TestMethod( po, "PadRight() ", s1, "abcZZZZZZ", 9 ); + s1.Set( "abcdef.dbf" ); + s1.Replace( "def", "DEF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.dbf", 10 ); + s1.Replace( ".dbf", ".DBF" ); + rc += TestMethod( po, "Replace", s1, "abcDEF.DBF", 10 ); + s1.Set( "abcdef.dbf" ); + s1.Replace( "def", "DEFG" ); + rc += TestMethod( po, "Replace", s1, "abcDEFG.dbf", 11 ); + s1.Set( "abcdefdef.dbf" ); + s1.Replace( "def", "DEFG" ); + rc += TestMethod( po, "Replace", s1, "abcDEFGDEFG.dbf", 15 ); - s1.Left( 4 ); - rc += TestMethod( po, "Left(4) ", s1, "abcZ", 4 ); - s1.Left( 1 ); - rc += TestMethod( po, "Left(1) ", s1, "a", 1 ); + s1.SetNum( (long) 123456 ); + rc += TestMethod( po, "SetNum() ", s1, "123456", 6 ); - s1.Left( 0 ); - rc += TestMethod( po, "Left(0) ", s1, "", 0 ); + xbFloat f = (xbFloat) 12.35; + // %f format varies depending on compiler + s1.Sprintf( "%6.2f", f ); + s1.Ltrim(); + rc += TestMethod( po, "s1.Sprintf()/s.Trim()", s1, "12.35", 5 ); char buf[5]; buf[0] = 'W'; @@ -319,18 +366,20 @@ int main( int argCnt, char **av = NULL ) buf[3] = 'Z'; buf[4] = 0x00; xbInt32 l = 1234567; - xbFloat f = (xbFloat) 12.35; s2 = "test string"; rc += TestMethod( po, "s1.Sprintf()", s1.Sprintf( "%s %d %s %ld", buf, 12, s2.Str(), l ), "WXYZ 12 test string 1234567", 27 ); - // %f format varies depending on compiler - s1.Sprintf( "%6.2f", f ); - s1.Ltrim(); - rc += TestMethod( po, "s1.Sprintf()/s.Trim()", s1, "12.35", 5 ); - s1.SetNum( (long) 123456 ); - rc += TestMethod( po, "SetNum() ", s1, "123456", 6 ); + s1 = "ABCABCABZ"; + s1.SwapChars( 'A', '9' ); + rc += TestMethod( po, "SwapChars() ", s1, "9BC9BC9BZ", 9 ); + + s1.ToLowerCase(); + rc += TestMethod( po, "ToLowerCase() ", s1, "9bc9bc9bz", 9 ); + + s1.ToUpperCase(); + rc += TestMethod( po, "ToUpperCase() ", s1, "9BC9BC9BZ", 9 ); s1 = "T"; rc += TestMethod( po, "ValidLogicalValue", s1.ValidLogicalValue(), 1 ); @@ -344,13 +393,19 @@ int main( int argCnt, char **av = NULL ) s1 = "ABC-123456.89"; rc += TestMethod( po, "ValidNumericValue", s1.ValidNumericValue(), 0 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'b' ), 8 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( 'x' ), 9 ); - s1 = "abcabcabx"; - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( '$' ), 0 ); - rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( "ab" ), 7 ); + + s1 = "BC9BC99BZ"; + s1.ZapChar( '9' ); + rc += TestMethod( po, "ZapChar('9') ", s1, "BCBCBZ", 6 ); + + s1.ZapLeadingChar( 'B' ); + rc += TestMethod( po, "ZapLeadingChar('B') ", s1, "CBCBZ", 5 ); + + s1.ZapTrailingChar( 'Z' ); + rc += TestMethod( po, "ZapTrailingChar('Z') ", s1, "CBCB", 4 ); + s1.ZapTrailingChar( 'Z' ); + rc += TestMethod( po, "ZapTrailingChar('Z') ", s1, "CBCB", 4 ); + s1 = ")"; rc += TestMethod( po, "GetLastPos", (xbInt16) s1.GetLastPos( ')' ), 1 ); @@ -385,17 +440,12 @@ int main( int argCnt, char **av = NULL ) s3.Sprintf( "%s and %s", s1.Str(), s2.Str()); rc += TestMethod( po, "Sprintf", s3, "string 1 and string 2.0", 23 ); - s1.Set( "abcdef.dbf" ); - s1.Replace( "def", "DEF" ); - rc += TestMethod( po, "Replace", s1, "abcDEF.dbf", 10 ); - s1.Replace( ".dbf", ".DBF" ); - rc += TestMethod( po, "Replace", s1, "abcDEF.DBF", 10 ); - +/* xbInt16 iErrorStop = 10; xbInt16 iRc = -100; sMsg.Sprintf( "class::method() Exception Caught. Error Stop = [%d] iRc = [%d] Expression = [%s]", iErrorStop, iRc, s3.Str() ); - +*/ if( po > 0 || rc < 0 ) fprintf( stdout, "Total Errors = %d\n", rc * -1 ); |