📄 sdp2test.cxx
字号:
} } if (same) cpLog(LOG_DEBUG, "In & out are identical"); else cpLog(LOG_DEBUG, "In & out are different"); ++linecount; } cpLog (LOG_DEBUG, "------- Test operator= end -------"); return same;} // testAssignOperatorbooltestCopyConstructor(split_t& tc_files, bool verbose){ cpLog (LOG_DEBUG, "------- Test copy constructor begin -------"); bool same = true; split_t::iterator linecount = tc_files.begin(); while (linecount != tc_files.end()) { string tc_in, tc_out; string record; // Get test case file name and throw away the description record = (*linecount); split_t lines(split(record, ":")); split_t::iterator filename; filename = lines.begin(); // Generate test case input & outp file names tc_in = (*filename) + ".in"; tc_out = (*filename) +"_copy" + ".out"; // Open and read the test case input file ifstream ifs(tc_in.c_str(), ios::in); fstream ofs(tc_out.c_str(), ios::in | ios::out); char buffer[4096]; string sdp; sdp.erase(); if (!ifs) { cpLog(LOG_ERR, "Cannot open input file: %s ", tc_in.c_str()); return false; } if (!ofs) { cpLog(LOG_ERR, "Cannot open out file: %s ", tc_out.c_str()); return false; } // Read in the SDP packet from file while (!ifs.eof()) { ifs.getline(buffer, sizeof(buffer), '\n'); sdp += buffer; sdp += "\n"; } if (verbose) cpLog(LOG_DEBUG, "String constructed from input file:\n[%s]", sdp.c_str()); SdpSession sdpDesc; sdpDesc.decode(sdp); SdpSession sdpCopy(sdpDesc); // Encode the object into SDP string and write it to output file // for verification ofs << sdpCopy.encode(); // Compare the input and output files // Reset stream pointers ifs.clear(); ofs.clear(); char in_char, out_char; while (ifs.get(in_char)) { ofs.get(out_char); if (out_char == '\r') { // throw waay the '\r' character ofs.get(out_char); } if (in_char != out_char) { same = false; cpLog(LOG_ERR, "In & out are different: in=\"%c\", out=\"%c\"", in_char, out_char); break; } } if (same) cpLog(LOG_DEBUG, "In & out are identical"); else cpLog(LOG_DEBUG, "In & out are different"); ++linecount; } cpLog (LOG_DEBUG, "------- Test copy constructor end -------"); return same;} // testCopyConstructorbooltestNcsSdp (){ cpLog (LOG_DEBUG, "------- Test NCS SDP begin -------"); try { SdpSession ncs; cpLog (LOG_DEBUG, "Check NCS conformance from default constructor"); cpLog (LOG_DEBUG, "The verdict should be FAILED"); if (ncs.verify (Vocal::SDP::SdpProtocolTypeNCS)) { cpLog (LOG_ERR, "Results: PASSED"); } cpLog (LOG_DEBUG, "Check NCS conformance after setting Protocol Type to NCS"); ncs.setProtocolType (Vocal::SDP::SdpProtocolTypeNCS); if (ncs.verify (Vocal::SDP::SdpProtocolTypeNCS)) { cpLog (LOG_DEBUG, "Results: PASSED"); } else return false; ncs.setAddress ("gauss.private.vovida.com"); (ncs.getConnection())->setUnicast ("192.168.5.2"); (*(ncs.getMediaList()).begin())->setPort (28888); cpLog (LOG_DEBUG, "Check NCS conformance filling in the rest"); if (ncs.verify (Vocal::SDP::SdpProtocolTypeNCS)) { cpLog (LOG_DEBUG, "Results: PASSED"); } else return false; } catch (Vocal::SDP::SdpExceptions& err) { cpLog (LOG_ERR, "Got Exception: %d", err.value); return false; } cpLog (LOG_DEBUG, "------- Test NCS SDP end -------"); return true;} // testNcsSdpintmain(int argc, char *argv[]){ string tc_file = "../testCases/SDP_tc"; // Default test case file name string log_file = "SdpTest.log"; // Default log file name bool verbose = false; if (argc > 1) { char c; while ((c = getopt(argc, argv, OPTIONS)) != -1) { switch (c) { case 'f': tc_file = optarg; break; case 'l': log_file = optarg ; log_file += ".log"; break; case 'v': verbose = true; break; default: cerr << "Unknow option: \"" << c << "\"" << endl; } } } ifstream ifs(tc_file.c_str(), ios::in); char buffer[256]; string s; s.erase(); if (!ifs) { cpLog(LOG_ERR, "Cannot open input file: %s ", tc_file.c_str()); return false; } while (!ifs.eof()) { ifs.getline(buffer, sizeof(buffer), '\n'); s += buffer; s += "\n"; } // read in all test case file names & store by sections split_t lines(split(s, "\n")); split_t tc_decode; split_t tc_assign_op; split_t tc_copy_const; split_t tc_NCS; split_t tc_dump; split_t::iterator linecount = lines.begin(); while (linecount != lines.end()) { if ((*linecount)[0] == '/') { /// Throw away comment lines ++linecount; continue; } string line = (*linecount); int pos = line.find(']'); string sec_label = line.substr(0,pos+1); if (sec_label == "[DECODE]") { ++linecount; while ((linecount != lines.end()) && ((*linecount)[0] != '[')) { if ((*linecount)[0] == '/') { ++linecount; continue; } (tc_decode).push_back(*linecount); ++linecount; } } else if (sec_label == "[ASSIGN_OP]") { ++linecount; while ((linecount != lines.end()) && ((*linecount)[0] != '[')) { if ((*linecount)[0] == '/') { ++linecount; continue; } (tc_assign_op).push_back(*linecount); ++linecount; } } else if (sec_label == "[COPY_CONST]") { ++linecount; while ((linecount != lines.end()) && ((*linecount)[0] != '[')) { if ((*linecount)[0] == '/') { ++linecount; continue; } (tc_copy_const).push_back(*linecount); ++linecount; } } else if (sec_label == "[NCS]") { ++linecount; while ((linecount != lines.end()) && ((*linecount)[0] != '[')) { if ((*linecount)[0] == '/') { ++linecount; continue; } (tc_NCS).push_back(*linecount); ++linecount; } } else if (sec_label == "[DUMP]") { ++linecount; while ((linecount != lines.end()) && ((*linecount)[0] != '[')) { if ((*linecount)[0] == '/') { ++linecount; continue; } (tc_dump).push_back(*linecount); ++linecount; } } else { cpLog(LOG_ERR, "Unknown section label: %s ", (*linecount).c_str()); return false; } } VTest sdpTest(__FILE__); cpLogOpen(log_file.c_str()); cpLogSetLabel ("SdpTest"); cpLogSetPriority (LOG_DEBUG_STACK); if (verbose) { cpLog(LOG_DEBUG, "Test Case File = \"%s\"", tc_file.c_str()); cpLog(LOG_DEBUG, "Log File = \"%s\"", tc_file.c_str()); cpLog(LOG_DEBUG, "Verbose = \"%s\"", verbose ? "ON" : "OFF"); } sdpTest.test(1, testDecode(tc_decode, verbose), "Testing encode functionality"); sdpTest.test(2, testAssignOperator(tc_assign_op, verbose), "Testing assign opertor"); sdpTest.test(3, testCopyConstructor(tc_copy_const, verbose), "Testing copy constructor"); sdpTest.test(4, testNcsSdp(), "Testing NCS conformance");// sdpTest.test(5, testDump(tc_dump, verbose), "Testing dump functionality"); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -