1 /*
2  * Copyright (C) 2011-2012 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library.  If not, see
16  * <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #pragma once
21 
22 #include "domain_conf.h"
23 #include "qemu/qemu_conf.h"
24 #include "qemu/qemu_monitor.h"
25 #include "qemu/qemu_agent.h"
26 
27 typedef struct _qemuMonitorTest qemuMonitorTest;
28 
29 typedef struct _qemuMonitorTestItem qemuMonitorTestItem;
30 typedef int (*qemuMonitorTestResponseCallback)(qemuMonitorTest *test,
31                                                qemuMonitorTestItem *item,
32                                                const char *message);
33 
34 int qemuMonitorTestAddHandler(qemuMonitorTest *test,
35                               const char *identifier,
36                               qemuMonitorTestResponseCallback cb,
37                               void *opaque,
38                               virFreeCallback freecb);
39 
40 int qemuMonitorTestAddResponse(qemuMonitorTest *test,
41                                const char *response);
42 
43 int qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTest *test,
44                                              const char *expectedcommand,
45                                              const char *actualcommand);
46 
47 void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestItem *item);
48 
49 int qemuMonitorTestAddErrorResponse(qemuMonitorTest *test, const char *errmsg, ...);
50 
51 void qemuMonitorTestAllowUnusedCommands(qemuMonitorTest *test);
52 void qemuMonitorTestSkipDeprecatedValidation(qemuMonitorTest *test,
53                                              bool allowRemoved);
54 
55 int qemuMonitorTestAddItem(qemuMonitorTest *test,
56                            const char *command_name,
57                            const char *response);
58 
59 int qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test,
60                                    const char *command,
61                                    const char *cmderr,
62                                    const char *response);
63 
64 int qemuMonitorTestAddAgentSyncResponse(qemuMonitorTest *test);
65 
66 int qemuMonitorTestAddItemParams(qemuMonitorTest *test,
67                                  const char *cmdname,
68                                  const char *response,
69                                  ...)
70     G_GNUC_NULL_TERMINATED;
71 
72 int qemuMonitorTestAddItemExpect(qemuMonitorTest *test,
73                                  const char *cmdname,
74                                  const char *cmdargs,
75                                  bool apostrophe,
76                                  const char *response);
77 
78 #define qemuMonitorTestNewSimple(xmlopt) \
79     qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, NULL)
80 #define qemuMonitorTestNewSchema(xmlopt, schema) \
81     qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, schema)
82 
83 qemuMonitorTest *qemuMonitorTestNew(virDomainXMLOption *xmlopt,
84                                       virDomainObj *vm,
85                                       virQEMUDriver *driver,
86                                       const char *greeting,
87                                       GHashTable *schema);
88 
89 qemuMonitorTest *qemuMonitorTestNewFromFile(const char *fileName,
90                                               virDomainXMLOption *xmlopt,
91                                               bool simple);
92 qemuMonitorTest *qemuMonitorTestNewFromFileFull(const char *fileName,
93                                                   virQEMUDriver *driver,
94                                                   virDomainObj *vm,
95                                                   GHashTable *qmpschema);
96 
97 qemuMonitorTest *qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt);
98 
99 
100 void qemuMonitorTestFree(qemuMonitorTest *test);
101 
102 qemuMonitor *qemuMonitorTestGetMonitor(qemuMonitorTest *test);
103 qemuAgent *qemuMonitorTestGetAgent(qemuMonitorTest *test);
104 virDomainObj *qemuMonitorTestGetDomainObj(qemuMonitorTest *test);
105 
106 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorTest, qemuMonitorTestFree);
107