diff options
Diffstat (limited to 'src/main/test_ipc.c')
-rw-r--r-- | src/main/test_ipc.c | 134 |
1 files changed, 68 insertions, 66 deletions
diff --git a/src/main/test_ipc.c b/src/main/test_ipc.c index 5e118fd..4da3ef5 100644 --- a/src/main/test_ipc.c +++ b/src/main/test_ipc.c | |||
@@ -46,77 +46,77 @@ static int ret = 2; | |||
46 | * @param data hello world or good bye | 46 | * @param data hello world or good bye |
47 | * @param data_len number of bytes in data | 47 | * @param data_len number of bytes in data |
48 | * @return 0 on hello world, 1 on goodbye | 48 | * @return 0 on hello world, 1 on goodbye |
49 | */ | 49 | */ |
50 | static int | 50 | static int |
51 | process_replies (void *cls, | 51 | process_replies (void *cls, |
52 | const char *plugin_name, | 52 | const char *plugin_name, |
53 | enum EXTRACTOR_MetaType type, | 53 | enum EXTRACTOR_MetaType type, |
54 | enum EXTRACTOR_MetaFormat format, | 54 | enum EXTRACTOR_MetaFormat format, |
55 | const char *data_mime_type, | 55 | const char *data_mime_type, |
56 | const char *data, | 56 | const char *data, |
57 | size_t data_len) | 57 | size_t data_len) |
58 | { | 58 | { |
59 | if (0 != strcmp (cls, | 59 | if (0 != strcmp (cls, |
60 | "main-cls")) | 60 | "main-cls")) |
61 | { | 61 | { |
62 | fprintf (stderr, "closure invalid\n"); | 62 | fprintf (stderr, "closure invalid\n"); |
63 | ret = 3; | 63 | ret = 3; |
64 | return 1; | 64 | return 1; |
65 | } | 65 | } |
66 | if (0 == strcmp (plugin_name, | 66 | if (0 == strcmp (plugin_name, |
67 | "test2")) | 67 | "test2")) |
68 | return 0; /* ignore 'test2' plugins */ | 68 | return 0; /* ignore 'test2' plugins */ |
69 | if (0 != strcmp (plugin_name, | 69 | if (0 != strcmp (plugin_name, |
70 | "test")) | 70 | "test")) |
71 | { | 71 | { |
72 | fprintf (stderr, "plugin name invalid\n"); | 72 | fprintf (stderr, "plugin name invalid\n"); |
73 | ret = 4; | 73 | ret = 4; |
74 | return 1; | 74 | return 1; |
75 | } | 75 | } |
76 | if (EXTRACTOR_METATYPE_COMMENT != type) | 76 | if (EXTRACTOR_METATYPE_COMMENT != type) |
77 | { | 77 | { |
78 | fprintf (stderr, "type invalid\n"); | 78 | fprintf (stderr, "type invalid\n"); |
79 | ret = 5; | 79 | ret = 5; |
80 | return 1; | 80 | return 1; |
81 | } | 81 | } |
82 | if (EXTRACTOR_METAFORMAT_UTF8 != format) | 82 | if (EXTRACTOR_METAFORMAT_UTF8 != format) |
83 | { | 83 | { |
84 | fprintf (stderr, "format invalid\n"); | 84 | fprintf (stderr, "format invalid\n"); |
85 | ret = 6; | 85 | ret = 6; |
86 | return 1; | 86 | return 1; |
87 | } | 87 | } |
88 | if ( (NULL == data_mime_type) || | 88 | if ( (NULL == data_mime_type) || |
89 | (0 != strcmp ("<no mime>", | 89 | (0 != strcmp ("<no mime>", |
90 | data_mime_type) ) ) | 90 | data_mime_type) ) ) |
91 | { | 91 | { |
92 | fprintf (stderr, "bad mime type\n"); | 92 | fprintf (stderr, "bad mime type\n"); |
93 | ret = 7; | 93 | ret = 7; |
94 | return 1; | 94 | return 1; |
95 | } | 95 | } |
96 | if ( (2 == ret) && | 96 | if ( (2 == ret) && |
97 | (data_len == strlen (HLO) + 1) && | 97 | (data_len == strlen (HLO) + 1) && |
98 | (0 == strncmp (data, | 98 | (0 == strncmp (data, |
99 | HLO, | 99 | HLO, |
100 | strlen (HLO))) ) | 100 | strlen (HLO))) ) |
101 | { | 101 | { |
102 | #if 0 | 102 | #if 0 |
103 | fprintf (stderr, "Received '%s'\n", HLO); | 103 | fprintf (stderr, "Received '%s'\n", HLO); |
104 | #endif | 104 | #endif |
105 | ret = 1; | 105 | ret = 1; |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | if ( (1 == ret) && | 108 | if ( (1 == ret) && |
109 | (data_len == strlen (GOB) + 1) && | 109 | (data_len == strlen (GOB) + 1) && |
110 | (0 == strncmp (data, | 110 | (0 == strncmp (data, |
111 | GOB, | 111 | GOB, |
112 | strlen (GOB))) ) | 112 | strlen (GOB))) ) |
113 | { | 113 | { |
114 | #if 0 | 114 | #if 0 |
115 | fprintf (stderr, "Received '%s'\n", GOB); | 115 | fprintf (stderr, "Received '%s'\n", GOB); |
116 | #endif | 116 | #endif |
117 | ret = 0; | 117 | ret = 0; |
118 | return 1; | 118 | return 1; |
119 | } | 119 | } |
120 | fprintf (stderr, "Invalid meta data\n"); | 120 | fprintf (stderr, "Invalid meta data\n"); |
121 | ret = 8; | 121 | ret = 8; |
122 | return 1; | 122 | return 1; |
@@ -138,35 +138,37 @@ main (int argc, char *argv[]) | |||
138 | size_t i; | 138 | size_t i; |
139 | 139 | ||
140 | /* initialize test buffer as expected by test plugin */ | 140 | /* initialize test buffer as expected by test plugin */ |
141 | for (i=0;i<sizeof(buf);i++) | 141 | for (i = 0; i<sizeof(buf); i++) |
142 | buf[i] = (unsigned char) (i % 256); | 142 | buf[i] = (unsigned char) (i % 256); |
143 | memcpy (buf, "test", 4); | 143 | memcpy (buf, "test", 4); |
144 | 144 | ||
145 | /* change environment to find 'extractor_test' plugin which is | 145 | /* change environment to find 'extractor_test' plugin which is |
146 | not installed but should be in the current directory (or .libs) | 146 | not installed but should be in the current directory (or .libs) |
147 | on 'make check' */ | 147 | on 'make check' */ |
148 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) | 148 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) |
149 | fprintf (stderr, | 149 | fprintf (stderr, |
150 | "Failed to update my environment, plugin loading may fail: %s\n", | 150 | "Failed to update my environment, plugin loading may fail: %s\n", |
151 | strerror (errno)); | 151 | strerror (errno)); |
152 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", | 152 | pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", |
153 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 153 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
154 | pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)", | 154 | pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)", |
155 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 155 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
156 | if (NULL == pl) | 156 | if (NULL == pl) |
157 | { | 157 | { |
158 | fprintf (stderr, "failed to load test plugin\n"); | 158 | fprintf (stderr, "failed to load test plugin\n"); |
159 | return 1; | 159 | return 1; |
160 | } | 160 | } |
161 | EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); | 161 | EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); |
162 | if (0 == ret) | 162 | if (0 == ret) |
163 | { | 163 | { |
164 | /* do it again... */ | 164 | /* do it again... */ |
165 | ret = 2; | 165 | ret = 2; |
166 | EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); | 166 | EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, |
167 | } | 167 | "main-cls"); |
168 | } | ||
168 | EXTRACTOR_plugin_remove_all (pl); | 169 | EXTRACTOR_plugin_remove_all (pl); |
169 | return ret; | 170 | return ret; |
170 | } | 171 | } |
171 | 172 | ||
173 | |||
172 | /* end of test_ipc.c */ | 174 | /* end of test_ipc.c */ |