Skip to content

Commit

Permalink
Adds sample integration tests for en_us and fr_fr
Browse files Browse the repository at this point in the history
Bug: 69861145
Change-Id: Ie3c06044d341481f169790430408d666847957ea
  • Loading branch information
Fleker committed Mar 9, 2018
1 parent 97cb921 commit 9ac5e9b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/audio_output_alsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ bool AudioOutputALSA::Start() {
snd_pcm_drain(pcm_handle);
snd_pcm_close(pcm_handle);
}));
std::cout << "AudioOutputALSA Start() succeeded" << std::endl;
return true;
}

Expand All @@ -118,7 +117,6 @@ void AudioOutputALSA::Stop() {
isRunning = false;
alsaThread->join();
alsaThread.reset(nullptr);
std::cout << "AudioOutputALSA Stop() succeeded" << std::endl;
}

void AudioOutputALSA::Send(std::shared_ptr<std::vector<unsigned char>> data) {
Expand Down
44 changes: 31 additions & 13 deletions src/run_assistant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,25 @@ static const std::string kLanguageCode = "en-US";
static const std::string kDeviceInstanceId = "default";
static const std::string kDeviceModelId = "default";

bool verbose = false;

// Creates a channel to be connected to Google.
std::shared_ptr<Channel> CreateChannel(const std::string& host) {
std::ifstream file("robots.pem");
std::stringstream buffer;
buffer << file.rdbuf();
std::string roots_pem = buffer.str();

std::cout << "assistant_sdk robots_pem: " << roots_pem << std::endl;
if (verbose) {
std::clog << "assistant_sdk robots_pem: " << roots_pem << std::endl;
}
::grpc::SslCredentialsOptions ssl_opts = {roots_pem, "", ""};
auto creds = ::grpc::SslCredentials(ssl_opts);
std::string server = host + ":443";
std::cout << "assistant_sdk CreateCustomChannel(" << server << ", creds, arg)"

if (verbose) {
std::clog << "assistant_sdk CreateCustomChannel(" << server << ", creds, arg)"
<< std::endl << std::endl;
}
::grpc::ChannelArguments channel_args;
return CreateCustomChannel(server, creds, channel_args);
}
Expand All @@ -101,13 +106,14 @@ bool GetCommandLineFlags(
{"credentials_type", required_argument, nullptr, 'c'},
{"api_endpoint", required_argument, nullptr, 'e'},
{"locale", required_argument, nullptr, 'l'},
{"verbose", no_argument, nullptr, 'v'},
{nullptr, 0, nullptr, 0}
};
*api_endpoint = ASSISTANT_ENDPOINT;
while (true) {
int option_index;
int option_char =
getopt_long(argc, argv, "i:t:f:c:e:l", long_options, &option_index);
getopt_long(argc, argv, "i:t:f:c:e:l:v", long_options, &option_index);
if (option_char == -1) {
break;
}
Expand Down Expand Up @@ -135,6 +141,9 @@ bool GetCommandLineFlags(
case 'l':
*locale = optarg;
break;
case 'v':
verbose = true;
break;
default:
PrintUsage();
return false;
Expand Down Expand Up @@ -219,8 +228,10 @@ int main(int argc, char** argv) {
std::shared_ptr<ClientReaderWriter<AssistRequest, AssistResponse>>
stream(std::move(assistant->Assist(&context)));
// Write config in first stream.
std::cout << "assistant_sdk wrote first request: "
<< request.ShortDebugString() << std::endl;
if (verbose) {
std::clog << "assistant_sdk wrote first request: "
<< request.ShortDebugString() << std::endl;
}
stream->Write(request);

if (!audio_input_source.empty()) {
Expand Down Expand Up @@ -259,8 +270,13 @@ int main(int argc, char** argv) {
#endif

// Read responses.
std::cout << "assistant_sdk waiting for response ... " << std::endl;
if (verbose) {
std::clog << "assistant_sdk waiting for response ... " << std::endl;
}
AssistResponse response;
if (verbose) {
std::clog << "assistant_sdk Got a response \n";
}
while (stream->Read(&response)) { // Returns false when no more to read.
if ((response.has_audio_out() ||
response.event_type() == AssistResponse_EventType_END_OF_UTTERANCE)
Expand All @@ -284,15 +300,17 @@ int main(int argc, char** argv) {
for (int i = 0; i < response.speech_results_size(); i++) {
google::assistant::embedded::v1alpha2::SpeechRecognitionResult result =
response.speech_results(i);
std::cout << "assistant_sdk request: \n"
<< result.transcript() << " ("
<< std::to_string(result.stability())
<< ")" << std::endl;
if (verbose) {
std::clog << "assistant_sdk request: \n"
<< result.transcript() << " ("
<< std::to_string(result.stability())
<< ")" << std::endl;
}
}
if (response.dialog_state_out().supplemental_display_text().size() > 0) {
// CUSTOMIZE: render spoken response on screen
std::cout << "assistant_sdk display text: \n"
<< response.dialog_state_out().supplemental_display_text()
std::clog << "assistant_sdk response:" << std::endl;
std::cout << response.dialog_state_out().supplemental_display_text()
<< std::endl;
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/integration_en_us.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tests that the command "how do you say hi in spanish"
# will return "Hola" to verify the Assistant SDK
# end-to-end.
set -e
set -x

./run_assistant --text_input "how do you say hi in spanish" \
--credentials_file ./credentials.json --credentials_type USER_ACCOUNT \
--verbose | grep "Hola"
9 changes: 9 additions & 0 deletions tests/integration_fr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tests that the command "how do you say hello in spanish"
# will return "buenos dias" to verify the Assistant SDK
# end-to-end.
set -e
set -x

./run_assistant --text_input "comment dit-on bonjour en español" \
--credentials_file ./credentials.json --credentials_type USER_ACCOUNT \
--locale "fr-FR" --verbose | grep "Buenos dias"
12 changes: 12 additions & 0 deletions tests/test_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Run all tests
# Expected usage:
# > cpp$ ./tests/test_all.sh
set -e
set -x

# Verify it builds
./tests/build.sh

# After building, run end-to-end tests
./tests/integration_en_us.sh
./tests/integration_fr.sh

0 comments on commit 9ac5e9b

Please sign in to comment.