1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include <condition_variable>
27 #include <OCPlatform.h>
30 #include <gtest/gtest.h>
32 namespace PH = std::placeholders;
37 // Entity handler used for register and find test
38 OCEntityHandlerResult entityHandler_rf(std::shared_ptr<OCResourceRequest> request)
43 // Condition variables used for register and find
45 std::condition_variable cv_rf;
46 std::shared_ptr <OCResource> res_rf;
48 void foundResource_rf(std::shared_ptr<OCResource> resource)
57 // Resource : Register and find test
59 // Create PlatformConfig object
61 OC::ServiceType::InProc,
63 "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
64 0, // Uses randomly available port
65 OC::QualityOfService::LowQos
67 OCPlatform::Configure(cfg);
69 std::string resourceURI = "/a/res";
70 std::string resourceTypeName = "core.res";
71 std::string resourceInterface = DEFAULT_INTERFACE;
73 uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
75 OCResourceHandle resourceHandle;
77 // This will internally create and register the resource.
78 if(OC_STACK_OK == OCPlatform::registerResource(
79 resourceHandle, resourceURI, resourceTypeName,
80 resourceInterface, entityHandler_rf, resourceProperty))
82 OCPlatform::findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
85 std::unique_lock<std::mutex> lk(mutex_rf);
91 EXPECT_EQ(res_rf->uri(), "/a/res");
92 vector<std::string> rts = res_rf->getResourceTypes();
93 EXPECT_EQ(rts.size(), (unsigned) 1);
94 EXPECT_EQ(rts[0], "core.res");
95 vector<std::string> ifs = res_rf->getResourceInterfaces();
96 EXPECT_EQ(ifs.size(), (unsigned) 1);
97 EXPECT_EQ(ifs[0], DEFAULT_INTERFACE);