Example #1
0
    void checkAccept() {
        report(0, "checking direct object accept...");

        PortReaderBuffer<Bottle> buffer;
        Bottle dummy;
        Bottle data("hello");
        Bottle data2("there");

        buffer.acceptObject(&data, &dummy);
        
        Bottle *bot = buffer.read();
        checkTrue(bot!=NULL,"Inserted message received");
        if (bot!=NULL) {
            checkEqual(bot->toString().c_str(),"hello","value ok");
        }

        buffer.acceptObject(&data2, NULL);

        bot = buffer.read();
        checkTrue(bot!=NULL,"Inserted message received");
        if (bot!=NULL) {
            checkEqual(bot->toString().c_str(),"there","value ok");
        }
        
        buffer.read(false);
    }
Example #2
0
    void checkTransmit() {
        report(0,"testing pair transmission...");

        PortablePair<Bottle,Bottle> pp;
        pp.head.fromString("1 2 3");
        pp.body.fromString("yes no");

        PortReaderBuffer< PortablePair<Bottle,Bottle> > buf;

        Port input, output;
        input.open("/in");
        output.open("/out");
        buf.setStrict();
        buf.attach(input);
        Network::connect("/out","/in");

        report(0,"writing...");
        output.write(pp);
        report(0,"reading...");
        PortablePair<Bottle,Bottle> *result = buf.read();
        
        checkTrue(result!=nullptr,"got something check");
        if (result!=nullptr) {
            checkEqual(result->head.size(),(size_t) 3,"head len is right");
            checkEqual(result->body.size(),(size_t) 2,"body len is right");
        }

        output.close();
        input.close();
    }
Example #3
0
    void testPair() {
        report(0,"checking paired send/receive");
        PortReaderBuffer<PortablePair<Bottle,Bottle> > buf;

        Port input, output;
        input.open("/in");
        output.open("/out");

        buf.setStrict();
        buf.attach(input);

        output.addOutput(Contact::byName("/in").addCarrier("tcp"));
        //Time::delay(0.2);


        PortablePair<Bottle,Bottle> bot1;
        bot1.head.fromString("1 2 3");
        bot1.body.fromString("4 5 6 7");

        report(0,"writing...");
        output.write(bot1);
        bool ok = output.write(bot1);
        checkTrue(ok,"output proceeding");
        report(0,"reading...");
        PortablePair<Bottle,Bottle> *result = buf.read();

        checkTrue(result!=NULL,"got something check");
        checkEqual(bot1.head.size(),result->head.size(),"head size check");
        checkEqual(bot1.body.size(),result->body.size(),"body size check");

        output.close();
        input.close();
    }
Example #4
0
    void testInt() {
        report(0,"checking binary read/write of native int");
        BinPortable<int> i;
        i.content() = 5;

        PortReaderBuffer<BinPortable<int> > buf;
        Port input, output;
        bool ok1 = input.open("/in");
        bool ok2 = output.open("/out");
        checkTrue(ok1&&ok2,"ports opened ok");
        if (!(ok1&&ok2)) {
            return;
        }
        //input.setReader(buf);
        buf.attach(input);
        output.addOutput(Contact("/in", "tcp"));
        report(0,"writing...");
        output.write(i);
        report(0,"reading...");
        BinPortable<int> *result = buf.read();
        checkTrue(result!=NULL,"got something check");
        if (result!=NULL) {
            checkEqual(result->content(),5,"value preserved");
        }
        output.close();
        input.close();
    }
Example #5
0
    void testTransmit() {
        report(0,"testing image transmission...");

        ImageOf<PixelRgb> img1;
        img1.resize(128,64);
        for (int x=0; x<img1.width(); x++) {
            for (int y=0; y<img1.height(); y++) {
                PixelRgb& pixel = img1.pixel(x,y);
                pixel.r = x;
                pixel.g = y;
                pixel.b = 42;
            }
        }

        PortReaderBuffer< ImageOf<PixelRgb> > buf;

        Port input, output;

        buf.setStrict();
        buf.attach(input);

        input.open("/in");
        output.open("/out");

        output.addOutput(Contact("/in", "tcp"));
        Time::delay(0.2);

        report(0,"writing...");
        output.write(img1);
        output.write(img1);
        output.write(img1);
        report(0,"reading...");
        ImageOf<PixelRgb> *result = buf.read();

        checkTrue(result!=NULL,"got something check");
        if (result!=NULL) {
            checkEqual(img1.width(),result->width(),"width check");
            checkEqual(img1.height(),result->height(),"height check");
            if (img1.width()==result->width() &&
                img1.height()==result->height()) {
                int mismatch = 0;
                for (int x=0; x<img1.width(); x++) {
                    for (int y=0; y<img1.height(); y++) {
                        PixelRgb& pix0 = img1.pixel(x,y);
                        PixelRgb& pix1 = result->pixel(x,y);
                        if (pix0.r!=pix1.r ||
                            pix0.g!=pix1.g ||
                            pix0.b!=pix1.b) {
                            mismatch++;
                        }
                    }
                }
                checkTrue(mismatch==0,"pixel match check");
            }
        }

        output.close();
        input.close();
    }
Example #6
0
    void testReadBuffer() {
        report(0,"checking read buffering");
        Bottle bot1;
        PortReaderBuffer<Bottle> buf;
        buf.setStrict(true);

        bot1.fromString("1 2 3");
        for (int i=0; i<10000; i++) {
            bot1.addInt(i);
        }

        Port input, output;
        input.open("/in");
        output.open("/out");

        buf.setStrict();
        buf.attach(input);

        output.addOutput(Contact::byName("/in").addCarrier("udp"));
        //Time::delay(0.2);

        report(0,"writing...");
        output.write(bot1);
        output.write(bot1);
        output.write(bot1);
        report(0,"reading...");
        Bottle *result = buf.read();

        for (int j=0; j<3; j++) {
            if (j!=0) {
                result = buf.read();
            }
            checkTrue(result!=NULL,"got something check");
            if (result!=NULL) {
                checkEqual(bot1.size(),result->size(),"size check");
                YARP_INFO(Logger::get(),String("size is in fact ") + 
                          NetType::toString(result->size()));
            }
        }

        output.close();
        input.close();
    }
Example #7
0
    void testHeavy() {
        report(0,"checking heavy udp");

        Bottle bot1;
        PortReaderBuffer<Bottle> buf;

        bot1.fromString("1 2 3");
        for (int i=0; i<100000; i++) {
            bot1.addInt(i);
        }

        Port input, output;
        input.open("/in");
        output.open("/out");

        buf.setStrict();
        buf.attach(input);

        output.addOutput(Contact::byName("/in").addCarrier("udp"));
        //Time::delay(0.2);


        for (int j=0; j<3; j++) {
            report(0,"writing/reading three times...");
            output.write(bot1);
        }

        report(0,"checking for whatever got through...");
        int ct = 0;
        while (buf.check()) {
            ct++;
            Bottle *result = buf.read();
            checkTrue(result!=NULL,"got something check");
            if (result!=NULL) {
                checkEqual(bot1.size(),result->size(),"size check");
                YARP_INFO(Logger::get(),String("size is in fact ") + 
                          NetType::toString(result->size()));
            }
        }
        if (ct==0) {
            report(0,"NOTHING got through - possible but sad");
        }

        output.close();
        input.close();
    }
Example #8
0
    void checkTransmit() {
        report(0,"checking sound transmission...");

        Sound snd1;
        snd1.resize(128);
        snd1.setFrequency(50);
        for (int i=0; i<snd1.getSamples(); i++) {
            snd1.set(i-snd1.getSamples()/2,i);
        }

        PortReaderBuffer<Sound> buf;
        Port input, output;
        input.open("/in");
        output.open("/out");
        buf.setStrict();
        buf.attach(input);
        Network::connect("/out","/in");

        report(0,"writing...");
        output.write(snd1);
        report(0,"reading...");
        Sound *result = buf.read();

        checkTrue(result!=NULL,"got something check");
        if (result!=NULL) {
            checkEqual(snd1.getSamples(),result->getSamples(),
                       "sample ct check");
            checkEqual(snd1.getFrequency(),result->getFrequency(),
                       "freq check");

            bool ok = true;
            for (int i=0; i<result->getSamples(); i++) {
                ok = ok && (result->get(i) == snd1.get(i));
            }
            checkTrue(ok,"sample values match");

        }

        output.close();
        input.close();
    }