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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include <OCPlatform.h>
24 #include <gtest/gtest.h>
26 namespace OCResourceTest
31 void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
32 const int& eCode, const int& sequenceNumber)
36 void onGetPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
40 void foundResource(std::shared_ptr<OCResource> resource)
46 OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
48 OCConnectivityType connectivityType = OC_WIFI;
49 std::vector<std::string> types = {"intel.rpost"};
50 std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
52 return OCPlatform::constructResourceObject(host, uri,
53 connectivityType, false, types, ifaces);
56 //ConstructResourceTest
57 TEST(ConstructResourceTest, ConstructResourceObject)
59 EXPECT_ANY_THROW(ConstructResourceObject(std::string(""), std::string("")));
62 TEST(ResourceGetTest, ResourceGetForValidUri)
64 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
68 EXPECT_EQ(OC_STACK_OK, resource->get(OC::QueryParamsMap(), &onGetPut));
72 TEST(ResourceGetTest, ResourceGetForBadUri)
74 OCResource::Ptr resource = ConstructResourceObject("", "coap://192.168.1.2:5000");
78 EXPECT_THROW(resource->get(OC::QueryParamsMap(), &onGetPut), OC::OCException);
82 TEST(ResourcePutTest, ResourcePutForValid)
84 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
89 EXPECT_EQ(OC_STACK_OK, resource->put(rep, test, &onGetPut));
93 TEST(ResourcePostTest, ResourcePostValidConfiguration)
96 OCPlatform::Configure(cfg);
98 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
101 OCRepresentation rep;
103 EXPECT_EQ(OC_STACK_OK, resource->post(rep, test, &onGetPut));
107 TEST(ResourceObserveTest, ResourceObserveValidUri)
109 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
113 OCRepresentation rep;
114 EXPECT_EQ(OC_STACK_OK,resource->observe(ObserveType::ObserveAll, test, &onObserve));