📄 dataverify.cxx
字号:
/* ==================================================================== * 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/>. * */static const char* const DataVerify_cxx_Version = "$Id: DataVerify.cxx,v 1.1.2.2 2003/01/30 22:39:10 bko Exp $";#include "Data.hxx"#include "Verify.hxx"#include <vector>//#include "CopyOnWriteData.hxx"//#include "StringData.hxx"template <class DataClass>void test(){ { DataClass xyz("AllCaps"); xyz.uppercase(); test_verify(xyz == "ALLCAPS"); xyz.lowercase(); test_verify(xyz == "allcaps"); } { DataClass xyz("allcaps"); test_verify("allcaps" == xyz); test_verify("allCaps" != xyz); } /// test parseOutsideQuotes { DataClass test("\"Ogawa, Bryan\" <sip:bko@cisco.com,foo,bar,city>,\"Doe, John\" <sip:johnd@test.com,,>,Test Person <sip:test@test.com>"); bool fail; DataClass a = test.parseOutsideQuotes(",", true, true, &fail); test_verify(fail == false); DataClass b = test.parseOutsideQuotes(",", true, true, &fail); test_verify(a == "\"Ogawa, Bryan\" <sip:bko@cisco.com,foo,bar,city>"); test_verify(b == "\"Doe, John\" <sip:johnd@test.com,,>"); test_verify(test == "Test Person <sip:test@test.com>"); test_verify(fail == false);// cout << a << endl;// cout << b << endl; } { DataClass test("\",,,\" <,,,,>,\",,\" <,,>,\",,,\"<,,,>"); bool fail; DataClass a = test.parseOutsideQuotes(",", true, false, &fail); test_verify(a == "\",,,\" <"); test = "<,,,,> \",,\" <,,>,\",,,\"<,,,>"; DataClass b = test.parseOutsideQuotes(",", false, true, &fail); test_verify(b == "<,,,,> \""); test = "<<,<,<,,,<,<,<, ,,,, , , >,> "; DataClass c = test.parseOutsideQuotes(",", false, true, &fail); test_verify(c == "<<,<,<,,,<,<,<, ,,,, , , >"); } /// test parse { bool fail; DataClass test = "this is a simple test"; DataClass a = test.parse(" ", &fail); test_verify(fail == false); test_verify(a == "this"); DataClass b = test.parse(" ", &fail); test_verify(fail == false); test_verify(b == "is"); DataClass c = test.parse(" ", &fail); test_verify(fail == false); test_verify(c == "a"); DataClass d = test.parse(" ", &fail); test_verify(fail == false); test_verify(d == "simple"); DataClass e = test.parse(" ", &fail); test_verify(fail == true); test_verify(test == "test"); } // more tests of parse { bool fail; DataClass test = "this is a simple test"; { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == "thi"); } { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == " i"); } { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == " "); } { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == " "); } { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == "imp"); } { DataClass a = test.parse("sal", &fail); test_verify(fail == false); test_verify(a == "e te"); } { DataClass a = test.parse("sal", &fail); test_verify(fail == true); test_verify(test == "t"); } } { DataClass test = "From: testItem"; bool fail; DataClass a = test.parse(": ", &fail); test_verify(fail == false); test_verify(a == "From"); test_verify(test == "testItem"); } { DataClass test; test = DataClass("a") + DataClass("b"); test_verify(test == "ab"); DataClass second = "Ogawa"; test = DataClass("Bryan ") + second; test_verify(test == "Bryan Ogawa"); DataClass number = "7"; DataClass result; result = DataClass("Wigets: ") + number; test_verify(result == "Wigets: 7"); } { DataClass test0 = "random junk asdf this is a test"; DataClass test1; int retn = test0.match("asdf", &test1, true, "hello"); test_verify(retn == FOUND); test_verify (test0 == "hello this is a test"); test_verify (test1 == "random junk "); } { DataClass test0 = "random junk asdf asdf this is a test"; DataClass test1; int retn = test0.match("asdf", &test1, true, "hello"); test_verify(retn == FOUND); test_verify (test0 == "hello asdf this is a test"); test_verify (test1 == "random junk "); } { DataClass test0 = "random junk asdf asdf this is a test"; DataClass test1; int retn = test0.match("asdf", &test1, false, ""); test_verify(retn == FOUND); test_verify (test0 == "random junk asdf asdf this is a test"); test_verify (test1 == "random junk "); } { DataClass msg1("From: test1@test.com\r\nTo: test2@test2.com\r\nCall-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\r\n"); DataClass msg2("From: test1@test.com\r\nTo: test2@test2.com\r\nCall-ID: e81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\r\n"); test_verify( !(msg1 < msg2) ); } { DataClass msg1("hello"); DataClass msg2("Hello"); test_verify ( isEqualNoCase(msg1, msg2) == true ); DataClass msg3("HeLLo"); DataClass msg4("hEllO"); test_verify ( isEqualNoCase(msg3, msg4) == true ) ; DataClass msg5("HeLLo"); DataClass msg6("hEllOo"); test_verify ( isEqualNoCase(msg5, msg6) == false ); DataClass msg7("HeLLoo"); DataClass msg8("hEllO"); test_verify ( isEqualNoCase(msg7, msg8) == false ); } { DataClass one = "data one"; DataClass two = "data two"; DataClass three = one + two; test_verify (three == "data onedata two"); } { DataClass one = "data one"; DataClass two = "data two"; one += two; test_verify (one == "data onedata two"); } { DataClass one = "abcd"; DataClass two = one; two.setchar(0, 'z'); two.setchar(1, 'y'); two.setchar(2, 'x'); two.setchar(3, 'w'); test_verify ( (one == "abcd") && (two == "zyxw")); } { DataClass junk; test_verify(junk == ""); } { DataClass junk = Data(7); test_verify(junk == "7"); } { DataClass junk; junk = Data(7); test_verify (junk == "7"); } { DataClass junk; junk = "Content-Length: "; junk += Data(7); test_verify (junk == "Content-Length: 7"); } { DataClass junk = "asnf abcd"; DataClass rest; test_verify (junk.match("d", &rest, true) == FOUND); test_verify (rest == "asnf abc"); test_verify (junk == ""); } { DataClass test0 = "1024"; DataClass test1 = "1000x1000"; DataClass test2 = " 1000"; DataClass test3 = "1000 1000";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -