Fixed C++ unit tests for connectivity abstraction integration
[platform/upstream/iotivity.git] / resource / unittests / OCResourceTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21
22 #include <OCPlatform.h>
23 #include <OCApi.h>
24 #include <gtest/gtest.h>
25
26 namespace OCResourceTest
27 {
28     using namespace OC;
29     // Callbacks
30
31     void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
32                         const int& eCode, const int& sequenceNumber)
33     {
34     }
35
36     void onGetPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
37     {
38     }
39
40     void foundResource(std::shared_ptr<OCResource> resource)
41     {
42
43     }
44
45     //Helper method
46     OCResource::Ptr ConstructResourceObject(std::string uri)
47     {
48         OCConnectivityType connectivityType = OC_WIFI;
49         std::vector<std::string> types = {"intel.rpost"};
50         std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
51
52         return OCPlatform::constructResourceObject(std::string(""), uri,
53                 connectivityType, false, types, ifaces);
54     }
55
56     //ConstructResourceTest
57     TEST(ConstructResourceTest, ConstructResourceObject)
58     {
59         EXPECT_ANY_THROW(ConstructResourceObject(std::string("")));
60     }
61
62     TEST(ResourceGetTest, ResourceGetForValidUri)
63     {
64         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
65         if(resource)
66         {
67             QueryParamsMap test;
68             EXPECT_EQ(OC_STACK_OK, resource->get(OC::QueryParamsMap(), &onGetPut));
69         }
70     }
71
72     TEST(ResourcePutTest, ResourcePutForValid)
73     {
74         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
75         if(resource)
76         {
77             QueryParamsMap test;
78             OCRepresentation rep;
79             EXPECT_EQ(OC_STACK_OK, resource->put(rep, test, &onGetPut));
80         }
81     }
82
83
84     TEST(ResourcePostTest, ResourcePostValidConfiguration)
85     {
86         PlatformConfig cfg;
87         OCPlatform::Configure(cfg);
88
89         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
90         if(resource)
91         {
92             OCRepresentation rep;
93             QueryParamsMap test;
94             EXPECT_EQ(OC_STACK_OK, resource->post(rep, test, &onGetPut));
95         }
96     }
97
98     TEST(ResourceObserveTest, ResourceObserveValidUri)
99     {
100         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000");
101         if(resource)
102         {
103             QueryParamsMap test;
104             OCRepresentation rep;
105             EXPECT_EQ(OC_STACK_OK,resource->observe(ObserveType::ObserveAll, test, &onObserve));
106         }
107     }
108
109 }