[libvirt] [PATCH 2/4] util: buffer: Add support for adding text blocks with indentation
Martin Kletzander
mkletzan at redhat.com
Wed Mar 25 09:32:11 UTC 2015
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?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150325/4929df73/attachment-0001.sig>
More information about the libvir-list
mailing list