curl-users
advice for building test suite with libcurl
Date: Wed, 28 Jan 2015 11:28:11 +0100
Hi,
I'm building a small network test suite using libcurl. The code for every
test is quite similar, all setting multiple CURLOPT_*,
possibly with different options set to different values for each test.
Due to the similarity of the code structure, I thought about defining the
tests in a config file (currently testing with libconfig).
This would enable me to have one code performing all tests, and also replace
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080"
<http://localhost:8080>);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_HEADER, 1L );
with something like this pseudo code to be translated in C:
for (i=0; i<options.length; i++) {
curl_easy_setopt(curl, get_symbol_value_from_name(options[i].name),
options[i].value);
}
And my question is how do you advise me to solve the translation from a
string to its symbol value,
eg from "CURLOPT_URL" to CURLOPT_URL ( get_symbol_value_from_name in the
pseudo code)?
One possibility is defining a mapping from the string to the symbol,
possibly with the help of a macro:
struct mapping {
char name;
int code;
char type;
}
mapping arr[] = {
{"CURLOPT_URL", CURLOPT_URL, "str"},
{"CURLOPT_HEADER", CURLOPT_HEADER, "long"}
}
#define add_mapping(tab,code,type) tab[(code)] = {#code, code, type}
Is this the way to go? Is there a way to define a mapping for all curl
options? Or is there something in libcurl's code that can help me?
Thanks in advance for your feedback!
Raph
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-28