xml2sexprtest.c 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12

#include <stdio.h>
#include <string.h>

#include "xml.h"
#include "testutils.h"
#include "internal.h"

static char *progname;

#define MAX_FILE 4096

13
static int testCompareFiles(const char *xml, const char *sexpr, const char *name, int xendConfigVersion) {
14 15 16 17 18 19
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotname = NULL;
  char *gotsexpr = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
20
  int ret = -1;
21 22

  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
23
    goto fail;
24 25

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
26
    goto fail;
27

28 29
  if (!(gotsexpr = virDomainParseXMLDesc(xmlData, &gotname, xendConfigVersion)))
    goto fail;
30 31

  if (getenv("DEBUG_TESTS")) {
32 33
      printf("Expect %d '%s'\n", (int)strlen(sexprData), sexprData);
      printf("Actual %d '%s'\n", (int)strlen(gotsexpr), gotsexpr);
34 35
  }
  if (strcmp(sexprData, gotsexpr))
36
    goto fail;
37 38

  if (strcmp(name, gotname))
39
    goto fail;
40

41 42 43 44 45 46 47 48
  ret = 0;

 fail:

  free(gotname);
  free(gotsexpr);

  return ret;
49 50
}

51 52 53 54 55
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
			  "xml2sexprdata/xml2sexpr-pv.sexpr",
			  "pvtest",
			  1);
56 57
}

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
			  "xml2sexprdata/xml2sexpr-fv.sexpr",
			  "fvtest",
			  1);
}

static int testComparePVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
			  "xml2sexprdata/xml2sexpr-pv.sexpr",
			  "pvtest",
			  2);
}

static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
			  "xml2sexprdata/xml2sexpr-fv-v2.sexpr",
			  "fvtest",
			  2);
77 78
}

79 80 81 82 83 84 85
static int testCompareFVversion2VNC(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-vncunused.xml",
                          "xml2sexprdata/xml2sexpr-fv-vncunused.sexpr",
                          "fvtest",
                          2);
}

86 87 88 89 90 91 92 93 94 95 96 97
int
main(int argc, char **argv)
{
    int ret = 0;
    
    progname = argv[0];
    
    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname); 
        exit(EXIT_FAILURE);
    }
    
98 99 100 101 102 103 104 105 106 107
    if (virtTestRun("XML-2-SEXPR PV config (format 1)", 
		    1, testComparePVversion1, NULL) != 0)
        ret = -1;

    if (virtTestRun("XML-2-SEXPR FV config (format 1)", 
		    1, testCompareFVversion1, NULL) != 0)
        ret = -1;

    if (virtTestRun("XML-2-SEXPR PV config (format 2)",
		    1, testComparePVversion2, NULL) != 0)
108 109
        ret = -1;

110 111
    if (virtTestRun("XML-2-SEXPR FV config (format 2)", 
		    1, testCompareFVversion2, NULL) != 0)
112 113
        ret = -1;

114 115 116 117
    if (virtTestRun("XML-2-SEXPR FV config (format 2, VNC unused)",
                    1, testCompareFVversion2VNC, NULL) != 0)
        ret = -1;

118 119
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}