Merge test folder of test branch
[iotivity.git] / test / src / tc / ns / gtest / cpp / src / helper / NSCppUtility.cpp
1 /******************************************************************
2  *
3  * Copyright 2017 Samsung Electronics 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 "NSCppUtility.h"
23
24 string NSCppUtility::getSyncType(OIC::Service::NSSyncInfo::NSSyncType type)
25 {
26     switch (type) {
27         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
28             return "UNREAD";
29
30         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ:
31             return "READ";
32         case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED:
33             return "DELETED";
34
35         default:
36             return "UNKNOWN";
37     }
38 }
39
40 void NSCppUtility::printSyncInfo(OIC::Service::NSSyncInfo info)
41 {
42     try {
43         IOTIVITYTEST_LOG(INFO, "SyncInfo --> ProviderID: %s, MessageID: %d, State: %s",
44                 info.getProviderId().c_str(), info.getMessageId(), getSyncType(info.getState()).c_str());
45     } catch (exception &e) {
46         IOTIVITYTEST_LOG(WARNING, "Can't print syncInfo. Exception: %s", e.what());
47     }
48 }
49
50 void NSCppUtility::printMessage(OIC::Service::NSMessage message)
51 {
52     string log = "\n\tMessageID: " + to_string(message.getMessageId());
53     log += "\n\tTitle = " + message.getTitle();
54     log += "\n\tBody = " + message.getContentText();
55     log += "\n\tTopic = " + message.getTopic();
56     log += "\n\tProviderID = " + message.getProviderId();
57     IOTIVITYTEST_LOG(INFO, "The Detailed Message is: %s", log.c_str());
58 }
59
60 OIC::Service::NSTopic NSCppUtility::getDesiredTopic(shared_ptr<OIC::Service::NSTopicsList> topicList, string topicID)
61 {
62     OIC::Service::NSTopic desiredTopic;
63     for (OIC::Service::NSTopic topic : topicList->getTopicsList() )
64     {
65         if (topic.getTopicName().compare(topicID) == 0)
66         {
67             desiredTopic = topic;
68             break;
69         }
70     }
71     return desiredTopic;
72 }
73
74 string NSCppUtility::getResultString(OIC::Service::NSResult result)
75 {
76     switch (result)
77     {
78         case OIC::Service::NSResult::OK:
79             return "OK";
80
81         case OIC::Service::NSResult::ERROR:
82             return "ERROR";
83
84         case OIC::Service::NSResult::SUCCESS:
85             return "SUCCESS";
86
87         case OIC::Service::NSResult::FAIL:
88             return "FAIL";
89
90         default:
91             return "UNKNOWN";
92     }
93 }