コード例 #1
0
ファイル: TestDviDiscovery.cpp プロジェクト: Jacik/ohNet
void SuiteAlive::Test()
{
    Environment& env = iDvStack.Env();
    Blocker* blocker = new Blocker(env);
    CpListenerBasic* listener = new CpListenerBasic;
    NetworkAdapter* nif = env.NetworkAdapterList().CurrentAdapter(kAdapterCookie);
    SsdpListenerMulticast* listenerMulticast = new SsdpListenerMulticast(env, nif->Address());
    nif->RemoveRef(kAdapterCookie);
    TInt listenerId = listenerMulticast->AddNotifyHandler(listener);
    listenerMulticast->Start();
    DviDevice* device = new DviDeviceStandard(iDvStack, gNameDevice1);
    device->SetAttribute("Upnp.Domain", "a.b.c");
    device->SetAttribute("Upnp.Type", "type1");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "a.b.c", "service1", 1));
    AddService(device, new DviService(iDvStack, "a.b.c", "service2", 1));
    device->SetEnabled();
    blocker->Wait(1);
    /* we expect 5 messages but linux sometimes reports multicast messages from
      all subnets to listeners on any single subnet so just check that we've
      received a multiple of 5 messages */

    TEST(listener->TotalAlives() > 0);
    TEST(listener->TotalAlives() == listener->TotalByeByes());
    TEST(listener->TotalAlives() % 5 == 0);

    TUint byebyes = listener->TotalByeByes();
    Functor disabled = MakeFunctor(*this, &SuiteAlive::Disabled);
    device->SetDisabled(disabled);
    iSem.Wait();
    blocker->Wait(1); /* semaphore being signalled implies that the device has been
                         disabled.  We may require some extra time to receive the
                         multicast byebye confirming this */
    TEST(listener->TotalByeByes() > byebyes);
    TEST(listener->TotalByeByes() % 5 == 0);

    TUint alives = listener->TotalAlives();
    byebyes = listener->TotalByeByes();
    device->SetEnabled();
    blocker->Wait(1);
    TEST(listener->TotalAlives() > alives);
    TEST(listener->TotalAlives() - alives == listener->TotalByeByes() - byebyes);
    TEST(listener->TotalAlives() % 5 == 0);

    // Control point doesn't process ssdp:update notifications
    // check that updates are basically working by counting the extra alive messages instead
    alives = listener->TotalAlives();
    device->SetAttribute("Upnp.TestUpdate", "1");
    blocker->Wait(1);
    TEST(listener->TotalAlives() > alives);
    TEST(listener->TotalAlives() % 5 == 0);

    device->Destroy();
    listenerMulticast->RemoveNotifyHandler(listenerId);
    delete listenerMulticast;
    delete listener;
    delete blocker;
}
コード例 #2
0
ファイル: TestDviDiscovery.cpp プロジェクト: Jacik/ohNet
void SuiteMsearch::Test()
{
    DviDevice* device = new DviDeviceStandard(iDvStack, gNameDevice1);
    iDevices[0] = device;
    device->SetAttribute("Upnp.Domain", "upnp.org");
    device->SetAttribute("Upnp.Type", "test1");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "upnp.org", "service1", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service2", 3));
    AddService(device, new DviService(iDvStack, "upnp.org", "service3", 1));
    DviService* service = new DviService(iDvStack, "upnp.org", "service1", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();
    device->SetEnabled();
    service = new DviService(iDvStack, "upnp.org", "service4", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();

    device = new DviDeviceStandard(iDvStack, gNameDevice2);
    iDevices[1] = device;
    device->SetAttribute("Upnp.Domain", "openhome.org");
    device->SetAttribute("Upnp.Type", "test2");
    device->SetAttribute("Upnp.Version", "2");
    AddService(device, new DviService(iDvStack, "openhome.org", "service4", 2));
    AddService(device, new DviService(iDvStack, "openhome.org", "service5", 1));

    device = new DviDeviceStandard(iDvStack, gNameDevice2Embedded1);
    iDevices[1]->AddDevice(device);
    device->SetAttribute("Upnp.Domain", "openhome.org");
    device->SetAttribute("Upnp.Type", "test3");
    device->SetAttribute("Upnp.Version", "1");
    AddService(device, new DviService(iDvStack, "upnp.org", "service1", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service6", 1));
    AddService(device, new DviService(iDvStack, "openhome.org", "service2", 3));
    service = new DviService(iDvStack, "openhome.org", "service5", 1);
    TEST_THROWS(device->AddService(service), AssertionFailed);
    service->RemoveRef();
    iDevices[1]->SetEnabled();
    device->SetEnabled();
    device = new DviDeviceStandard(iDvStack, kNameDummy);
    TEST_THROWS(iDevices[1]->AddDevice(device), AssertionFailed);
    device->Destroy();
    //Wait(); // allow time for initial annoucements to be delivered

    TestMsearchAll();
    TestMsearchRoot();
    TestMsearchUuid();
    TestMsearchDeviceType();
    TestMsearchServiceType();
}