void draw_grid(int i,int j,int k)                       //This draws the grid and changes the color the grid according to the player
{   beginFrame();
    Line h1(0,0,600,0),h2(0,100,600,100),               // "h" is the horizontal lines and "v" is the vertical lines
    h3(0,200,600,200),h4(0,300,600,300),
    h5(0,400,600,400),h6(0,500,600,500),
    h7(0,600,600,600),h8(0,700,600,700),
    h9(0,800,600,800);
    Line v1(0,0,0,800),v2(100,0,100,800),
    v3(200,0,200,800),v4(300,0,300,800),
    v5(400,0,400,800),v6(500,0,500,800),
    v7(600,0,600,800);
    h1.setColor(COLOR(255*i,255*j,255*k)),h2.setColor(COLOR(255*i,255*j,255*k)),
    h3.setColor(COLOR(255*i,255*j,255*k)),h4.setColor(COLOR(255*i,255*j,255*k)),
    h5.setColor(COLOR(255*i,255*j,255*k)),h6.setColor(COLOR(255*i,255*j,255*k)),
    h7.setColor(COLOR(255*i,255*j,255*k)),h8.setColor(COLOR(255*i,255*j,255*k)),
    h9.setColor(COLOR(255*i,255*j,255*k));
    v1.setColor(COLOR(255*i,255*j,255*k)),v2.setColor(COLOR(255*i,255*j,255*k)),
    v3.setColor(COLOR(255*i,255*j,255*k)),v4.setColor(COLOR(255*i,255*j,255*k)),
    v5.setColor(COLOR(255*i,255*j,255*k)),v6.setColor(COLOR(255*i,255*j,255*k)),
    v7.setColor(COLOR(255*i,255*j,255*k));
    h1.imprint(),h2.imprint(),
    h3.imprint(),h4.imprint(),
    h5.imprint(),h6.imprint(),
    h7.imprint(),h8.imprint(),h9.imprint();
    v1.imprint(),v2.imprint(),
    v3.imprint(),v4.imprint(),
    v5.imprint(),v6.imprint(),v7.imprint();
    endFrame();
}
Esempio n. 2
0
static void getBlockHeader(
    size_t        &size,
    Block        *&prev,
    uint8_t      *&hash,
    size_t        &earlyMissCnt,
    const uint8_t *p
) {

    LOAD(uint32_t, magic, p);
    if(unlikely(gExpectedMagic!=magic)) {
        hash = 0;
        return;
    }

    LOAD(uint32_t, sz, p);
    size = sz;
    prev = 0;

    hash = allocHash256();

    #if defined(DARKCOIN)
        h9(hash, p, gHeaderSize);
    #elif defined(PAYCON)
        h13(hash, p, gHeaderSize);
    #elif defined(CLAM)
        auto pBis = p;
        LOAD(uint32_t, nVersion, pBis);
        if(6<nVersion) {
            sha256Twice(hash, p, gHeaderSize);
        } else {
            scrypt(hash, p, gHeaderSize);
        }
    #elif defined(JUMBUCKS)
        scrypt(hash, p, gHeaderSize);
    #else
        h9(hash, p, gHeaderSize);
    #endif

    auto i = gBlockMap.find(p + 4);
    if(likely(gBlockMap.end()!=i)) {
        prev = i->second;
    } else {
        ++earlyMissCnt;
    }
}
Esempio n. 3
0
void test01()
{
    {
        String on1;
        on1 = "//atp:77/root/cimv25:"
              "TennisPlayer.last=\"Rafter\",first=\"Patrick\"";

        String on2;
        on2 = "//atp:77/root/cimv25:"
              "TennisPlayer.first=\"Patrick\",last=\"Rafter\"";

        CIMObjectPath r = on1;
        PEGASUS_TEST_ASSERT(r.toString() != on1);
        PEGASUS_TEST_ASSERT(r.toString() == on2);

        CIMObjectPath r2 = r;
        CIMObjectPath r3 = CIMObjectPath
            ("//atp:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");

        if (verbose)
        {
            XmlWriter::printValueReferenceElement(r, false);
            cout << r.toString() << endl;
        }

        Buffer mofOut;
        MofWriter::appendValueReferenceElement(mofOut, r);
        r.clear();
    }

    {
        CIMObjectPath r1 = CIMObjectPath
            ("MyClass.z=true,y=1234,x=\"Hello World\"");
        CIMObjectPath r2 = CIMObjectPath
            ("myclass.X=\"Hello World\",Z=true,Y=1234");
        CIMObjectPath r3 = CIMObjectPath ("myclass.X=\"Hello\",Z=true,Y=1234");
        // cout << r1.toString() << endl;
        // cout << r2.toString() << endl;
        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1 != r3);
    }

    // Test case independence and order independence of parameters.
    {
        CIMObjectPath r1 = CIMObjectPath ("X.a=123,b=true");
        CIMObjectPath r2 = CIMObjectPath ("x.B=TRUE,A=123");
        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1.makeHashCode() == r2.makeHashCode());

        CIMObjectPath r3 = CIMObjectPath ("x.B=TRUE,A=123,c=FALSE");
        PEGASUS_TEST_ASSERT(r1 != r3);
        String keyValue;

        Array<CIMKeyBinding> kbArray;
        {
            Boolean found = false;
            kbArray = r3.getKeyBindings();
            for (Uint32 i = 0; i < kbArray.size(); i++)
            {
                if (verbose)
                {
                    cout << "keyName= " <<  kbArray[i].getName().getString()
                         << " Value= " << kbArray[i].getValue() << endl;
                }
                if ( kbArray[i].getName() == CIMName ("B") )
                {
                    keyValue = kbArray[i].getValue();
                    if(keyValue == "TRUE")
                    found = true;
                }
            }
            if(!found)
            {
                cerr << "Key Binding Test error " << endl;
                exit(1);
            }
            //ATTN: KS 12 May 2002 P3 DEFER - keybinding manipulation. too
            // simplistic.
            // This code demonstrates that it is not easy to manipulate and
            // test keybindings.  Needs better tool both in CIMObjectPath and
            // separate.
        }
    }


    // Test building from component parts of CIM Reference.
    {
        CIMObjectPath r1 ("atp:77", CIMNamespaceName ("root/cimv25"),
            CIMName ("TennisPlayer"));
        CIMObjectPath r2 ("//atp:77/root/cimv25:TennisPlayer.");
        //cout << "r1 " << r1.toString() << endl;
        //cout << "r2 " << r2.toString() << endl;

        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1.toString() == r2.toString());

    }


    {
        String hostName = "atp:77";
        String nameSpace = "root/cimv2";
        String className = "tennisplayer";

        CIMObjectPath r1;
        r1.setHost(hostName);
        r1.setNameSpace(nameSpace);
        r1.setClassName(className);
        PEGASUS_TEST_ASSERT(r1.getClassName().equal(CIMName ("TENNISPLAYER")));
        PEGASUS_TEST_ASSERT(!r1.getClassName().equal(CIMName ("blob")));


        String newHostName = r1.getHost();
        //cout << "HostName = " << newHostName << endl;

        CIMObjectPath r2 (hostName, nameSpace, className);
        PEGASUS_TEST_ASSERT(r1 == r2);
    }

    // Test cases for the Hostname.  CIMObjectPaths allows the
    // host to include the domain. Eg. xyz.company.com

    // First, try a good hostname
    CIMObjectPath h0("//usoPen-9.ustA-1-a.org:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h1("//usoPen-9:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h2("//usoPen-9/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h3("//usoPen-9.ustA-1-a.org:0/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h4("//usoPen-9.ustA-1-a.org:9876/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h5("//usoPen-9.ustA-1-a.org:65535/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h6("//usopen-9.usta-1-a.1org:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h7("//192.168.1.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h8("//192.168.0.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h9("//192.168.1.80.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h10("//192.168.0.80.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h11("//192.168.1.80.255.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h12("//192.168.0.80.254.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h13("//192.168.257.80.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h14("//192.256.0.80.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath h15("//localhost/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h16("//ou812/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h17("//u812/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    // Hostname with '_' character support checks, see bug#2556.
    CIMObjectPath h18("//_atp:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h19("//a_tp/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h20("//atp_:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h21("//atp_-9:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h22(
        "//_a_t_p_-9.ustA-1-a.org:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h23("//_/root/cimv25:_TennisPlayer");
    CIMObjectPath h24("//_______/root/cimv25:_TennisPlayer");

    // try IPAddress as hostname which should be good
    CIMObjectPath h_ip0("//192.168.1.80:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h_ip1("//192.168.0.255/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    // Try IPv6 Addresses.
    CIMObjectPath ip6_1("//[::1]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_2("//[::ffff:192.1.2.3]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_3("//[fffe:233:321:234d:e45:fad4:78:12]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_4("//[fffe::]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");


    Boolean errorDetected = false;

    // Invalid IPV6 Addresses
    try
    { // IPv6 addresses must be enclosed in brackets
        CIMObjectPath ip6_mb("//fffe::12ef:127/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    { // IPv6 address invalid
        CIMObjectPath ip6_invalid("//[fffe::sd:77]/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:9876543210/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:65536/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:100000/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        //more than three digits in an octect
        CIMObjectPath h_ErrIp0("//192.1600008.1.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Octet out of range
        CIMObjectPath op("//192.168.256.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Missing port is okay, needs be ignored
        CIMObjectPath op("//192.168.1.80:/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(!errorDetected);

    errorDetected = false;
    try
    {
        // Too many octets
        CIMObjectPath op("//192.168.1.80.12/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Too few octets
        CIMObjectPath op("//192.168.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Missing port is okay, needs be ignored
        CIMObjectPath op("//usopen-9.usta-1-a.org:/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(!errorDetected);

    errorDetected = false;
    try
    {
        // Hostname (IP) without trailing '/' (with port)
        CIMObjectPath op("//192.168.256.80:77");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname (IP) without trailing '/' (without port)
        CIMObjectPath op("//192.168.256.80");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname without trailing '/' (with port)
        CIMObjectPath op("//usopen-9.usta-1-a.org:77");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname without trailing '/' (without port)
        CIMObjectPath op("//usopen-9.usta-1-a.org");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Invalid first character
        CIMObjectPath op("//+usopen-9.usta-1-a.1org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Non-alphanum char (?)
        CIMObjectPath op("//usopen-9.usta?-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Leading dot
        CIMObjectPath op("//.usopen-9.usta-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Dot in the wrong spot (before a -)
        CIMObjectPath op("//usopen.-9.usta-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Two dots in a row
        CIMObjectPath op("//usopen-9.usta-1-a..org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Trailing dot
        CIMObjectPath op("//usopen-9.usta-1-a.org.:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);
}
Esempio n. 4
0
int main(int argc, char* argv[]){
    //Test Constructors:
    printf("*******Test for defaut constructor String()*******\n");
    String h1=String();
    printf("String h1 delarated with String h=String()\n");
    printf("c_str: %s \n",h1.c_str());
    printf("Length: %zu \n", h1.length());
    printf("Capacity: %zu \n\n",h1.capacity());
    
    printf("******Test for fill constructor String(size_t n, char c)"
	   "******\n");
    String h2=String(5,'x');
    printf("String h2 delarated with String h2=String(5,'x')\n");
    printf("c_str: %s \n",h2.c_str());
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n\n",h2.capacity());
    
    String h3=String(55,'x');
    printf("String h3 delarated with String h3=String(55,'x')\n");
    printf("c_str: %s \n",h3.c_str());
    printf("Length: %zu \n", h3.length());
    printf("Capacity: %zu \n\n",h3.capacity());
    
    printf("String h4 delarated with String h4=String(155,'x')\n");
    String h4=String(155,'x');
    printf("c_str: %s \n",h4.c_str());    
    printf("Length: %zu \n", h4.length());
    printf("Capacity: %zu \n\n",h4.capacity());
    
    printf("******Test for Copy Constructor String(const String& str)"
	   "*******\n");
    String h5=String(h1);
    printf("String h5 delarated with String h5=String(h1)\n");
    printf("c_str: %s \n",h5.c_str());
    printf("Length: %zu \n", h5.length());
    printf("Capacity: %zu \n\n",h5.capacity());
    //printf("sizeof %lu\n",sizeof(h4.c_str()));
    String h6=String(h4);
    printf("String h6 delarated with String h6=String(h4)\n");
    printf("c_str: %s \n",h6.c_str());
    printf("Length: %zu \n", h6.length());
    printf("Capacity: %zu \n\n",h6.capacity());
	
    printf("******Test for C_str Constructor String(char* s)******\n");
    char c1[]= "abcdefg";
    printf("c1 = %s\n", c1);
    String h7=String(c1);
    printf("String h7 delarated with String h7=String(c1)\n");
    printf("c_str: %s \n",h7.c_str());
    printf("Length: %zu \n", h7.length());
    printf("Capacity: %zu \n\n",h7.capacity());
    
    char c2[]= "12345678901234567890123456789012345678901234567890"
	"123456789012345678901234567890123456789012345678901234567890"
	"1234567890";
    printf("c2 = %s (lenth=110)\n",c2);
    String h8=String(c2);
    printf("String h8 delarated with String h8=String(c2)\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    
    
    //Test of Public Methods
    printf("******Test for resize()******\n");
    h8.resize(5);
    printf("h8.resize(5):\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    h8.resize(0);
    printf("h8.resize(0):\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    h8.resize(120);
    printf("h8.resize(120):\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    h8.resize(0,'c');
    printf("h8.resize(0,'c');:\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    h8.resize(120,'c');
    printf("h8.resize(120,'c'):\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    
    printf("******Test for clear()******\n");
    printf("Before h8.clear\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    h8.clear();
    printf("After h8.clear()\n");
    printf("c_str: %s \n",h8.c_str());
    printf("Length: %zu \n", h8.length());
    printf("Capacity: %zu \n\n",h8.capacity());
    
    printf("*********Test for empty()*******\n");
    printf("String h1 (defined with defaut constructor):\n");
    printf("c_str: %s \n",h1.c_str());
    printf("Length: %zu \n", h1.length());
    printf("Capacity: %zu \n",h1.capacity());
    printf("Empty: %d\n\n",h1.empty());
    printf("String h2:\n");
    printf("c_str: %s \n",h2.c_str());
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n",h2.capacity());
    printf("Empty: %d\n\n",h2.empty());
    
    printf("******Test for reserve()******\n");
    printf("String h2:\n");
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n\n",h2.capacity());
    h2.reserve(4);
    printf("h2.reserve(4)\n");
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n\n",h2.capacity());
    h2.reserve(40);
    printf("h2.reserve(40)\n");
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n\n",h2.capacity());
    h2.reserve(140);
    printf("h2.reserve(140)\n");
    printf("Length: %zu \n", h2.length());
    printf("Capacity: %zu \n\n",h2.capacity());
	
    // test operators
    printf("******Test for operator+(str, str)******\n");
    String h9(10,'9');
    String h10=h9+h3;
    printf("String h10 = String h9 + String h3\n");
    printf("c_str: %s \n",h10.c_str());
    printf("Length: %zu \n", h10.length());
    printf("Capacity: %zu \n\n",h10.capacity());
    printf("String h10 = String h3 + String h9\n");
    h10=h3+h9;
    printf("c_str: %s \n",h10.c_str());
    printf("Length: %zu \n", h10.length());
    printf("Capacity: %zu \n\n",h10.capacity());
    
    printf("******Test for operator+(str, char *)******\n");
    printf("String h11=h9+\"abcdefg\"\n");
    String h11=h9+"abcdefg";
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());
    printf("h11=h9+c1\n");
    h11=h9+c1;
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());

    printf("******Test for operator +(char*, str)******\n");
    printf("h11=c1+h9\n");
    h11=c1+h9;
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());
    printf("h11=c2+h9\n");
    h11=c2+h9;
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());
    
    printf("******Test for operator +(str, char)******\n");
    printf("h11=h9+'z'\n");
    h11=h9+'z';
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());
    printf("h13=h6+'z'\n");
    String h13=h6+'z';
    printf("c_str: %s \n",h13.c_str());
    printf("Length: %zu \n", h13.length());
    printf("Capacity: %zu \n\n",h13.capacity());
    printf("******Test for operator +(str, char)******\n");
    printf("h11='z'+h9\n");
    h11='z'+h9;
    printf("c_str: %s \n",h11.c_str());
    printf("Length: %zu \n", h11.length());
    printf("Capacity: %zu \n\n",h11.capacity());
    printf("h13='z'+h6\n");
    h13='z'+h6;
    printf("c_str: %s \n",h13.c_str());
    printf("Length: %zu \n", h13.length());
    printf("Capacity: %zu \n\n",h13.capacity());
    return 0;
}
Esempio n. 5
0
/* --std=c90 -Wv */
void f1(void) { int i; struct tag { int x; } x; int *p; i(); x(); p(); }
void f2(void) { void h2(int, double); void g2(); h2(0, 1); g2(0, 1); }    /* prototype vs. non-prototype */
void f3(void) { struct tag { int x; } h3(void), x; int g3(void), y; x = h3(); y = g3(); }    /* struct vs. non-struct */
void f4(void) { struct tag h4(void); h4(); }    /* error - incomplete return */
void f5(void) { void h5(int, double); void g5(void); h5(0, 1); g5(); }    /* argument vs. no argument */
void f6(void) { struct tag; void h6(struct tag); struct tag *p; h6(*p); }    /* error - incomplete argument */
void f7(void) { void h7(int, ...); int x; h7(x, x, 0); }    /* arguments to variadic part */
void f8(void) { struct tag { int x; } x; void h8(int, struct tag, int *); h8(&x, x, &x); }    /* error - incompatible argument */
void f9(void) { void h9(char, short, int, long); char c; short s; int i; long l; h9(c, s, i, l); }    /* arguments that promote */