int main() { multipartparser_callbacks_init(&g_callbacks); g_callbacks.on_body_begin = &on_body_begin; g_callbacks.on_part_begin = &on_part_begin; g_callbacks.on_header_field = &on_header_field; g_callbacks.on_header_value = &on_header_value; g_callbacks.on_headers_complete = &on_headers_complete; g_callbacks.on_data = &on_data; g_callbacks.on_part_end = &on_part_end; g_callbacks.on_body_end = &on_body_end; test_simple(); test_simple_with_preamble(); test_simple_with_epilogue(); test_headers(); test_with_empty_headers(); test_with_header_field_parsed_in_two_times(); test_with_header_field_parsed_in_two_times_1(); test_with_header_field_parsed_in_two_times_2(); test_with_header_value_parsed_in_two_times(); test_with_header_value_parsed_in_two_times_1(); test_with_header_value_parsed_in_two_times_2(); return 0; }
void run() { test_headers(); { std::string const text = "get / http/1.1\r\n" "\r\n" ; message m; body b; parser p (m, b, true); auto result (p.write (boost::asio::buffer(text))); expect (! result.first); auto result2 (p.write_eof()); expect (! result2); expect (p.complete()); } { // malformed std::string const text = "get\r\n" "\r\n" ; message m; body b; parser p (m, b, true); auto result = p.write (boost::asio::buffer(text)); if (expect (result.first)) expect (result.first.message() == "invalid http method"); } }
int main(int argc, char** argv) { test_harness t; string slash = "/"; test_objdir_prefix = (argc >= 2)? argv[1] + slash : ""; test_srcdir_prefix = (argc >= 3)? argv[2] + slash : test_objdir_prefix; try { test_headers(t); test_alignments(t); test_intervals(t); test_sam_io(t); test_wire(t); } catch (const sam::exception& e) { if (e.filename().empty()) std::cerr << "Excess sam::exception: " << e.what() << '\n'; else std::cerr << "Excess sam::exception from " << e.filename() << ": " << e.what() << '\n'; t.nfail++; } catch (const std::exception& e) { std::cerr << "Excess std::exception: " << e.what() << '\n'; t.nfail++; } catch (const char* what) { std::cerr << "Excess exception: " << what << '\n'; t.nfail++; } if (t.nfail > 0) { std::cerr << "\nTotal failures: " << t.nfail << '\n'; return EXIT_FAILURE; } return EXIT_SUCCESS; }