summaryrefslogtreecommitdiff
path: root/test/components/json_handler/src/formatter_test_helper.cc
blob: cc2b55b83a73511a5e0bd97bf7d57f311683920f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2013, Ford Motor Company
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with the
// distribution.
//
// Neither the name of the Ford Motor Company nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 'A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include "json_handler/formatter_test_helper.h"
#include "formatters/CSmartFactory.hpp"

using namespace test::components::json_handler::formatters;
using namespace NsSmartDeviceLink::NsSmartObjects;
using namespace NsSmartDeviceLink::NsJSONHandler::strings;

void CFormatterTestHelper::fillTestObject(SmartObject& obj)
{
    obj[S_PARAMS][S_MESSAGE_TYPE] = "request";
    obj[S_PARAMS][S_FUNCTION_ID] = "some function";
    obj[S_PARAMS][S_CORRELATION_ID] = 12;
    obj[S_PARAMS][S_PROTOCOL_TYPE] = 0;
    obj[S_MSG_PARAMS]["appId"] = "APP ID";
    obj[S_MSG_PARAMS]["appName"] = "APP NAME";
    obj[S_MSG_PARAMS]["appType"][0] = "SYSTEM";
    obj[S_MSG_PARAMS]["appType"][1] = "COMMUNICATION";
    obj[S_MSG_PARAMS]["hmiDisplayLanguageDesired"] = "RU-RU";
    obj[S_MSG_PARAMS]["isMediaApplication"] = true;
    obj[S_MSG_PARAMS]["languageDesired"] = "EN-US";
    obj[S_MSG_PARAMS]["ngnMediaScreenAppName"] = "SCREEN NAME";
    obj[S_MSG_PARAMS]["syncMsgVersion"]["majorVersion"] = 2;
    obj[S_MSG_PARAMS]["syncMsgVersion"]["minorVersion"] = 10;
    obj[S_MSG_PARAMS]["ttsName"][0]["text"] = "ABC";
    obj[S_MSG_PARAMS]["ttsName"][0]["type"] = "TEXT";
    obj[S_MSG_PARAMS]["vrSynonyms"][0] = "Synonym1";
    obj[S_MSG_PARAMS]["vrSynonyms"][1] = "Synonym2";
    // obj[S_MSG_PARAMS]["null"] = NsSmartDeviceLink::NsSmartObjects::SmartObject();
    obj[S_MSG_PARAMS]["double"] = -0.1234;
}


void CFormatterTestHelper::compareObjects(
    const NsSmartDeviceLink::NsSmartObjects::SmartObject& first,
    const NsSmartDeviceLink::NsSmartObjects::SmartObject& second) {
  if (SmartType_Array == first.getType()) {
    ASSERT_EQ(SmartType_Array, second.getType());

    for (size_t i = 0; i < first.length(); i++) {
      compareObjects(first.getElement(i), second.getElement(i));
    }
  } else if (SmartType_Map == first.getType()) {
    ASSERT_EQ(SmartType_Map, second.getType());

    std::set<std::string> keys = first.enumerate();

    for (std::set<std::string>::const_iterator key = keys.begin();
        key != keys.end(); key++) {
      compareObjects(first.getElement(*key), second.getElement(*key));
    }
  } else if (SmartType_Boolean == first.getType()) {
    ASSERT_EQ(first.asBool(), second.asBool());
  } else if (SmartType_Integer == first.getType()) {
    ASSERT_EQ(first.asInt(), second.asInt());
  } else if (SmartType_Double == first.getType()) {
    ASSERT_EQ(first.asDouble(), second.asDouble());
  } else if (SmartType_String == first.getType()) {
    ASSERT_EQ(first.asString(), second.asString());
  } else if (SmartType_Null == first.getType()) {
    ASSERT_EQ(SmartType_Null, second.getType());
  } else {
    FAIL() << "Unknown SmartObject type: " << first.getType();
  }
}