示例#1
0
static void test_response()
{
    static const struct {
            int         d_line;
            std::string d_input_file;
            std::string d_expected_output_file;
        } DATA[] = {
            // LINE             // INPUT            //EXP
            {L_,                "testFiles/200",    "testFiles/200"},
            {L_,                "testFiles/400",    "testFiles/400"},
            {L_,                "testFiles/304",    "testFiles/304"},
        };
        
        const size_t NUM_DATA = sizeof (DATA) / sizeof (*DATA);
        
        for (size_t ti = 0; ti < NUM_DATA; ++ti) {
            const int     LINE            = DATA[ti].d_line;
            const char   *INPUT_FILE      = DATA[ti].d_input_file.c_str();
            const char   *EXP_OUTPUT_FILE = DATA[ti].d_expected_output_file.c_str();
            
            // read in the files
            const std::string INPUT      = get_file_contents(INPUT_FILE);
            const size_t      LEN_INPUT  = INPUT.length();
            const std::string EXP_OUTPUT = get_file_contents(EXP_OUTPUT_FILE);
            char             *output     = new char[LEN_INPUT];
            HttpResponse rep;
            
            if (veryVeryVerbose) { T_ P(LINE) };
            // parse the input file into a response object
            rep.ParseResponse(INPUT.c_str(), LEN_INPUT);
            
            // output the response back into a string
            rep.FormatResponse(output);
            output[LEN_INPUT] = '\0';
            // compare the output from the Response object to the expected value
            ASSERT(std::string(output) == EXP_OUTPUT);
            
            delete [] output;
        }
}