Debian Codegraph @

tests/metadata.c

raw
1 /* Copyright (C) 2008 Vincent Penquerc'h.
2 This file is part of the Kate codec library.
3 Written by Vincent Penquerc'h.
4
5 Use, distribution and reproduction of this library is governed
6 by a BSD style source license included with this source in the
7 file 'COPYING'. Please read these terms before distributing. */
8
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "kate/kate.h"
13
14 static const struct meta_op {
15 const char *op;
16 const char *tag;
17 const char *value;
18 size_t len;
19 int idx;
20 int expected_return_code;
21 } meta_ops[]={
22 { "count", NULL, "", -1, 0, 0 },
23 { "adds", "", "", -1, -1, KATE_E_INVALID_PARAMETER },
24 { "adds", "\xff", "", -1, -1, KATE_E_BAD_TAG },
25 { "adds", "raw", "\xff", -1, -1, KATE_E_TEXT },
26 { "addr", "raw", "\xff", 1, -1, 0 },
27 { "adds", "foo", "bar", -1, -1, 0 },
28 { "count", NULL, "", -1, 0, 2 },
29 { "remove", "foo", "bar", -1, -1, KATE_E_INVALID_PARAMETER },
30 { "remove", "foo", "bar", -1, 1, KATE_E_INVALID_PARAMETER },
31 { "remove", "foo", "bar", -1, 0, 0 },
32 { "remove", "foo", "bar", -1, 0, KATE_E_INVALID_PARAMETER },
33 { "count", NULL, "", -1, 0, 1 },
34 { "count", "foo", "", -1, 0, 0 },
35 { "adds", "foo", "bar", -1, -1, 0 },
36 { "count", "foo", "", -1, 0, 1 },
37 { "count", "bar", "", -1, 0, 0 },
38 { "count", NULL, "", -1, 0, 2 },
39 { "remove", "raw", "", -1, 0, 0 },
40 { "count", NULL, "", -1, 0, 1 },
41 { "adds", "bar", "baz", -1, -1, 0 },
42 { "remove", NULL, "", -1, 1, 0 },
43 { "remove", NULL, "", -1, 0, 0 },
44 { "count", NULL, "", -1, 0, 0 },
45 };
46
47 int main()
48 {
49 size_t i,count;
50 kate_meta *km;
51 int ret;
52
53 ret=kate_meta_create(&km);
54 if (ret<0) {
55 fprintf(stderr,"kate_meta_init failed: %d\n",ret);
56 return ret;
57 }
58
59 for (i=0;i<sizeof(meta_ops)/sizeof(meta_ops[0]);++i) {
60 const struct meta_op *op=meta_ops+i;
61 if (!strcmp(op->op,"adds")) {
62 ret=kate_meta_add_string(km,op->tag,op->value);
63 }
64 else if (!strcmp(op->op,"addr")) {
65 ret=kate_meta_add(km,op->tag,op->value,op->len);
66 }
67 else if (!strcmp(op->op,"remove")) {
68 ret=op->tag?kate_meta_remove_tag(km,op->tag,op->idx):kate_meta_remove(km,op->idx);
69 }
70 else if (!strcmp(op->op,"count")) {
71 ret=op->tag?kate_meta_query_tag_count(km,op->tag):kate_meta_query_count(km);
72 }
73 else {
74 fprintf(stderr,"error: unknown op: %s\n",op->op);
75 return -1;
76 }
77 if (ret!=op->expected_return_code) {
78 fprintf(stderr,"error in op %zu: %d different from expected %d\n",i,ret,op->expected_return_code);
79 return -1;
80 }
81 }
82
83 ret=kate_meta_destroy(km);
84 if (ret<0) {
85 fprintf(stderr,"kate_meta_clear failed: %d\n",ret);
86 return ret;
87 }
88
89 return 0;
90 }
91