Re: [PATCH 2/4] util: buffer: Add support for adding text blocks with indentation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 25, 2015 at 13:10:49 +0100, Martin Kletzander wrote:
> On Wed, Mar 25, 2015 at 01:00:17PM +0100, Peter Krempa wrote:
> >On Wed, Mar 25, 2015 at 10:32:11 +0100, Martin Kletzander wrote:
> >> On Tue, Mar 24, 2015 at 03:03:21PM +0100, Peter Krempa wrote:
> >> >The current auto-indentation buffer code applies indentation only on
> >> >complete strings. To allow adding a string containing newlines and
> >> >having it properly indented this patch adds virBufferAddStr.
> >> >---
> >> > src/libvirt_private.syms |  1 +
> >> > src/util/virbuffer.c     | 38 ++++++++++++++++++++++++++++++++++++
> >> > src/util/virbuffer.h     |  1 +
> >> > tests/virbuftest.c       | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
> >> > 4 files changed, 90 insertions(+)
> >> >
> >> >diff --git a/tests/virbuftest.c b/tests/virbuftest.c
> >> >index f964feb..067a77e 100644
> >> >--- a/tests/virbuftest.c
> >> >+++ b/tests/virbuftest.c
> >> >@@ -310,6 +310,44 @@ static int testBufAddBuffer(const void *data ATTRIBUTE_UNUSED)
> >> >     return ret;
> >> > }
> >> >
> >> >+struct testBufAddStrData {
> >> >+    const char *data;
> >> >+    const char *expect;
> >> >+};
> >> >+
> >> >+static int
> >> >+testBufAddStr(const void *opaque ATTRIBUTE_UNUSED)
> >> >+{
> >> >+    const struct testBufAddStrData *data = opaque;
> >> >+    virBuffer buf = VIR_BUFFER_INITIALIZER;
> >> >+    char *actual;
> >> >+    int ret = -1;
> >> >+
> >> >+    virBufferAddLit(&buf, "<c>\n");
> >> >+    virBufferAdjustIndent(&buf, 2);
> >> >+    virBufferAddStr(&buf, data->data);
> >> >+    virBufferAdjustIndent(&buf, -2);
> >> >+    virBufferAddLit(&buf, "</c>");
> >> >+
> >> >+    if (!(actual = virBufferContentAndReset(&buf))) {
> >> >+        TEST_ERROR("buf is empty");
> >> >+        goto cleanup;
> >> >+    }
> >> >+
> >> >+    if (STRNEQ_NULLABLE(actual, data->expect)) {
> >> >+        TEST_ERROR("testBufAddStr(): Strings don't match:\n"
> >> >+                   "Expected:\n%s\nActual:\n%s\n",
> >> >+                   data->expect, actual);
> >>
> >> One more question though, virtTestDifferenceFull() doens't make sense
> >> here?
> >
> >Actually the output with virtTestDifferenceFull kind of sucks with short
> >documents.
> >
> 
> I find it cleaner, but that's highly subjective ;) go ahead and push
> it as-is, the ACK still stands.

I've also changed to the strchr approach as it's really better, so I'll
repost with that and also virtTestDifference() since I've switched to it
when writing the mail :)

Peter

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]