+static void TestStrBufPeek(void)
+{
+ StrBuf *Buf;
+ const char *pch;
+
+ Buf = NewStrBufPlain(HKEY("0123456"));
+ pch = ChrPtr(Buf);
+
+ CU_ASSERT(StrBufPeek(NULL, pch + 4, -1, 'A') == -1);
+
+ CU_ASSERT(StrBufPeek(Buf, pch + 4, -1, 'A') == 4);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
+
+ CU_ASSERT(StrBufPeek(Buf, pch - 1, -1, 'A') == -1);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
+
+ CU_ASSERT(StrBufPeek(Buf, pch + 10, -1, 'A') == -1);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
+
+ CU_ASSERT(StrBufPeek(Buf, NULL, -1, 'A') == -1);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
+
+ CU_ASSERT(StrBufPeek(Buf, NULL, 10, 'A') == -1);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
+
+ CU_ASSERT(StrBufPeek(Buf, NULL, 5, 'A') == 5);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123AA6");
+}
+
+static void TestBufStringManipulation(void)
+{
+ long len, i = 0;
+ StrBuf *dest = NewStrBuf ();
+ StrBuf *Buf = NewStrBufPlain(HKEY("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"));
+
+ StrBufSub(dest, Buf, -5, i);
+ len = StrLength(Buf);
+ for (i = 0; i < len + 10; i++)
+ {
+ StrBufSub(dest, Buf, 5, i);
+ if (i + 5 < len)
+ {
+ CU_ASSERT(StrLength(dest) == i);
+ }
+ else
+ {
+ CU_ASSERT(StrLength(dest) == len - 5);
+ }
+ }
+ FreeStrBuf(&dest);
+ dest = NewStrBuf ();
+ StrBufSub(dest, Buf, -5, 200);
+
+ StrBufCutLeft(Buf, 5);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
+ CU_ASSERT(StrLength(Buf) == 95);
+
+ StrBufCutRight(Buf, 5);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 90);
+
+ StrBufCutAt(Buf, 80, NULL);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"67890123456789012345678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 80);
+
+ StrBufCutAt(Buf, -1, ChrPtr(Buf) + 70);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"6789012345678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 70);
+
+
+ StrBufCutAt(Buf, 0, ChrPtr(Buf) + 60);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 60);
+
+ StrBufCutAt(Buf, 0, ChrPtr(Buf) + 70);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 60);
+
+ StrBufCutAt(Buf, 70, NULL);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
+ CU_ASSERT(StrLength(Buf) == 60);
+
+
+ StrBufCutLeft(Buf, 70);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"");
+ CU_ASSERT(StrLength(Buf) == 0);
+
+ StrBufPlain(Buf, HKEY("678901234567890123456789012345678901234567890123456789012345"));
+ StrBufCutRight(Buf, 70);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"");
+ CU_ASSERT(StrLength(Buf) == 0);
+
+ FreeStrBuf(&dest);
+ FreeStrBuf(&Buf);
+
+ Buf = NewStrBufPlain(HKEY(" \tabc\t "));
+ StrBufTrim(Buf);
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"abc");
+ CU_ASSERT(StrLength(Buf) == 3);
+
+ StrBufUpCase(NULL);
+ FlushStrBuf(Buf);
+ StrBufUpCase(Buf);
+ StrBufPlain(Buf, HKEY("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
+ StrBufUpCase(Buf);
+
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+
+
+ StrBufLowerCase(NULL);
+ FlushStrBuf(Buf);
+ StrBufLowerCase(Buf);
+ StrBufPlain(Buf, HKEY("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
+ StrBufLowerCase(Buf);
+
+ CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789");
+
+
+ FreeStrBuf(&Buf);
+
+}
+