void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkInterface(); } UpnpLibrary::Initialise(aInitParams); UpnpLibrary::StartCombined(); //Debug::SetLevel(Debug::kDevice/*Debug::kXmlFetch | Debug::kHttp*/); Print("TestDviDeviceList - starting\n"); DvDevices* devices = new DvDevices; CpDevices* deviceList = new CpDevices; FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added); FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed); Print("Count devices implementing service1\n"); Brn domainName("a.b.c"); Brn serviceType("service1"); TUint ver = 1; CpDeviceListUpnpServiceType* list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); Blocker* blocker = new Blocker; blocker->Wait(aInitParams->MsearchTimeSecs()); std::vector<const char*> udns; udns.push_back((const char*)gNameDevice1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; deviceList->Clear(); Print("Count devices implementing service2\n"); serviceType.Set("service2"); list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); blocker->Wait(aInitParams->MsearchTimeSecs()); udns.push_back((const char*)gNameDevice1_1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; delete blocker; delete deviceList; delete devices; Print("TestDviDeviceList - completed\n"); UpnpLibrary::Close(); }
DvDevices::DvDevices() { RandomiseUdn(gNameDevice1); RandomiseUdn(gNameDevice1_1); RandomiseUdn(gNameDevice1_2); RandomiseUdn(gNameDevice2); DviDeviceStandard* device = new DviDeviceStandard(Brn(gNameDevice1)); iDevices[0] = device; device->SetAttribute("Upnp.Domain", "a.b.c"); device->SetAttribute("Upnp.Type", "test1"); device->SetAttribute("Upnp.Version", "1"); device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1.Ptr()); AddService(device, new DviService("a.b.c", "service1", 1)); device = new DviDeviceStandard(Brn(gNameDevice1_1)); iDevices[0]->AddDevice(device); device->SetAttribute("Upnp.Domain", "a.b.c"); device->SetAttribute("Upnp.Type", "test3"); device->SetAttribute("Upnp.Version", "1"); device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1_1.Ptr()); AddService(device, new DviService("a.b.c", "service2", 1)); AddService(device, new DviService("a.b.c", "service3", 1)); device->SetEnabled(); device = new DviDeviceStandard(Brn(gNameDevice1_2)); iDevices[0]->AddDevice(device); device->SetAttribute("Upnp.Domain", "a.b.c"); device->SetAttribute("Upnp.Type", "test4"); device->SetAttribute("Upnp.Version", "1"); device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice1_2.Ptr()); AddService(device, new DviService("a.b.c", "service4", 1)); device->SetEnabled(); iDevices[0]->SetEnabled(); device = new DviDeviceStandard(Brn(gNameDevice2)); iDevices[1] = device; device->SetAttribute("Upnp.Domain", "a.b.c"); device->SetAttribute("Upnp.Type", "test2"); device->SetAttribute("Upnp.Version", "1"); device->SetAttribute("Upnp.FriendlyName", (const TChar*)gNameDevice2.Ptr()); AddService(device, new DviService("a.b.c", "service1", 1)); AddService(device, new DviService("a.b.c", "service2", 1)); iDevices[1]->SetEnabled(); }
void TestDviDeviceList() { InitialisationParams& initParams = Stack::InitParams(); TUint oldMsearchTime = initParams.MsearchTimeSecs(); initParams.SetMsearchTime(1); Debug::SetLevel(Debug::kDevice | Debug::kDvDevice | Debug::kXmlFetch); Print("TestDviDeviceList - starting\n"); DvDevices* devices = new DvDevices; CpDevices* deviceList = new CpDevices; FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added); FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed); Print("Count devices implementing service1\n"); Brn domainName("a.b.c"); Brn serviceType("service1"); TUint ver = 1; CpDeviceListUpnpServiceType* list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); std::vector<const char*> udns; udns.push_back((const char*)gNameDevice1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; deviceList->Clear(); Print("Count devices implementing service2\n"); serviceType.Set("service2"); list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); udns.push_back((const char*)gNameDevice1_1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; delete deviceList; delete devices; Print("TestDviDeviceList - completed\n"); initParams.SetMsearchTime(oldMsearchTime); }
static void RandomiseUdn(std::string& aUdn) { Bwh udn; udn.Grow((TUint)aUdn.length() + 1 + Ascii::kMaxUintStringBytes + 1); Brn buf((const TByte*)aUdn.c_str(), (TUint)aUdn.length()); udn.Append(buf); udn.Append('-'); Bws<Ascii::kMaxUintStringBytes> addr; std::vector<NetworkAdapter*>* subnetList = gEnv->NetworkAdapterList().CreateSubnetList(); TUint max = (*subnetList)[0]->Address(); TUint seed = gDvStack->ServerUpnp().Port((*subnetList)[0]->Address()); SetRandomSeed(seed); gEnv->NetworkAdapterList().DestroySubnetList(subnetList); (void)Ascii::AppendDec(addr, Random(max)); udn.Append(addr); udn.PtrZ(); aUdn.assign((const char*)udn.Ptr(), udn.Bytes()); }