Good coverage for strbuf
authorenglebass <englebass@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 11 Feb 2010 21:53:00 +0000 (21:53 +0000)
committerenglebass <englebass@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 11 Feb 2010 21:53:00 +0000 (21:53 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@46101 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eina_strbuf.c
src/tests/eina_test_strbuf.c

index b6e584a..778747c 100644 (file)
@@ -499,6 +499,8 @@ _eina_strbuf_resize(Eina_Strbuf *buf, size_t size)
    else
      {
        /* shrink the buffer */
+       if (new_step > EINA_STRBUF_INIT_STEP)
+         new_step /= 2;
        while (new_size - new_step > size)
          {
             new_size -= new_step;
index 00d70b4..1b145e7 100644 (file)
@@ -85,6 +85,19 @@ START_TEST(strbuf_remove)
    eina_strbuf_remove(buf, 2, 4);
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "45789"));
+   eina_strbuf_remove(buf, 4, 1);
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   fail_if(strcmp(eina_strbuf_string_get(buf), "45789"));
+   eina_strbuf_remove(buf, 0, eina_strbuf_length_get(buf));
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   fail_if(strcmp(eina_strbuf_string_get(buf), ""));
+
+#define TEXT "This test should be so long that it is longer than the initial size of strbuf"
+   eina_strbuf_append(buf, TEXT TEXT);
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   eina_strbuf_remove(buf, 0, eina_strbuf_length_get(buf) - 1);
+   fail_if(strcmp(eina_strbuf_string_get(buf), "f"));
+#undef TEXT
 
    eina_strbuf_free(buf);
 
@@ -176,7 +189,7 @@ START_TEST(strbuf_replace)
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "aaa"));
 
-   eina_strbuf_replace(buf, "a", "b", 1);
+   fail_if(!eina_strbuf_replace(buf, "a", "b", 1));
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "baa"));
 
@@ -184,7 +197,7 @@ START_TEST(strbuf_replace)
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "bbb"));
 
-   eina_strbuf_replace(buf, "b", "cc", 2);
+   fail_if(!eina_strbuf_replace(buf, "b", "cc", 2));
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "bccb"));
 
@@ -192,6 +205,19 @@ START_TEST(strbuf_replace)
    fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
    fail_if(strcmp(eina_strbuf_string_get(buf), "baaaab"));
 
+   fail_if(eina_strbuf_replace(buf, "c", "aa", 0));
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   fail_if(strcmp(eina_strbuf_string_get(buf), "baaaab"));
+
+   fail_if(eina_strbuf_replace(buf, "c", "aa", 2));
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   fail_if(strcmp(eina_strbuf_string_get(buf), "baaaab"));
+
+   fail_if(eina_strbuf_replace_all(buf, "c", "aa") != 0);
+   fail_if(strlen(eina_strbuf_string_get(buf)) != eina_strbuf_length_get(buf));
+   fail_if(strcmp(eina_strbuf_string_get(buf), "baaaab"));
+
+
    eina_strbuf_free(buf);
 
    eina_shutdown();