Re: [PATCH 2/6] tests: qemu: Add support for testing aguments on monitor verbatim

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

 



On Wed, Oct 05, 2016 at 09:37:50 -0400, John Ferlan wrote:
> On 09/27/2016 12:39 PM, Peter Krempa wrote:
> > Add code that takes a string and matches it against the data passed as
> > arguments from qemu. This is a simpler version of
> > qemuMonitorTestAddItemParams.
> > ---
> >  tests/qemumonitortestutils.c | 112 +++++++++++++++++++++++++++++++++++++++++++
> >  tests/qemumonitortestutils.h |   6 +++
> >  2 files changed, 118 insertions(+)

[...]

> > +/**
> > + * qemuMonitorTestAddItemExpect:
> > + *
> > + * @test: test monitor object
> > + * @cmdname: command name
> > + * @cmdargs: expected arguments of the command
> > + * @apostrophe: convert apostrophes (') in @cmdargs to quotes (")
> > + * @response: simulated response of the command
> > + *
> > + * Simulates a qemu monitor command. Checks that the 'arguments' of the qmp
> > + * command are expected. If @apostrophe is true apostrophes are converted to
> > + * quotes for simplification of writing the strings into code.
> > + */
> > +int
> > +qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
> > +                             const char *cmdname,
> > +                             const char *cmdargs,
> > +                             bool apostrophe,
> > +                             const char *response)
> > +{
> > +    struct qemuMonitorTestHandlerData *data;
> > +
> > +    if (VIR_ALLOC(data) < 0)
> > +        goto error;
> > +
> > +    if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
> > +        VIR_STRDUP(data->response, response) < 0 ||
> > +        VIR_STRDUP(data->expectArgs, cmdargs) < 0)
> > +        goto error;
> > +
> > +    if (apostrophe) {
> > +        char *tmp = data->expectArgs;
> > +
> > +        while (*tmp != '\0') {
> > +            if (*tmp == '\'')
> > +                *tmp = '"';
> > +
> > +            tmp++;
> > +        }
> 
> Would there ever be a time when apostrophe would be false?

It certainly can be. If you construct a proper JSON string, then
basically everything is enclosed in quotes. But those are very hard to
do in C code, thus you can cut the corner by using apostrophes. This
won't work though if you e.g. want to send a string containing an
apostrophe, thus you will need to do it properly and set @apostrophe to
false.

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]