2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19 * @brief Definition of types, constants and functions common for both tests and plugins
28 namespace CynaraTestPlugins {
30 Cynara::PluginData wrapAgentData(const AgentDataVector &data) {
31 std::stringstream wrappedData;
32 wrappedData << AGENT_DATA_RECORD_SEPARATOR;
33 for (size_t i = 0; i < data.size(); ++i) {
34 wrappedData << AGENT_DATA_UNIT_SEPARATOR
36 << AGENT_DATA_UNIT_SEPARATOR;
38 wrappedData << AGENT_DATA_RECORD_SEPARATOR;
39 return wrappedData.str();
42 static bool unwrapAgentDataFromSeparator(const Cynara::PluginData &wrappedData,
43 const std::string &separator,
44 size_t &pos, std::string &unit) {
45 //check if wrapped data starts with separator
46 size_t separatorSize = separator.size();
47 if (wrappedData.compare(pos, separatorSize, separator) != 0)
50 //find ending separator
51 size_t unitStartIndex = pos + separatorSize;
52 size_t endingSeparatorIndex = wrappedData.find(separator, unitStartIndex);
53 if (endingSeparatorIndex == std::string::npos)
57 pos = endingSeparatorIndex + separatorSize;
58 size_t unitSize = endingSeparatorIndex - unitStartIndex;
59 unit.assign(wrappedData, unitStartIndex, unitSize);
63 bool unwrapAgentData(const Cynara::PluginData &wrappedData, AgentDataVector& data) {
66 if (!unwrapAgentDataFromSeparator(wrappedData, AGENT_DATA_RECORD_SEPARATOR, pos, record))
70 while (pos < record.size()) {
72 if (!unwrapAgentDataFromSeparator(record, AGENT_DATA_UNIT_SEPARATOR, pos, unit))
79 } // namespace CynaraTestPlugins