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,
39 std::shared_ptr<OCResourceResponse> response)
44 // Condition variables used for register and find
46 std::condition_variable cv_rf;
47 std::shared_ptr <OCResource> res_rf;
49 void foundResource_rf(std::shared_ptr<OCResource> resource)
58 // Resource : Register and find test
60 // Create PlatformConfig object
62 OC::ServiceType::InProc,
64 "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
65 0, // Uses randomly available port
66 OC::QualityOfService::LowQos
68 OCPlatform platform(cfg);
70 std::string resourceURI = "/a/res";
71 std::string resourceTypeName = "core.res";
72 std::string resourceInterface = DEFAULT_INTERFACE;
74 uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
76 OCResourceHandle resourceHandle;
78 // This will internally create and register the resource.
79 if(OC_STACK_OK == platform.registerResource(
80 resourceHandle, resourceURI, resourceTypeName,
81 resourceInterface, entityHandler_rf, resourceProperty))
83 platform.findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
86 std::unique_lock<std::mutex> lk(mutex_rf);
92 EXPECT_EQ(res_rf->uri(), "/a/res");
93 vector<std::string> rts = res_rf->getResourceTypes();
94 EXPECT_EQ(rts.size(), (unsigned) 1);
95 EXPECT_EQ(rts[0], "core.res");
96 vector<std::string> ifs = res_rf->getResourceInterfaces();
97 EXPECT_EQ(ifs.size(), (unsigned) 1);
98 EXPECT_EQ(ifs[0], DEFAULT_INTERFACE);