1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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>
28 namespace OCMQResourceTest
33 void onSubscribe(const HeaderOptions, const OCRepresentation&, const int&, const int&)
37 void onReqPub(const HeaderOptions&, const OCRepresentation&, const int)
43 void onPublish(const HeaderOptions&, const OCRepresentation&, const int)
48 void foundResource(const int, const std::string, std::shared_ptr<OCResource>)
52 void createdTopic(const int, const std::string, std::shared_ptr<OCResource>)
57 OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
59 OCConnectivityType connectivityType = CT_DEFAULT;
60 std::vector<std::string> types = {"oic.ps"};
61 std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
63 auto ret = OCPlatform::constructResourceObject(host, uri,
64 connectivityType, false, types, ifaces);
68 ADD_FAILURE() << "ConstructResourceObject result was null";
76 TEST(MessageQueueTest, DiscoveryMQTopicsValid)
78 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
79 EXPECT_TRUE(resource != NULL);
80 QueryParamsMap query = {};
81 EXPECT_EQ(OC_STACK_OK, resource->discoveryMQTopics(query, &foundResource,
82 QualityOfService::LowQos));
85 TEST(MessageQueueTest, CreateMQTopicValid)
87 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
88 EXPECT_TRUE(resource != NULL);
90 QueryParamsMap query = {};
91 EXPECT_EQ(OC_STACK_OK, resource->createMQTopic(rep, "/lightTopic", query, &createdTopic,
92 QualityOfService::LowQos));
96 TEST(MessageQueueTest, PublishMQTopicValid)
98 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
99 EXPECT_TRUE(resource != NULL);
100 OCRepresentation rep;
101 QueryParamsMap query = {};
102 EXPECT_EQ(OC_STACK_OK, resource->publishMQTopic(rep, query, &onPublish,
103 QualityOfService::LowQos));
108 TEST(MessageQueueTest, SubscribeMQTopicValid)
110 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
111 EXPECT_TRUE(resource != NULL);
112 QueryParamsMap query = {};
113 EXPECT_EQ(OC_STACK_OK, resource->subscribeMQTopic(ObserveType::Observe, query,
114 &onSubscribe, QualityOfService::LowQos));
117 TEST(MessageQueueTest, RequestMQPublishValid)
119 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
120 EXPECT_TRUE(resource != NULL);
121 QueryParamsMap query = {};
122 EXPECT_EQ(OC_STACK_OK, resource->requestMQPublish(query, &onReqPub,
123 QualityOfService::LowQos));