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 uri)
48 std::vector<std::string> types = {"intel.rpost"};
49 std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
50 return OCPlatform::constructResourceObject(std::string(""), uri,
51 false, types, ifaces);
54 //ConstructResourceTest
55 TEST(ConstructResourceTest, ConstructResourceObject)
57 EXPECT_ANY_THROW(ConstructResourceObject(std::string("")));
61 TEST(ResourceGetTest, ResourceGetForInvalidUri)
63 OCResource::Ptr resource = ConstructResourceObject("192.168.1.2:5000");
67 EXPECT_ANY_THROW(resource->get(test, &onGetPut));
71 TEST(ResourceGetTest, ResourceGetForValidUri)
73 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
77 EXPECT_EQ(OC_STACK_OK, resource->get(OC::QueryParamsMap(), &onGetPut));
82 TEST(ResourcePutTest, ResourcePutForInvalidUri)
84 OCResource::Ptr resource = ConstructResourceObject("192.168.1.2:5000");
89 EXPECT_ANY_THROW(resource->put(rep, test, &onGetPut));
93 TEST(ResourcePutTest, ResourcePutForValid)
95 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
100 EXPECT_EQ(OC_STACK_OK, resource->put(rep, test, &onGetPut));
105 TEST(ResourcePostTest, ResourcePostForInvalidUri)
107 OCResource::Ptr resource = ConstructResourceObject("192.168.1.2:5000");
110 OCRepresentation rep;
112 EXPECT_ANY_THROW(resource->post(rep, test, &onGetPut));
116 TEST(ResourcePostTest, ResourcePostValidConfiguration)
119 OCPlatform::Configure(cfg);
121 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
124 OCRepresentation rep;
126 EXPECT_EQ(OC_STACK_OK, resource->post(rep, test, &onGetPut));
130 //ResourceObserveTest
131 TEST(ResourceObserveTest, ResourceObserveInValidUri)
133 OCResource::Ptr resource = ConstructResourceObject("192.168.1.2:5000");
137 EXPECT_ANY_THROW(resource->observe(ObserveType::ObserveAll, test, &onObserve));
141 TEST(ResourceObserveTest, ResourceObserveValidUri)
143 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
147 OCRepresentation rep;
148 EXPECT_EQ(OC_STACK_OK,resource->observe(ObserveType::ObserveAll, test, &onObserve));