Exemple #1
0
    void testBinary() {
        report(0,"testing binary representation...");
        BottleImpl bot;
        bot.addInt(5);
        bot.addString("hello");
        checkEqual(bot.isInt(0),true,"type check");
        checkEqual(bot.isString(1),true,"type check");
        ManagedBytes store(bot.byteCount());
        bot.toBytes(store.bytes());
        BottleImpl bot2;
        bot2.fromBytes(store.bytes());
        checkEqual((int)bot2.size(),2,"recovery binary, length");
        checkEqual(bot2.isInt(0),bot.isInt(0),"recovery binary, integer");
        checkEqual(bot2.isString(1),bot.isString(1),"recovery binary, integer");
        BottleImpl bot3;
        bot3.fromString("[go] (10 20 30 40)");
        ManagedBytes store2(bot3.byteCount());
        bot3.toBytes(store2.bytes());
        bot.fromBytes(store2.bytes());
        checkEqual(bot.get(0).isVocab(),true,"type check");
        checkEqual(bot.get(1).isList(),true,"type check");

        Bottle bot4("0 1 2.2 3");
        size_t hsize;
        const char *hbuf = bot4.toBinary(&hsize);
        Bottle bot5;
        bot5.fromBinary(hbuf,hsize);
        checkEqual(bot5.size(),4,"player bug");

    }
Exemple #2
0
 void testSize() {
     report(0,"testing sizes...");
     BottleImpl bot;
     checkEqual(0,(int)bot.size(),"empty bottle");
     bot.addInt(1);
     checkEqual(1,(int)bot.size(),"add int");
     bot.addString("hello");
     checkEqual(2,(int)bot.size(),"add string");
     bot.clear();
     checkEqual(0,(int)bot.size(),"clear");
 }
Exemple #3
0
 void testString() {
     report(0,"testing string representation...");
     String target = "hello \"my\" \\friend";
     BottleImpl bot;
     bot.addInt(5);
     bot.addString("hello \"my\" \\friend");
     String txt = bot.toString();
     const char *expect = "5 \"hello \\\"my\\\" \\\\friend\"";
     checkEqual(txt,expect,"string rep");
     BottleImpl bot2;
     bot2.fromString(txt);
     checkEqual(2,(int)bot2.size(),"return from string rep");
 }
Exemple #4
0
    void testStreaming() {
        report(0,"testing streaming (just text mode)...");

        BottleImpl bot;
        bot.addInt(5);
        bot.addString("hello");

        BufferedConnectionWriter bbw(true);
        bot.write(bbw);
      
        String s;
        StringInputStream sis;
        StreamConnectionReader sbr;
      
        s = bbw.toString();
        sis.add(s);
        Route route;
        sbr.reset(sis,NULL,route,s.length(),true);
      
        BottleImpl bot2;
        bot2.read(sbr);
        checkEqual(bot2.toString(),bot.toString(),"to/from stream");

    }