test_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef LEX_COMMON_TEST__TEST_UTILS_H_
17 #define LEX_COMMON_TEST__TEST_UTILS_H_
18 
19 #include <gmock/gmock.h>
20 
21 #include <aws/core/utils/Outcome.h>
22 #include <aws/lex/LexRuntimeServiceClient.h>
23 #include <aws/core/utils/memory/AWSMemory.h>
24 #include <aws/lex/model/PostContentRequest.h>
25 #include <aws/core/utils/memory/stl/AWSStreamFwd.h>
26 
27 #include <lex_common/lex_common.h>
28 
29 #include <string>
30 #include <memory>
31 #include <vector>
32 
33 namespace Aws
34 {
35 namespace Lex
36 {
37 class TestData
38 {
39 public:
40  std::string content_type = "content_type";
41  LexRuntimeService::Model::DialogState dialog_state =
42  LexRuntimeService::Model::DialogState::ElicitSlot;
43  std::string intent_name = "intent_name";
44  std::string message = "message";
45  std::string slot_to_elicit = "slot_to_elicit";
46  LexRuntimeService::Model::MessageFormatType message_format =
47  LexRuntimeService::Model::MessageFormatType::PlainText;
48  std::string session_attributes = "session_attributes";
49 
51  Aws::LexRuntimeService::Model::PostContentResult & example_result)
52  {
53  example_result.SetContentType(content_type.c_str());
54  example_result.SetDialogState(dialog_state);
55  example_result.SetIntentName(intent_name.c_str());
56  example_result.SetMessage(message.c_str());
57  example_result.SetSlots("");
58  example_result.SetSlotToElicit(slot_to_elicit.c_str());
59  example_result.SetMessageFormat(message_format);
60  example_result.SetSessionAttributes(session_attributes.c_str());
61  auto io_stream = new Aws::StringStream();
62  example_result.ReplaceBody(io_stream);
63  }
64 
65  inline void ExpectEq(const LexResponse & response)
66  {
67  EXPECT_EQ(message, response.text_response);
68  EXPECT_EQ(intent_name, response.intent_name);
69  using Aws::LexRuntimeService::Model::DialogStateMapper::GetNameForDialogState;
70  std::string dialog_state_name =
71  GetNameForDialogState(dialog_state).c_str();
72  EXPECT_EQ(dialog_state_name, response.dialog_state);
73  using Aws::LexRuntimeService::Model::MessageFormatTypeMapper::GetNameForMessageFormatType;
74  std::string message_format_name =
75  GetNameForMessageFormatType(message_format).c_str();
76  EXPECT_EQ(message_format_name, response.message_format_type);
77  EXPECT_EQ(session_attributes, response.session_attributes);
78  EXPECT_TRUE(response.slots.empty());
79  }
80 };
81 } // namespace Lex
82 
83 namespace LexRuntimeService
84 {
85 namespace Model
86 {
87 
88 using Aws::LexRuntimeService::Model::PostContentRequest;
89 
90 inline std::vector<uint8_t> GetVectorFromStream(std::shared_ptr<Aws::IOStream> io_stream)
91 {
92  std::streampos audio_size = io_stream->seekg(0, std::ios_base::end).tellg();
93  std::vector<uint8_t> vec(audio_size);
94  io_stream->seekg(0, std::ios_base::beg);
95  io_stream->readsome(reinterpret_cast<char *>(&vec[0]), audio_size);
96  io_stream->seekg(0, std::ios_base::beg);
97  return vec;
98 }
99 
100 inline bool operator==(const PostContentRequest & left, const PostContentRequest & right)
101 {
102  std::cout << "Checking equals" << std::endl;
103  bool is_equal = true;
104  std::string left_user_id = left.GetUserId().c_str();
105  std::string right_user_id = right.GetUserId().c_str();
106  is_equal &= static_cast<bool>(left_user_id == right_user_id);
107  is_equal &= static_cast<bool>(left.GetBotAlias() == right.GetBotAlias());
108  is_equal &= static_cast<bool>(left.GetBotName() == right.GetBotName());
109  is_equal &= static_cast<bool>(left.GetContentType() == right.GetContentType());
110  is_equal &= static_cast<bool>(left.GetSessionAttributes() == right.GetSessionAttributes());
111  is_equal &= static_cast<bool>(left.GetAccept() == right.GetAccept());
112  EXPECT_THAT(GetVectorFromStream(left.GetBody()),
113  testing::ElementsAreArray(GetVectorFromStream(right.GetBody())));
114  return is_equal;
115 }
116 
117 } // namespace Model
118 } // namespace LexRuntimeService
119 } // namespace Aws
120 
121 #endif // LEX_COMMON_TEST__TEST_UTILS_H_
std::string slot_to_elicit
Definition: test_utils.h:45
std::string session_attributes
Definition: lex_common.h:80
bool operator==(const PostContentRequest &left, const PostContentRequest &right)
Definition: test_utils.h:100
LexRuntimeService::Model::DialogState dialog_state
Definition: test_utils.h:41
std::vector< uint8_t > GetVectorFromStream(std::shared_ptr< Aws::IOStream > io_stream)
Definition: test_utils.h:90
std::string message_format_type
Definition: lex_common.h:75
std::string intent_name
Definition: test_utils.h:43
std::string session_attributes
Definition: test_utils.h:48
std::string content_type
Definition: test_utils.h:40
std::unordered_map< std::string, std::string > slots
Definition: lex_common.h:79
std::string text_response
Definition: lex_common.h:74
void ConfigureExampleResult(Aws::LexRuntimeService::Model::PostContentResult &example_result)
Definition: test_utils.h:50
std::string message
Definition: test_utils.h:44
LexRuntimeService::Model::MessageFormatType message_format
Definition: test_utils.h:46
std::string intent_name
Definition: lex_common.h:77
std::string dialog_state
Definition: lex_common.h:78
void ExpectEq(const LexResponse &response)
Definition: test_utils.h:65


lex_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:43:24