sexpr2xmltest.c 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

#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

static int testCompareFiles(const char *xml, const char *sexpr) {
  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;

  if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData)))
    return -1;

  if (getenv("DEBUG_TESTS")) {
      printf("In  %d '%s'\n", strlen(xmlData), xmlData);
      printf("Out %d '%s'\n", strlen(gotxml), gotxml);
  }
  if (strcmp(xmlData, gotxml))
    return -1;

  return 0;
}

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

static int testCompareFV(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xml-fv.xml",
			  "sexpr2xml-fv.sexpr");
}

int
main(int argc, char **argv)
{
    int ret = 0;
    
    progname = argv[0];
    
    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname); 
        exit(EXIT_FAILURE);
    }
    
    if (virtTestRun("SEXPR-2-XML PV config", 
		    1, testComparePV, NULL) != 0)
        ret = -1;

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

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