sexpr2xmltest.c 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13

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

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

static char *progname;

#define MAX_FILE 4096

14
static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) {
15 16 17 18 19 20 21 22 23 24 25 26
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotxml = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);

  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
    return -1;

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
    return -1;

27
  if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
28 29 30
    return -1;

  if (getenv("DEBUG_TESTS")) {
31 32
      printf("Expect %d '%s'\n", (int)strlen(xmlData), xmlData);
      printf("Actual %d '%s'\n", (int)strlen(gotxml), gotxml);
33 34 35 36 37 38 39
  }
  if (strcmp(xmlData, gotxml))
    return -1;

  return 0;
}

40 41 42 43
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
			  "sexpr2xmldata/sexpr2xml-pv.sexpr",
			  1);
44 45
}

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv.xml",
			  "sexpr2xmldata/sexpr2xml-fv.sexpr",
			  1);
}

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

static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-v2.xml",
			  "sexpr2xmldata/sexpr2xml-fv-v2.sexpr",
			  2);
62 63 64 65 66 67 68 69 70 71 72 73 74 75
}

int
main(int argc, char **argv)
{
    int ret = 0;
    
    progname = argv[0];
    
    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname); 
        exit(EXIT_FAILURE);
    }
    
76 77 78 79 80 81 82 83 84 85
    if (virtTestRun("SEXPR-2-XML PV config (version 1)", 
		    1, testComparePVversion1, NULL) != 0)
        ret = -1;

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

    if (virtTestRun("SEXPR-2-XML PV config (version 2)", 
		    1, testComparePVversion2, NULL) != 0)
86 87
        ret = -1;

88 89
    if (virtTestRun("SEXPR-2-XML FV config  (version 2)", 
		    1, testCompareFVversion2, NULL) != 0)
90 91 92 93
        ret = -1;

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