Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
PrimitiveTest.c File Reference
#include "xpt_xdr.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  TestData

Defines

#define PASS(msg)   fprintf(stderr, "PASSED : %s\n", msg);
#define FAIL(msg)   fprintf(stderr, "FAILURE: %s\n", msg);
#define TRY_(msg, cond, silent)
#define TRY(msg, cond)   TRY_(msg, cond, 0)
#define TRY_Q(msg, cond)   TRY_(msg, cond, 1);

Functions

void dump_struct (char *label, struct TestData *str)
PRBool XDR (XPTArena *arena, XPTCursor *cursor, struct TestData *str)
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

XPTString in_str = { 4, "bazz" }
struct TestData input
struct TestData output

Define Documentation

#define FAIL (   msg)    fprintf(stderr, "FAILURE: %s\n", msg);

Definition at line 47 of file PrimitiveTest.c.

#define PASS (   msg)    fprintf(stderr, "PASSED : %s\n", msg);

Definition at line 44 of file PrimitiveTest.c.

#define TRY (   msg,
  cond 
)    TRY_(msg, cond, 0)

Definition at line 58 of file PrimitiveTest.c.

#define TRY_ (   msg,
  cond,
  silent 
)
Value:
if ((cond) && !silent) {                                             \
    PASS(msg);                                                              \
  } else {                                                           \
    FAIL(msg);                                                              \
    return 1;                                                        \
  }

Definition at line 50 of file PrimitiveTest.c.

#define TRY_Q (   msg,
  cond 
)    TRY_(msg, cond, 1);

Definition at line 59 of file PrimitiveTest.c.


Function Documentation

void dump_struct ( char *  label,
struct TestData str 
)

Definition at line 73 of file PrimitiveTest.c.

{
    fprintf(stderr, "%s: {%#08x, %#04x, {%#02x, %#02x}, %s, %d/%s}\n",
           label, str->bit32, str->bit16, str->bit8[0], str->bit8[1],
           str->cstr, str->str->length, str->str->bytes);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 93 of file PrimitiveTest.c.

{
    XPTArena *arena;
    XPTState *state;
    XPTCursor curs, *cursor = &curs;
    char *header, *data, *whole;
    uint32 hlen, dlen, i;

    TRY("XPT_NewArena", (arena = XPT_NewArena(1024, sizeof(double), "main")));
    
    TRY("NewState (ENCODE)", (state = XPT_NewXDRState(XPT_ENCODE, NULL, 0)));

    XPT_SetDataOffset(state, sizeof input);

    TRY("MakeCursor", XPT_MakeCursor(state, XPT_HEADER, sizeof input, cursor));

    dump_struct("before", &input);

    if (XDR(arena, cursor, &input))
       return 1;

    fprintf(stderr, "ENCODE successful\n");
    XPT_GetXDRData(state, XPT_HEADER, &header, &hlen);
    fprintf(stderr, "XDR header %d bytes at %p:",
           hlen, header);
    for (i = 0; i < hlen; i++)
       fprintf(stderr, "%c%02x", i ? ',' : ' ', (uint8)header[i]);
    fprintf(stderr, "\n");

    XPT_GetXDRData(state, XPT_DATA, &data, &dlen);

    fprintf(stderr, "XDR data %d bytes at %p:",
           dlen, data);
    for (i = 0; i < dlen; i++)
       fprintf(stderr, "%c%02x/%c", i ? ',' : ' ', (uint8)data[i],
              (uint8)data[i]);
    fprintf(stderr, "\n");

    whole = malloc(dlen + hlen);
    if (!whole) {
       fprintf(stderr, "malloc %d failed!\n", dlen + hlen);
       return 1;
    }

    /* TRY_Q("malloc", (data2 = malloc(len))); */
    memcpy(whole, header, hlen);
    memcpy(whole + hlen, data, dlen);
    XPT_DestroyXDRState(state);

    TRY("NewState (DECODE)", (state = XPT_NewXDRState(XPT_DECODE, whole,
                                                hlen + dlen)));

    TRY("MakeCursor", XPT_MakeCursor(state, XPT_HEADER, sizeof input, cursor));
    XPT_SetDataOffset(state, sizeof input);

    if (XDR(arena, cursor, &output))
       return 1;
    
    dump_struct("after", &output);
    XPT_DestroyXDRState(state);
    XPT_DestroyArena(arena);
    free(whole);

    return 0;
}

Here is the call graph for this function:

PRBool XDR ( XPTArena arena,
XPTCursor cursor,
struct TestData str 
)

Definition at line 81 of file PrimitiveTest.c.

{
    TRY("Do32", XPT_Do32(cursor, &str->bit32));
    TRY("Do16", XPT_Do16(cursor, &str->bit16));
    TRY("Do8",  XPT_Do8 (cursor, &str->bit8[0]));
    TRY("Do8",  XPT_Do8 (cursor, &str->bit8[1]));
    TRY("DoCString", XPT_DoCString(arena, cursor, &str->cstr));
    TRY("DoString", XPT_DoString(arena, cursor, &str->str));
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

XPTString in_str = { 4, "bazz" }

Definition at line 61 of file PrimitiveTest.c.

struct TestData input
struct TestData output