aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2009-05-21 14:22:51 +0000
committerDaniel P. Berrange <berrange@redhat.com>2009-05-21 14:22:51 +0000
commit107a7bd06bc8049619e964ced796ed18aa00a514 (patch)
treeeea4119f25ed3e458044ba5212541241dc9ac005 /tests/testutils.c
parentAdd docs on domain XML conversion usage for QEMU/Xen drivers (diff)
downloadlibvirt-107a7bd06bc8049619e964ced796ed18aa00a514.tar.gz
libvirt-107a7bd06bc8049619e964ced796ed18aa00a514.tar.bz2
libvirt-107a7bd06bc8049619e964ced796ed18aa00a514.zip
Test case for QEMU driver ARGV -> XML conversion
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index c90d4a9e1..78df731d1 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -18,6 +18,7 @@
#ifndef WIN32
#include <sys/wait.h>
#endif
+#include <regex.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
@@ -457,3 +458,48 @@ cleanup:
virResetLastError();
return ret;
}
+
+
+int virtTestClearLineRegex(const char *pattern,
+ char *str)
+{
+ regex_t reg;
+ char *lineStart = str;
+ char *lineEnd = strchr(str, '\n');
+
+ if (regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB) != 0)
+ return -1;
+
+ while (lineStart) {
+ int ret;
+ if (lineEnd)
+ *lineEnd = '\0';
+
+
+ ret = regexec(&reg, lineStart, 0, NULL, 0);
+ //fprintf(stderr, "Match %d '%s' '%s'\n", ret, lineStart, pattern);
+ if (ret == 0) {
+ if (lineEnd) {
+ memmove(lineStart, lineEnd + 1, strlen(lineEnd+1) + 1);
+ /* Don't update lineStart - just iterate again on this
+ location */
+ lineEnd = strchr(lineStart, '\n');
+ } else {
+ *lineStart = '\0';
+ lineStart = NULL;
+ }
+ } else {
+ if (lineEnd) {
+ *lineEnd = '\n';
+ lineStart = lineEnd + 1;
+ lineEnd = strchr(lineStart, '\n');
+ } else {
+ lineStart = NULL;
+ }
+ }
+ }
+
+ regfree(&reg);
+
+ return 0;
+}