示例#1
0
int bad_filename_returns_error()
{
    int     status;
    int     numroutes;
    route_t **routes;

    fork_to_test(
        status = parse_routes("/fubar", &routes, &numroutes);
        if(!status)
            exit(1);
        exit(0);
    )
}
示例#2
0
文件: kotiin.c 项目: pafcu/kotiin
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "inbox");

  Tuple *tuple;
  
  tuple = dict_find(iterator, KEY_ROUTE_DATA);
  if(tuple) {
    parse_routes(tuple->value->cstring);
    return;
  }
  
  tuple = dict_find(iterator, KEY_READY);
  if(tuple) {
    request_routes();
    return;
  }
  tuple = dict_find(iterator, KEY_APPROACHING_POINT);
  if(tuple) {
    alert_point(tuple->value->int32);
    return;
  }
}
示例#3
0
int bad_lines_in_otherwise_good_file_ignored()
{
    char        *routefile_path;
    FILE        *routefile;
    int         status;
    int         numroutes;
    route_t     **routes;
    void        *FUNC, *FUNC2;

    char        *goodline = "GET /static dummy_routine\n";
    char        *badline = "FOO BAR BAZ\n";

    routefile_path = tempnam(".", "martin_unit_XXX");
    routefile = fopen(routefile_path, "w");
    if(!routefile)
    {
        printf("%s(): couldn't open tempfile '%s' for writing, aborting test!\n", __func__, routefile_path);
        status = -1;
        goto cleanup;
    }
    fwrite(goodline, strlen(goodline), 1, routefile);
    fwrite(badline, strlen(badline), 1, routefile);
    goodline = "PUT /static dummy_routine2\n";
    fwrite(goodline, strlen(goodline), 1, routefile);
    fwrite(badline, strlen(badline), 1, routefile);
    fclose(routefile);

    FUNC = dlsym(RTLD_DEFAULT, "dummy_routine");
    FUNC2 = dlsym(RTLD_DEFAULT, "dummy_routine2");
    if(FUNC == NULL || FUNC2 == NULL)
    {
        printf("%s(): couldn't resolve symbol 'dummy_routine' or 'dummy_routine2', aborting test!\n", __func__);
        status = -1;
        goto cleanup;
    }

    fork_and_get_exitcode(status,
        status = parse_routes(routefile_path, &routes, &numroutes);
        if(status)
        {
            printf("%s(): parse_routes returned %d\n", __func__, status);
            exit(status);
        }

        if(numroutes != 2)
        {
            printf("%s(): numroutes != 2\n", __func__);
            exit(1);
        }

        if(routes[0]->handler != FUNC || routes[1]->handler != FUNC2)
        {
            printf("%s(): handler resolved to an unexpected address\n", __func__);
            exit(1);
        }

        if(routes[0]->method != HTTP_GET || routes[1]->method != HTTP_PUT)
        {
            printf("%s(): method resolved incorrectly\n", __func__);
            exit(1);
        }

        exit(0);
    )