RDK Documentation (Open Sourced RDK Components)
drmTestUtils.cpp
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 #include <iomanip>
5 #include <algorithm>
6 #include <iterator>
7 #include <sstream>
8 
9 #include "CppUTest/TestHarness.h"
10 
11 #include "drmTestUtils.h"
12 
13 TestUtilJsonWrapper::TestUtilJsonWrapper(const std::string& jsonStr)
14 {
15  mJsonObj = cJSON_Parse(jsonStr.c_str());
16 }
17 
18 TestUtilJsonWrapper::~TestUtilJsonWrapper()
19 {
20  if (mJsonObj) cJSON_Delete(mJsonObj);
21 }
22 
23 SimpleString StringFrom(const std::vector<std::string>& vec)
24 {
25  std::ostringstream oss;
26 
27  if (!vec.empty())
28  {
29  std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<std::string>(oss, ","));
30  oss << vec.back();
31  }
32 
33  return SimpleString(oss.str().c_str());
34 }
35 
36 SimpleString StringFrom(const std::vector<std::uint8_t>& v)
37 {
38  std::ostringstream oss;
39 
40  for (auto x : v)
41  {
42  oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned)x;
43  }
44 
45  return SimpleString(oss.str().c_str());
46 }