00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026
00027 #include "gs2parser.h"
00028
00029 #define ZERO "\x00\x00\x00\x00"
00030 #define ONE "\x00\x00\x00\x01"
00031 #define TWO "\x00\x00\x00\x02"
00032 #define DATA "\x41"
00033 #define DATA2 "\x42"
00034
00035 struct
00036 {
00037 char *name;
00038 char *token;
00039 size_t length;
00040 int expected_rc;
00041 char *expected_context;
00042 size_t expected_context_length;
00043 char *expected_wrap;
00044 size_t expected_wrap_length;
00045 } tv[] =
00046 {
00047
00048 { "string0", "foobarbaz", 0, -1 },
00049 { "string1", "foobarbaz", 1, -1 },
00050 { "string2", "foobarbaz", 2, -1 },
00051 { "string3", "foobarbaz", 3, -1 },
00052 { "string4", "foobarbaz", 4, -1 },
00053 { "string5", "foobarbaz", 5, -1 },
00054 { "string6", "foobarbaz", 6, -1 },
00055 { "string7", "foobarbaz", 7, -1 },
00056 { "string8", "foobarbaz", 8, -1 },
00057 { "string9", "foobarbaz", 9, -1 },
00058 { "allzero", ZERO ZERO, 8, -1 },
00059 { "allzero-overlong", ZERO ZERO DATA, 9, -1 },
00060 { "one-empty", ONE ZERO, 8, -1 },
00061 { "one-empty2", ZERO ONE, 8, -1 },
00062 { "size-one", ONE ZERO DATA, 9, 0, DATA, 1, NULL, 0 },
00063 { "size-one2", ZERO ONE DATA, 9, 0, NULL, 0, DATA, 1 },
00064 { "size-one3", ONE ONE DATA DATA, 10, 0, DATA, 1, DATA, 1 },
00065 { "size-one-overlong", ZERO ONE DATA DATA, 10, -1 },
00066 { "size-one-overlong2", ONE ZERO DATA DATA, 10, -1 },
00067 { "size-one-overlong3", ONE ONE DATA DATA DATA, 11, -1 },
00068 { "size-two", TWO TWO DATA DATA2 DATA DATA2, 12, 0,
00069 DATA DATA2, 2, DATA2 DATA, 2 },
00070
00071 };
00072
00073 int
00074 main (int argc, char *argv[])
00075 {
00076 struct gs2_token tok;
00077 int rc;
00078 size_t i;
00079
00080 for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
00081 {
00082 rc = gs2_parser (tv[i].token, tv[i].length, &tok);
00083 if (rc != tv[i].expected_rc)
00084 {
00085 printf ("gs2 tv[%d] '%s': %.*s expected %d got %d\n",
00086 i, tv[i].name, tv[i].length,
00087 tv[i].token, tv[i].expected_rc, rc);
00088 }
00089 if (rc >= 0 &&
00090 (tv[i].expected_context_length != tok.context_length ||
00091 memcmp (tv[i].expected_context, tok.context_token,
00092 tok.context_length) != 0))
00093 {
00094 printf ("gs2 tv[%d] '%s': "
00095 "expected context %.*s (size %d) got %.*s (size %d)\n",
00096 i, tv[i].name,
00097 tv[i].expected_context_length,
00098 tv[i].expected_context,
00099 tv[i].expected_context_length,
00100 tok.context_length, tok.context_token, tok.context_length);
00101 abort ();
00102 }
00103 }
00104
00105 return 0;
00106 }