Merge branch 'simulator'
[platform/upstream/iotivity.git] / resource / unittests / ConstructResourceTest.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 #include <OCPlatform.h>
22 #include <OCApi.h>
23
24 //Uncomment the below line for testing with Mocks
25 //TODO enable these tests (unconditionally) after CA code clean up
26 //#define WITH_MOCKS
27 #ifdef WITH_MOCKS
28
29 #include "hippomocks.h"
30 #include "Framework.h"
31
32 #define GTEST_DONT_DEFINE_TEST 1
33
34 #include <gtest/gtest.h>
35
36 namespace ConstructResourceTest
37 {
38     using namespace OC;
39     std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
40     //using mocks framework
41     GTEST_TEST(ConstructResourceObjectTest, ConstructResourceObjectValidReturnValue)
42     {
43         MockRepository mocks;
44         OCResource::Ptr rightdoor = std::shared_ptr<OCResource>();
45         OCConnectivityType connectivityType = OC_WIFI;
46         mocks.ExpectCallFunc(OCPlatform::constructResourceObject).Return(rightdoor);
47         std::vector<std::string> types = {"core.leftdoor"};
48         OCResource::Ptr leftdoor = OCPlatform::constructResourceObject("192.168.1.2:5000",
49                 "a/leftdoor", connectivityType, false, types, ifaces);
50         EXPECT_EQ(leftdoor, rightdoor);
51
52     }
53
54     GTEST_TEST(ConstructResourceObjectTest, ConstructResourceObjectInValidReturnValue)
55     {
56         MockRepository mocks;
57         OCResource::Ptr rightdoor = std::shared_ptr<OCResource>();
58         OCConnectivityType connectivityType = OC_WIFI;
59         mocks.ExpectCallFunc(OCPlatform::constructResourceObject).Return(NULL);
60         std::vector<std::string> types = {"core.rightdoor"};
61         OCResource::Ptr leftdoor = OCPlatform::constructResourceObject("192.168.1.2:5000",
62                 "a/rightdoor", connectivityType, false, types, ifaces);
63         bool value = (leftdoor == NULL);
64         EXPECT_EQ(true, value);
65     }
66 }
67 #endif
68