aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2006-08-24 15:05:19 +0000
committerDaniel P. Berrange <berrange@redhat.com>2006-08-24 15:05:19 +0000
commit441246297ed3eabc2218a9a9395c34837f96f0a8 (patch)
tree1c0f644893637ba9254efba233dac987034c38c1 /tests/testutils.c
parentCheck for failure of virConnectListDomains in 'list' command (diff)
downloadlibvirt-441246297ed3eabc2218a9a9395c34837f96f0a8.tar.gz
libvirt-441246297ed3eabc2218a9a9395c34837f96f0a8.tar.bz2
libvirt-441246297ed3eabc2218a9a9395c34837f96f0a8.zip
Added tests for the SEXPR<->XML conversion process
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index ee562d71a..4da6c7dc0 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -13,6 +13,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "testutils.h"
@@ -72,3 +75,33 @@ virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data)
free(ts);
return ret;
}
+
+int virtTestLoadFile(const char *name,
+ char **buf,
+ int buflen) {
+ FILE *fp = fopen(name, "r");
+ struct stat st;
+
+ if (!fp)
+ return -1;
+
+ if (fstat(fileno(fp), &st) < 0) {
+ fclose(fp);
+ return -1;
+ }
+
+ if (st.st_size > (buflen-1)) {
+ fclose(fp);
+ return -1;
+ }
+
+ if (fread(*buf, st.st_size, 1, fp) != 1) {
+ fclose(fp);
+ return -1;
+ }
+ (*buf)[st.st_size] = '\0';
+
+ fclose(fp);
+ return st.st_size;
+}
+