⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdp2test.cxx

📁 SIP 1.5.0源代码
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */#include"global.h"#include <string>#include <fstream.h>#include <unistd.h>#include "Sdp2Session.hxx"#include "VTest.hxx"#define OPTIONS "f:l:v"using Vocal::SDP::SdpSession;booltestEncode (SdpSession& sd){    cpLog (LOG_DEBUG, "------- Test encode() begin -------");    // Session Description    // v=0 by default - no other value as of now    // o= owner/creator and session identifier    // s= session name    // i=* session information    // u=* URI of description    // e=* email address    // p=* phone number    // c=* connection information (not required if included in all media    // b=* bandwidth information        // Time Description        // t= time the session is active        // r=* zero or more repeated times    // z=* time zone adjustment    // k=* encryption key    // Verify    cout << sd.encode();    cpLog (LOG_DEBUG, "------- Test encode() end -------");    return true;}    // testEncodebooltestDump(split_t& tc_files, bool verbose){    cpLog (LOG_DEBUG, "------- Test Dump() begin -------");    split_t::iterator linecount = tc_files.begin();    while (linecount != tc_files.end())    {        // Get test case file name and throw away the description        string tc_in;        string record;        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";        // Open and read the test case input file        ifstream ifs(tc_in.c_str(), ios::in);        char buffer[4096];        string sdp;        sdp.erase();        if (!ifs)        {            cpLog(LOG_ERR, "Cannot open input file: %s ", tc_in.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());        // Decode input file into SDP object            SdpSession sdpDesc;           sdpDesc.decode(sdp);/*           if (!sdpDesc.dump(sdpDesc))            return false;*/        ++linecount;    }    cpLog (LOG_DEBUG, "------- Test Dump() end -------");    return true;}    // testDumpbooltestDecode(split_t& tc_files, bool verbose){    cpLog (LOG_DEBUG, "------- Test decode() 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) + "_encode" + ".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());        // Decode input file into SDP object            SdpSession sdpDesc;           sdpDesc.decode(sdp);        // Encode the object into SDP string and write it to output file         // for verification           ofs << sdpDesc.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 decode() end -------");    return same;}    // testDecodebooltestAssignOperator(split_t& tc_files, bool verbose){    cpLog (LOG_DEBUG, "------- Test operator= 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) +"_assign" + ".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());        // Decode input file into SDP object            SdpSession sdpDesc, sdpAssign;           sdpDesc.decode(sdp);        sdpAssign = sdpDesc;        // Encode the assign object into SDP string and write         // it to output file for verification           ofs << sdpAssign.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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -