DataVerify.cxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:12k
- /* ====================================================================
- * 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.4 2001/07/25 21:06:31 bko Exp $";
- #include "Data.hxx"
- #include "Verify.hxx"
- void test()
- {
- {
- Data xyz("AllCaps");
-
- xyz.uppercase();
- test_verify(xyz == "ALLCAPS");
-
- xyz.lowercase();
- test_verify(xyz == "allcaps");
- }
- {
- Data xyz("allcaps");
- test_verify("allcaps" == xyz);
- test_verify("allCaps" != xyz);
- }
- /// test parseOutsideQuotes
- {
- Data test(""Ogawa, Bryan" <sip:bko@cisco.com,foo,bar,city>,"Doe, John" <sip:johnd@test.com,,>,Test Person <sip:test@test.com>");
- bool fail;
- Data a = test.parseOutsideQuotes(",", true, true, &fail);
- test_verify(fail == false);
- Data 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;
- }
- {
- Data test("",,," <,,,,>,",," <,,>,",,,"<,,,>");
- bool fail;
- Data a = test.parseOutsideQuotes(",", true, false, &fail);
- test_verify(a == "",,," <");
- test = "<,,,,> ",," <,,>,",,,"<,,,>";
- Data b = test.parseOutsideQuotes(",", false, true, &fail);
- test_verify(b == "<,,,,> "");
- test = "<<,<,<,,,<,<,<, ,,,, , , >,> ";
- Data c = test.parseOutsideQuotes(",", false, true, &fail);
- test_verify(c == "<<,<,<,,,<,<,<, ,,,, , , >");
- }
- /// test parse
- {
- bool fail;
- Data test = "this is a simple test";
- Data a = test.parse(" ", &fail);
- test_verify(fail == false);
- test_verify(a == "this");
- Data b = test.parse(" ", &fail);
- test_verify(fail == false);
- test_verify(b == "is");
- Data c = test.parse(" ", &fail);
- test_verify(fail == false);
- test_verify(c == "a");
- Data d = test.parse(" ", &fail);
- test_verify(fail == false);
- test_verify(d == "simple");
- Data e = test.parse(" ", &fail);
- test_verify(fail == true);
- test_verify(test == "test");
- }
- // more tests of parse
- {
- bool fail;
- Data test = "this is a simple test";
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == "thi");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == " i");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == " ");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == " ");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == "imp");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == false);
- test_verify(a == "e te");
- }
- {
- Data a = test.parse("sal", &fail);
- test_verify(fail == true);
- test_verify(test == "t");
- }
- }
- {
- Data test = "From: testItem";
- bool fail;
- Data a = test.parse(": ", &fail);
- test_verify(fail == false);
- test_verify(a == "From");
- test_verify(test == "testItem");
- }
- {
- Data test;
- test = Data("a") + Data("b");
- test_verify(test == "ab");
- Data second = "Ogawa";
- test = "Bryan " + second;
- test_bug(test == "Bryan Ogawa");
- Data number = "7";
- Data result;
-
- result = "Wigets: " + number;
- test_bug(result == "Wigets: 7");
- }
- {
- Data test0 = "random junk asdf this is a test";
- Data 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 ");
- }
- {
- Data msg1("From: test1@test.comrnTo: test2@test2.comrnCall-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.comrn");
- Data msg2("From: test1@test.comrnTo: test2@test2.comrnCall-ID: e81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.comrn");
- test_verify( !(msg1 < msg2) );
- }
- {
- Data msg1("hello");
- Data msg2("Hello");
- test_verify ( isEqualNoCase(msg1, msg2) == true );
- Data msg3("HeLLo");
- Data msg4("hEllO");
- test_verify ( isEqualNoCase(msg3, msg4) == true ) ;
- Data msg5("HeLLo");
- Data msg6("hEllOo");
- test_verify ( isEqualNoCase(msg5, msg6) == false );
- Data msg7("HeLLoo");
- Data msg8("hEllO");
- test_verify ( isEqualNoCase(msg7, msg8) == false );
- }
- {
- Data one = "data one";
- Data two = "data two";
- Data three = one + two;
- test_verify (three == "data onedata two");
- }
- {
- Data one = "data one";
- Data two = "data two";
- one += two;
- test_verify (one == "data onedata two");
- }
- {
- Data one = "abcd";
- Data two = one;
-
- two.setchar(0, 'z');
- two.setchar(1, 'y');
- two.setchar(2, 'x');
- two.setchar(3, 'w');
- test_verify ( (one == "abcd") && (two == "zyxw"));
- }
- {
- Data junk;
- test_verify(junk == "");
- }
- {
- Data junk = 7;
- test_verify(junk == "7");
- }
- {
- Data junk;
- junk = 7;
- test_verify (junk == "7");
- }
- {
- Data junk;
- junk = "Content-Length: ";
- junk += 7;
- test_verify (junk == "Content-Length: 7");
- }
- {
- Data junk = "asnf abcd";
- Data rest;
-
- test_verify (junk.match("d", &rest, true) == FOUND);
- test_verify (rest == "asnf abc");
- test_verify (junk == "");
- }
- {
- Data test0 = "1024";
- Data test1 = "1000x1000";
- Data test2 = " 1000";
- Data test3 = "1000 1000";
- Data test4 = "19238471832758715289725371";
- Data test5 = "4000@";
- test_verify(int(test0) == 1024);
- test_verify(int(test1) == 1000);
- test_verify (int(test2) == 0);
- test_verify(int(test3) == 1000);
- test_verify (int(test5) == 4000);
- }
- {
- Data j = "asnf abcd";
- string s = j;
- test_verify (Data(s) == j);
- }
- {
- const int MAX_TESTS = 25;
-
- Data data[MAX_TESTS];
- data[0] = "Testing Data";
- test_verify (strcmp(data[0].getData(), "Testing Data") == 0);
- data[1] = data[0];
- test_verify (strcmp(data[1].getData(), "Testing Data") == 0);
- data[2] = "Testing Data";
- data[2] += "added data";
- test_verify (strcmp(data[2].getData(), "Testing Dataadded data") == 0);
- data[3] = data[1] + data[2];
- test_verify (data[3] == "Testing DataTesting Dataadded data");
- string str("This is a string");
- Data data4(str);
- test_verify (data4 == "This is a string");
- mstring mstr("This is a mstring");
- Data data5(mstr);
- test_verify (data5 == "This is a mstring");
- int value = 5;
- Data data6(value);
- test_verify (data6 == "5");
- Data testData;
- testData = "alphb";
-
- data[7] = "alpha";
-
- test_verify ((data[7] < testData) &&
- !(data[7] == testData) &&
- !(data[7] > testData) &&
- (data[7] != testData));
- data[8] = "alphc";
- test_verify ((data[8] > testData) &&
- !(data[8] == testData) &&
- !(data[8] < testData) &&
- (data[8] != testData));
- data[9] = "alphb";
- test_verify ((data[9] == testData) &&
- !(data[9] < testData) &&
- !(data[9] > testData) &&
- !(data[9] != testData));
- data[10] = "alphbx";
-
- test_verify ((data[10] > testData) &&
- !(data[10] < testData) &&
- !(data[10] == testData) &&
- (data[10] != testData));
- data[11] = "hello, world!";
-
- char newstr[256];
- strcpy(newstr, data[11].getData());
-
- test_verify (
- (strcmp(newstr, "hello, world!") == 0) && (data[11].length() == 13));
- }
- {
- Data test = "Hello, world!";
- Data test2 = "Hello";
- test_verify ( test > "Hello");
- test_verify ( test > test2);
- test_verify ( "Hello" < test);
- test_verify ( test2 < test );
- }
- {
- // test lowercase() and uppercase()
- Data test = "Hello, World!";
- test.lowercase();
- test_verify(test == "hello, world!");
- test_verify(test != "Hello, World!");
- Data test2 = "Hello, World!";
- test2.uppercase();
- test_verify(test2 == "HELLO, WORLD!");
- test_verify(test2 != "Hello, World!");
- }
- /// test matchChar
- {
- char fail;
- Data test = "this is a simple test";
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 's');
- test_verify(a == "thi");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 's');
- test_verify(a == " i");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 'a');
- test_verify(a == " ");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 's');
- test_verify(a == " ");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 'l');
- test_verify(a == "imp");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == 's');
- test_verify(a == "e te");
- }
- {
- Data a = test.matchChar("sal", &fail);
- test_verify(fail == ' ');
- test_verify(test == "t");
- }
- }
- {
- Data test = "From: testItem";
- char fail;
- Data a = test.matchChar(": ", &fail);
- test_verify(fail == ':');
- test_verify(a == "From");
- test_verify(test == " testItem");
- }
- // test getLine
- {
- Data test = "testntestrntestrn";
- {
- bool fail;
- Data a = test.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "test");
- }
- {
- bool fail;
- Data a = test.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "test");
- }
- {
- bool fail;
- Data a = test.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "test");
- }
- {
- bool fail;
- Data a = test.getLine(&fail);
- test_verify(fail == true);
- }
- Data test2 = "testrnrntestrn";
- {
- bool fail;
- Data a = test2.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "test");
- }
- {
- bool fail;
- Data a = test2.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "");
- }
- {
- bool fail;
- Data a = test2.getLine(&fail);
- test_verify(fail == false);
- test_verify(a == "test");
- }
- }
- // test removeLWS
- {
- Data test = "From: testrn continuationrn test2rn";
- test.removeLWS();
- // cout << test;
- test_verify(test == "From: testrn continuation test2n");
- }
- }
- int main()
- {
- test();
- return test_return_code(117);
- }