Compare() public static method

public static Compare ( byte a, byte b ) : int
a byte
b byte
return int
Example #1
0
 /// <summary>
 /// Compares <paramref name="count" /> characters of the
 /// string against <paramref name="str" />.
 /// </summary>
 public int Compare(string str, int count)
 {
     return(ByteString.Compare(Pointer, str, count));
 }
Example #2
0
        public static void __Test1()
        {
            byte *ptr1 = (byte *)Stubs.CString("US"), ptr2 = (byte *)Stubs.CString("SK");
            byte *longer = (byte *)Stubs.CString("The US");

            //Test constant CString buffers
            Testcase.Test(ByteString.Compare(ptr1, ptr2) != 0,
                          "ByteString.Compare()",
                          "Comparing: 'US' != 'SK'");

            Testcase.Test(ByteString.Compare(ptr1, ptr1) == 0,
                          "ByteString.Compare()",
                          "Comparing: 'US' == 'US'");

            Testcase.Test(ByteString.Compare(ptr1, 1, ptr1, 1, 1) == 0,
                          "ByteString.Compare()",
                          "Comparing substrings: 'U[S]' == 'U[S]'");

            Testcase.Test(ByteString.Compare(longer, 4, ptr1, 0, 2) == 0,
                          "ByteString.Compare()",
                          "Comparing substrings: 'The [US]' == 'US'");

            Testcase.Test(ByteString.Compare(longer, 4, ptr1, 0, 0) == 0,
                          "ByteString.Compare()",
                          "Comparing substrings: 'The [US]' == 'US' (count=0)");

            //Test constant CString buffer with constant String type

            Testcase.Test(ByteString.Compare(ptr1, "SK") != 0,
                          "ByteString.Compare()",
                          "Comparing byte* and string constant: 'US' != const 'SK'");

            Testcase.Test(ByteString.Compare(ptr1, "US") == 0,
                          "ByteString.Compare()",
                          "Comparing byte* and string constant: 'US' == const 'US'");

            Testcase.Test(ByteString.Compare(longer, 4, "US", 0, 2) == 0,
                          "ByteString.Compare()",
                          "Comparing byte* substring and string constant: 'The [US]' == const 'US'");
            Testcase.Test(ByteString.Compare(longer, 4, "US", 0, 2) == 0,
                          "ByteString.Compare()",
                          "Comparing byte* substring and string constant: 'The [US]' == const 'US' (count=2)");

            Testcase.Test(ByteString.Compare(longer, 4, "US", 0, 0) == 0,
                          "ByteString.Compare()",
                          "Comparing byte* substring and string constant: 'The [US]' == const 'US' (count=0)");

            //Test that constant String is working properly
            const string str1 = "US";
            const string str2 = "SK";

            Testcase.Test((byte)str1 [0] == (byte)'U',
                          "ByteString",
                          "Testing string constants: (byte)\"US\" [0] == (byte)'U'");

            Testcase.Test((byte)str1 [1] == (byte)'S',
                          "ByteString",
                          "Testing string constants: (byte)\"US\" [1] == (byte)'S'");

            Testcase.Test(str1.Length == 2,
                          "ByteString",
                          "Testing string constant length: \"US\".Length == 2");

            Testcase.Test((byte)str1 [1] == (byte)str2 [0],
                          "ByteString",
                          "Testing string constants: (byte)\"US\" [1] == (byte)\"SK\" [0]");

            // FIXME: This testcase does not test ByteString, but the string constants.... where should it go?

            Testcase.Test("\n".Length == 1,
                          "ByteString",
                          "Testing string constants: Length of newline (\"\\n\".Length == 1");
        }
Example #3
0
 /// <summary>
 /// Compares <paramref name="count" /> characters of the
 /// string against <paramref name="str" />.
 /// </summary>
 public int Compare(string str, int offset, int count)
 {
     return(ByteString.Compare(Pointer, 0, str, offset, count));
 }
Example #4
0
 /// <summary>
 /// Compares <paramref name="count" /> characters of the
 /// string against <paramref name="str" />.
 /// </summary>
 public int Compare(byte *str, int count)
 {
     return(ByteString.Compare(Pointer, 0, str, 0, count));
 }
Example #5
0
 /// <summary>
 /// Compares <paramref name="count" /> characters of the
 /// string against <paramref name="str" />.
 /// </summary>
 public int Compare(int from, byte *str, int offset, int count)
 {
     return(ByteString.Compare(Pointer, from, str, offset, count));
 }