static void test_inheritance0(Pothos::ProxyEnvironment::Sptr env)
{
    Pothos::ManagedClass()
        .registerConstructor<MyBaseClass0>()
        .registerMethod(POTHOS_FCN_TUPLE(MyBaseClass0, negateInt))
        .commit("MyBaseClass0");

    //prove that base class can work
    auto myBase0 = env->findProxy("MyBaseClass0").callProxy("new");
    POTHOS_TEST_EQUAL(-42, myBase0.call<int>("negateInt", 42));

    Pothos::ManagedClass()
        .registerConstructor<MyDerivedClass0>()
        .registerBaseClass<MyDerivedClass0, MyBaseClass0>()
        .commit("MyDerivedClass0");

    //prove that derived class has the base methods
    auto myDerived0 = env->findProxy("MyDerivedClass0").callProxy("new");
    POTHOS_TEST_EQUAL(-42, myDerived0.call<int>("negateInt", 42));

    //runtime registration does not associate the module
    //therefore to be safe, we unregister these classes now
    Pothos::PluginRegistry::remove("/managed/MyBaseClass0");
    Pothos::PluginRegistry::remove("/managed/MyDerivedClass0");
}
void testComparatorTmpl(const double val, const std::string op_string)
{
    auto dtype = Pothos::DType(typeid(Type));
    std::cout << "Testing comparator with type " << dtype.toString() << ", value " << val << std::endl;

    auto feeder0 = Pothos::BlockRegistry::make("/blocks/feeder_source", dtype);
    auto feeder1 = Pothos::BlockRegistry::make("/blocks/feeder_source", dtype);
    auto comp = Pothos::BlockRegistry::make("/comms/comparator", dtype, op_string);
    auto collector = Pothos::BlockRegistry::make("/blocks/collector_sink", "char");

    //load the feeder
    auto buffIn0 = Pothos::BufferChunk(typeid(Type), NUM_POINTS);
    auto pIn0 = buffIn0.as<Type *>();
    auto buffIn1 = Pothos::BufferChunk(typeid(Type), NUM_POINTS);
    auto pIn1 = buffIn1.as<Type *>();

    for (size_t i = 0; i < buffIn0.elements(); i++)
    {
        pIn0[i] = Type(i);
        pIn1[i] = Type(val);
    }
    
    feeder0.callProxy("feedBuffer", buffIn0);
    feeder1.callProxy("feedBuffer", buffIn1);

    //run the topology
    {
        Pothos::Topology topology;
        topology.connect(feeder0, 0, comp, 0);
        topology.connect(feeder1, 0, comp, 1);
        topology.connect(comp, 0, collector, 0);
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive(0.01));
    }

    //check the collector
    auto buffOut = collector.call<Pothos::BufferChunk>("getBuffer");
    POTHOS_TEST_EQUAL(buffOut.length, NUM_POINTS*sizeof(char));
    auto pOut = buffOut.as<const char *>();
    for (size_t i = 0; i < NUM_POINTS; i++)
    {
      char expected;
      if (op_string == ">")
        expected = (pIn0[i] > pIn1[i]);
      else if (op_string == "<")
        expected = (pIn0[i] < pIn1[i]);
      else if (op_string == "<=")
        expected = (pIn0[i] <= pIn1[i]);
      else if (op_string == ">=")
        expected = (pIn0[i] >= pIn1[i]);
      else if (op_string == "==")
        expected = (pIn0[i] == pIn1[i]);
      else if (op_string == "!=")
        expected = (pIn0[i] != pIn1[i]);
      POTHOS_TEST_EQUAL(pOut[i], expected);
    }
}
Exemple #3
0
static void delayBlockTestCase(const int delayVal)
{
    auto feeder = Pothos::BlockRegistry::make("/blocks/feeder_source", "int");
    auto delay = Pothos::BlockRegistry::make("/blocks/delay");
    auto collector = Pothos::BlockRegistry::make("/blocks/collector_sink", "int");

    //setup
    std::cout << "delayBlockTestCase " << delayVal << std::endl;
    Pothos::BufferChunk buff0(typeid(int), 100);
    feeder.callVoid("feedBuffer", buff0);
    delay.callVoid("setDelay", delayVal);

    //run the topology
    std::cout << "run the topology\n";
    {
        Pothos::Topology topology;
        topology.connect(feeder, 0, delay, 0);
        topology.connect(delay, 0, collector, 0);
        topology.commit();
        POTHOS_TEST_TRUE(topology.waitInactive());
    }

    auto buff1 = collector.call<Pothos::BufferChunk>("getBuffer");
    POTHOS_TEST_EQUAL(buff1.elements(), size_t(100-delayVal));
}