/*! * @brief Create an empty list with preallocated storage for at least 'min' members */ struct bstrList *bstrListCreateMin(int min) { struct bstrList *sl = NULL; if ((sl = bstrListCreate()) == NULL) return NULL; if ((bstrListAlloc(sl, min)) != BSTR_OK) { bstrListDestroy(sl); return NULL; } return sl; }
char *test_Request_speeds() { int i = 0; FILE *infile = fopen("tests/request_payloads.txt", "r"); mu_assert(infile != NULL, "Failed to open the tests/request_payloads.txt test file."); struct bstrList *list = bstrListCreate(); bstrListAlloc(list, 300); // load up all the ones we can for(i = 0; i < 300; i++, list->qty++) { bstring sender = bgets((bNgetc)fgetc, infile, ' '); bstring conn_id = bgets((bNgetc)fgetc, infile, ' '); bstring path = bgets((bNgetc)fgetc, infile, ' '); list->entry[i] = bgets((bNgetc)fgetc, infile, '\n'); // stop if we didn't read anything if(!(sender && conn_id && path)) break; bdestroy(sender); bdestroy(conn_id); bdestroy(path); } fclose(infile); // now rip through and parse them for speed test int j = 0; for(j = 0; j < 200; j++) { for(i = 0; i < list->qty; i++) { tns_value_t *val = tns_parse(bdata(list->entry[i]), blength(list->entry[i]), NULL); mu_assert(val->type == tns_tag_string || val->type == tns_tag_dict, "Got an invalid data chunk from file."); size_t len = 0; char *payload = tns_render(val, &len); mu_assert(len > 0, "Failed to render the payload."); free(payload); tns_value_destroy(val); } } bstrListDestroy(list); return NULL; }