TEST(OptionsTest, test_options_copy_ctor) { Option opt_i("my_int", 17, "This is my integral option."); const Option opt_s("my_string", "Yow.", "This is my stringy option."); Options opts; opts.add(opt_i); opts.add(opt_s); Options copy(opts); EXPECT_TRUE(copy.hasOption("my_int")); EXPECT_TRUE(copy.hasOption("my_string")); }
int options(int argc, char **argv, options_t *opt){ int c=0; char *optarg; poptContext context; const struct poptOption pop_opt[] = { {"connection_limit", 'c', POPT_ARG_STRING, NULL, 'c', NULL, NULL}, {"debug", 'd', POPT_ARG_NONE, NULL, 'd', NULL, NULL}, {"help", 'h', POPT_ARG_NONE, NULL, 'h', NULL, NULL}, {"listen_host", 'l', POPT_ARG_STRING, NULL, 'l', NULL, NULL}, {"listen_port", 'L', POPT_ARG_STRING, NULL, 'L', NULL, NULL}, {"no_lookup", 'n', POPT_ARG_NONE, NULL, 'n', NULL, NULL}, {"outgoing_host", 'o', POPT_ARG_STRING, NULL, 'o', NULL, NULL}, {"outgoing_port", 'O', POPT_ARG_STRING, NULL, 'O', NULL, NULL}, {"quiet", 'q', 0, NULL, 'q', NULL, NULL}, {"timeout", 't', POPT_ARG_STRING, NULL, 't', NULL, NULL}, {NULL, 0, 0, NULL, 0, NULL, NULL} }; if(argc==0 || argv==NULL) return(0); if (opt_i(&opt->connection_limit, DEFAULT_CONNECTION_LIMIT, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_i(&opt->debug, DEFAULT_DEBUG, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_p(&opt->listen_host, DEFAULT_LISTEN_HOST, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_p(&opt->listen_port, DEFAULT_LISTEN_PORT, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_i(&opt->no_lookup, DEFAULT_NO_LOOKUP, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_p(&opt->outgoing_host, DEFAULT_OUTGOING_HOST, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_p(&opt->outgoing_port, DEFAULT_OUTGOING_PORT, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_i(&opt->quiet, DEFAULT_QUIET, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } if (opt_i(&opt->timeout, DEFAULT_TIMEOUT, OPT_NOT_SET)) { VANESSA_LOGGER_DEBUG("Error setting default values"); return -1; } context= poptGetContext( "vanessa_socket_pipe", argc, (const char **) argv, pop_opt, 0 ); while ((c=poptGetNextOpt(context)) >= 0){ optarg=(char *)poptGetOptArg(context); switch (c){ case 'c': if(!vanessa_socket_str_is_digit(optarg)){ usage(-1); } opt_i(&opt->connection_limit, atoi(optarg), 0); break; case 'd': opt_i(&opt->debug, 1, 0); break; case 'h': usage(0); break; case 'l': opt_p(&opt->listen_host, optarg, 0); break; case 'L': opt_p(&opt->listen_port, optarg, 0); break; case 'n': opt_i(&opt->no_lookup, 1, 0); break; case 'o': opt_p(&opt->outgoing_host, optarg, 0); break; case 'O': opt_p(&opt->outgoing_port, optarg, 0); break; case 'q': opt_i(&opt->quiet, 1, 0); break; case 't': if(!vanessa_socket_str_is_digit(optarg)){ usage(-1); } opt_i(&opt->timeout, atoi(optarg), 0); break; } } if (c < -1) { fprintf( stderr, "options: %s: %s\n", poptBadOption(context, POPT_BADOPTION_NOALIAS), poptStrerror(c) ); usage(-1); } if(opt->outgoing_host==NULL || opt->listen_port==NULL){ usage(-1); } if(opt->outgoing_port==NULL){ opt->outgoing_port=opt->listen_port; } poptFreeContext(context); return(0); }