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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/* Copyright (C) 2008 Vincent Penquerc'h.
This file is part of the Kate codec library.
Written by Vincent Penquerc'h.
Use, distribution and reproduction of this library is governed
by a BSD style source license included with this source in the
file 'COPYING'. Please read these terms before distributing. */
#include <stdio.h>
#include <string.h>
#include "kate/kate.h"
static const struct meta_op {
const char *op;
const char *tag;
const char *value;
size_t len;
int idx;
int expected_return_code;
} meta_ops[]={
{ "count", NULL, "", -1, 0, 0 },
{ "adds", "", "", -1, -1, KATE_E_INVALID_PARAMETER },
{ "adds", "\xff", "", -1, -1, KATE_E_BAD_TAG },
{ "adds", "raw", "\xff", -1, -1, KATE_E_TEXT },
{ "addr", "raw", "\xff", 1, -1, 0 },
{ "adds", "foo", "bar", -1, -1, 0 },
{ "count", NULL, "", -1, 0, 2 },
{ "remove", "foo", "bar", -1, -1, KATE_E_INVALID_PARAMETER },
{ "remove", "foo", "bar", -1, 1, KATE_E_INVALID_PARAMETER },
{ "remove", "foo", "bar", -1, 0, 0 },
{ "remove", "foo", "bar", -1, 0, KATE_E_INVALID_PARAMETER },
{ "count", NULL, "", -1, 0, 1 },
{ "count", "foo", "", -1, 0, 0 },
{ "adds", "foo", "bar", -1, -1, 0 },
{ "count", "foo", "", -1, 0, 1 },
{ "count", "bar", "", -1, 0, 0 },
{ "count", NULL, "", -1, 0, 2 },
{ "remove", "raw", "", -1, 0, 0 },
{ "count", NULL, "", -1, 0, 1 },
{ "adds", "bar", "baz", -1, -1, 0 },
{ "remove", NULL, "", -1, 1, 0 },
{ "remove", NULL, "", -1, 0, 0 },
{ "count", NULL, "", -1, 0, 0 },
};
int main()
{
size_t i,count;
kate_meta *km;
int ret;
ret=kate_meta_create(&km);
if (ret<0) {
fprintf(stderr,"kate_meta_init failed: %d\n",ret);
return ret;
}
for (i=0;i<sizeof(meta_ops)/sizeof(meta_ops[0]);++i) {
const struct meta_op *op=meta_ops+i;
if (!strcmp(op->op,"adds")) {
ret=kate_meta_add_string(km,op->tag,op->value);
}
else if (!strcmp(op->op,"addr")) {
ret=kate_meta_add(km,op->tag,op->value,op->len);
}
else if (!strcmp(op->op,"remove")) {
ret=op->tag?kate_meta_remove_tag(km,op->tag,op->idx):kate_meta_remove(km,op->idx);
}
else if (!strcmp(op->op,"count")) {
ret=op->tag?kate_meta_query_tag_count(km,op->tag):kate_meta_query_count(km);
}
else {
fprintf(stderr,"error: unknown op: %s\n",op->op);
return -1;
}
if (ret!=op->expected_return_code) {
fprintf(stderr,"error in op %zu: %d different from expected %d\n",i,ret,op->expected_return_code);
return -1;
}
}
ret=kate_meta_destroy(km);
if (ret<0) {
fprintf(stderr,"kate_meta_clear failed: %d\n",ret);
return ret;
}
return 0;
}
|