avs-device-sdk/Settings/test/NetworkInfoTest.cpp

242 lines
8.4 KiB
C++
Raw Normal View History

Version 1.18.0 alexa-client-sdk Changes in this update: **Enhancements** * Added support for [Bluetooth Interface 2.0](https://developer.amazon.com/docs/alexa/alexa-voice-service/bluetooth.html). This interface adds support for multiple simultaneous connections to Bluetooth peripherals. * Added support for [Audio Focus Manager Library (AFML) Multi Activity](https://developer.amazon.com/docs/alexa/avs-device-sdk/sdk-interaction-model.html). This interface enhances the behavior of a device so it can handle more than one Activity per Channel. * Added the `obfuscatePrivateData` logging method to help remove certain data from logs. * Updated `MediaPlayerObserverInterface` to include metadata about playback states. * Added SDK extension point. You can integrate CMake projects into the SDK without cloning those projects into a subdirectory. **Bug fixes** * Fixed Mac/OSX issue that caused an unresponsive Sample App when not connected to the internet. * Fixed issue that prevented sample app from exiting various states. * Fixed `UIManager` issue that caused an error in the logs when the device with built without the wake word enabled. * Fixed volume issue that caused timers to ascend in volume when setting up ascending alarms. * Fixed alert volume issue that caused any changes to the alert volume to notify observers. * Fixed EQ issue where changes to the EQ band levels didn't notify observers. * Fixed Bluetooth bug that caused short notification sounds from a connected phone to stop audio playback on the device. **Known Issues** * Build errors can occur on the Raspberry Pi due to incorrect linking of the atomic library. A suggested workaround is to add the following `set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")` to the top most CMake file. * The WebVTT dependency required for `captions` isn't supported for Windows/Android. * Exiting from the setting option takes you back to the Options Menu directly. It doesn't provide a message to indicate that you're back in the main menu. * Failing Unit Tests and AIP Unit tests are disabled on Windows * `AudioInputProcessor` unit tests don't build on Windows when with the `-DCMAKE_BUILD_TYPE=DEBUG` cmake parameter. * Music playback history isn't displayed in the Alexa app for certain account and device types. * When using Gnu Compiler Collection 8+ (GCC 8+), `-Wclass-memaccess` triggers warnings. You can ignore these, they don't cause the build to fail. * Android error `libDefaultClient.so not found` might occur. Resolve this by upgrading to ADB version 1.0.40. * If a device loses a network connection, the lost connection status isn't returned though local TTS. * ACL encounters issues if it receives audio attachments but doesn't consume them. * Media streamed through Bluetooth might abruptly stop. To restart playback, resume the media in the source application or toggle next/previous. * If a connected Bluetooth device is inactive, the Alexa app might indicates that audio is playing. * The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation isn't yet supported. * When using some products, interrupted Bluetooth playback might not resume if other content is locally streamed. * `make integration` isn't available for Android. To run Android integration tests, manually upload the test binary and input file and run ADB. * Alexa might truncate the beginning of speech when responding to text-to-speech (TTS) user events. This only impacts Raspberry Pi devices running Android Things with HDMI output audio. * A reminder TTS message doesn't play if the sample app restarts and loses a network connection. Instead, the default alarm tone plays twice. * `ServerDisconnectIntegratonTest` tests are disabled until they are updated to reflect new service behavior. * The `DirectiveSequencerTest.test_handleBlockingThenImmediatelyThenNonBockingOnSameDialogId` test fails intermittently.
2020-02-19 18:35:26 +00:00
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Version 1.18.0 alexa-client-sdk Changes in this update: **Enhancements** * Added support for [Bluetooth Interface 2.0](https://developer.amazon.com/docs/alexa/alexa-voice-service/bluetooth.html). This interface adds support for multiple simultaneous connections to Bluetooth peripherals. * Added support for [Audio Focus Manager Library (AFML) Multi Activity](https://developer.amazon.com/docs/alexa/avs-device-sdk/sdk-interaction-model.html). This interface enhances the behavior of a device so it can handle more than one Activity per Channel. * Added the `obfuscatePrivateData` logging method to help remove certain data from logs. * Updated `MediaPlayerObserverInterface` to include metadata about playback states. * Added SDK extension point. You can integrate CMake projects into the SDK without cloning those projects into a subdirectory. **Bug fixes** * Fixed Mac/OSX issue that caused an unresponsive Sample App when not connected to the internet. * Fixed issue that prevented sample app from exiting various states. * Fixed `UIManager` issue that caused an error in the logs when the device with built without the wake word enabled. * Fixed volume issue that caused timers to ascend in volume when setting up ascending alarms. * Fixed alert volume issue that caused any changes to the alert volume to notify observers. * Fixed EQ issue where changes to the EQ band levels didn't notify observers. * Fixed Bluetooth bug that caused short notification sounds from a connected phone to stop audio playback on the device. **Known Issues** * Build errors can occur on the Raspberry Pi due to incorrect linking of the atomic library. A suggested workaround is to add the following `set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")` to the top most CMake file. * The WebVTT dependency required for `captions` isn't supported for Windows/Android. * Exiting from the setting option takes you back to the Options Menu directly. It doesn't provide a message to indicate that you're back in the main menu. * Failing Unit Tests and AIP Unit tests are disabled on Windows * `AudioInputProcessor` unit tests don't build on Windows when with the `-DCMAKE_BUILD_TYPE=DEBUG` cmake parameter. * Music playback history isn't displayed in the Alexa app for certain account and device types. * When using Gnu Compiler Collection 8+ (GCC 8+), `-Wclass-memaccess` triggers warnings. You can ignore these, they don't cause the build to fail. * Android error `libDefaultClient.so not found` might occur. Resolve this by upgrading to ADB version 1.0.40. * If a device loses a network connection, the lost connection status isn't returned though local TTS. * ACL encounters issues if it receives audio attachments but doesn't consume them. * Media streamed through Bluetooth might abruptly stop. To restart playback, resume the media in the source application or toggle next/previous. * If a connected Bluetooth device is inactive, the Alexa app might indicates that audio is playing. * The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation isn't yet supported. * When using some products, interrupted Bluetooth playback might not resume if other content is locally streamed. * `make integration` isn't available for Android. To run Android integration tests, manually upload the test binary and input file and run ADB. * Alexa might truncate the beginning of speech when responding to text-to-speech (TTS) user events. This only impacts Raspberry Pi devices running Android Things with HDMI output audio. * A reminder TTS message doesn't play if the sample app restarts and loses a network connection. Instead, the default alarm tone plays twice. * `ServerDisconnectIntegratonTest` tests are disabled until they are updated to reflect new service behavior. * The `DirectiveSequencerTest.test_handleBlockingThenImmediatelyThenNonBockingOnSameDialogId` test fails intermittently.
2020-02-19 18:35:26 +00:00
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <memory>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <Settings/Types/NetworkInfo.h>
namespace alexaClientSDK {
namespace settings {
namespace test {
using namespace alexaClientSDK::settings::types;
/// A random valid connection type.
static const auto CONNECTION_TYPE = NetworkInfo::ConnectionType::WIFI;
/// A random valid bssid.
static const auto BSSID = "10:00:22:33:44:55";
/// A random valid IP address.
static const auto IP_ADDRESS = "1.2.3.5";
/// A random valid subnet mask.
static const auto SUBNET_MASK = "1.2.3.0/2";
/// A random valid MAC address.
static const auto MAC_ADDRESS = "00:FF:00:FF:00:FF";
/// A random valid DHCP server address.
static const auto DHCP_SERVER_ADDRESS = "200.125.4.0";
/// A random valid connection type.
static const auto ESSID = "essid";
/// A random valid connection type.
static const auto IS_STATIC_IP = false;
TEST(NetworkInfoTest, test_restoreInfoFromEmptyString) {
NetworkInfo info;
std::stringstream stream;
stream << "";
stream >> std::boolalpha >> info;
EXPECT_TRUE(stream.fail());
EXPECT_FALSE(info.getConnectionType().hasValue());
EXPECT_FALSE(info.getEssid().hasValue());
EXPECT_FALSE(info.getBssid().hasValue());
EXPECT_FALSE(info.getIpAddress().hasValue());
EXPECT_FALSE(info.getSubnetMask().hasValue());
EXPECT_FALSE(info.getMacAddress().hasValue());
EXPECT_FALSE(info.getDhcpServerAddress().hasValue());
EXPECT_FALSE(info.getIsStaticIP().hasValue());
}
TEST(NetworkInfoTest, test_restoreInfoFromEmptyJson) {
NetworkInfo info;
std::stringstream stream;
stream << "{}";
stream >> std::boolalpha >> info;
EXPECT_FALSE(stream.fail());
EXPECT_FALSE(info.getConnectionType().hasValue());
EXPECT_FALSE(info.getEssid().hasValue());
EXPECT_FALSE(info.getBssid().hasValue());
EXPECT_FALSE(info.getIpAddress().hasValue());
EXPECT_FALSE(info.getSubnetMask().hasValue());
EXPECT_FALSE(info.getMacAddress().hasValue());
EXPECT_FALSE(info.getDhcpServerAddress().hasValue());
EXPECT_FALSE(info.getIsStaticIP().hasValue());
}
TEST(NetworkInfoTest, test_convertFullInfoToStringAndBack) {
NetworkInfo info;
info.setConnectionType(NetworkInfo::ConnectionType::WIFI);
info.setEssid("essid");
info.setIsStaticIP(false);
EXPECT_TRUE(info.setBssid("10:00:22:33:44:55"));
EXPECT_TRUE(info.setIpAddress("1.2.3.5"));
EXPECT_TRUE(info.setSubnetMask("1.2.3.0/2"));
EXPECT_TRUE(info.setMacAddress("00:FF:00:FF:00:FF"));
EXPECT_TRUE(info.setDhcpServerAddress("200.125.4.0"));
NetworkInfo info2;
ASSERT_NE(info, info2);
std::stringstream stream;
stream << info;
stream >> info2;
EXPECT_EQ(info, info2);
}
TEST(NetworkInfoTest, test_outputEmptyNetworkInfo) {
NetworkInfo info;
std::stringstream stream;
stream << info;
EXPECT_EQ(stream.str(), "{}");
}
TEST(NetworkInfoTest, test_setIpV4Address) {
NetworkInfo info;
EXPECT_TRUE(info.setIpAddress("0.0.0.0"));
EXPECT_TRUE(info.setIpAddress("255.255.255.255"));
EXPECT_FALSE(info.setIpAddress("255.255.255. 255"));
EXPECT_FALSE(info.setIpAddress("-255.255.255.255"));
EXPECT_FALSE(info.setIpAddress("255.255.255.2555"));
EXPECT_FALSE(info.setIpAddress("255.255.255"));
EXPECT_FALSE(info.setIpAddress("255.255.255.255.5"));
EXPECT_FALSE(info.setIpAddress("255.255.255:19"));
EXPECT_FALSE(info.setIpAddress("255.255.F.19"));
}
TEST(NetworkInfoTest, test_setIpV6Address) {
NetworkInfo info;
EXPECT_TRUE(info.setIpAddress("FFFF::1234"));
EXPECT_TRUE(info.setIpAddress("::FFFF:1234"));
EXPECT_TRUE(info.setIpAddress("255:0001:FFFF:AAAE:2345:2:44:23"));
EXPECT_FALSE(info.setIpAddress("FFFF::-1234"));
EXPECT_FALSE(info.setIpAddress("FFFF::1234::AAAA"));
EXPECT_FALSE(info.setIpAddress("255:0001:FFFF:AAAE:2345:2:44:23211"));
EXPECT_FALSE(info.setIpAddress("FFFF::-1234"));
}
TEST(NetworkInfoTest, test_setMacAddress) {
NetworkInfo info;
EXPECT_TRUE(info.setMacAddress("00:00:23:11:35:34"));
EXPECT_TRUE(info.setMacAddress("FF:EE:DD:CC:BB:AA"));
EXPECT_TRUE(info.setMacAddress("F5:E4:D3:C2:B1:A0"));
EXPECT_FALSE(info.setMacAddress("F5:E4:D3:C2:B1:A0:"));
EXPECT_FALSE(info.setMacAddress("F5:E4:D3:C2:B1:A0:0"));
}
TEST(NetworkInfoTest, test_setSubnetMask) {
NetworkInfo info;
// IPv4.
EXPECT_TRUE(info.setSubnetMask("0.0.0.0/20"));
EXPECT_TRUE(info.setSubnetMask("255.255.255.255/8"));
EXPECT_TRUE(info.setSubnetMask("255.255.255.0"));
EXPECT_FALSE(info.setSubnetMask("255.255.255.255/33"));
EXPECT_FALSE(info.setSubnetMask("255.255.255.255/-2"));
EXPECT_FALSE(info.setSubnetMask("-255.255.255.255/21"));
EXPECT_FALSE(info.setSubnetMask("255.255.255.2555/20"));
EXPECT_FALSE(info.setSubnetMask("255.255.255.255/"));
EXPECT_FALSE(info.setSubnetMask("255.255.255.255/a"));
// IPv6.
EXPECT_TRUE(info.setSubnetMask("FFFF::1234/100"));
EXPECT_TRUE(info.setSubnetMask("255:0001:FFFF:AAAE:2345:2:44:23/120"));
EXPECT_FALSE(info.setSubnetMask("255:0001:FFFF:AAAE:2345:2:44:23/250"));
}
TEST(NetworkInfoTest, test_emptyGetters) {
NetworkInfo info;
EXPECT_FALSE(info.getConnectionType().hasValue());
EXPECT_FALSE(info.getEssid().hasValue());
EXPECT_FALSE(info.getBssid().hasValue());
EXPECT_FALSE(info.getIpAddress().hasValue());
EXPECT_FALSE(info.getSubnetMask().hasValue());
EXPECT_FALSE(info.getMacAddress().hasValue());
EXPECT_FALSE(info.getDhcpServerAddress().hasValue());
EXPECT_FALSE(info.getIsStaticIP().hasValue());
}
TEST(NetworkInfoTest, test_gettersAfterSet) {
NetworkInfo info;
info.setConnectionType(CONNECTION_TYPE);
info.setEssid(ESSID);
info.setIsStaticIP(IS_STATIC_IP);
EXPECT_TRUE(info.setBssid(BSSID));
EXPECT_TRUE(info.setIpAddress(IP_ADDRESS));
EXPECT_TRUE(info.setSubnetMask(SUBNET_MASK));
EXPECT_TRUE(info.setMacAddress(MAC_ADDRESS));
EXPECT_TRUE(info.setDhcpServerAddress(DHCP_SERVER_ADDRESS));
ASSERT_TRUE(info.getConnectionType().hasValue());
ASSERT_TRUE(info.getEssid().hasValue());
ASSERT_TRUE(info.getBssid().hasValue());
ASSERT_TRUE(info.getIpAddress().hasValue());
ASSERT_TRUE(info.getSubnetMask().hasValue());
ASSERT_TRUE(info.getMacAddress().hasValue());
ASSERT_TRUE(info.getDhcpServerAddress().hasValue());
ASSERT_TRUE(info.getIsStaticIP().hasValue());
EXPECT_EQ(info.getConnectionType().value(), CONNECTION_TYPE);
EXPECT_EQ(info.getEssid().value(), ESSID);
EXPECT_EQ(info.getBssid().value(), BSSID);
EXPECT_EQ(info.getIpAddress().value(), IP_ADDRESS);
EXPECT_EQ(info.getSubnetMask().value(), SUBNET_MASK);
EXPECT_EQ(info.getMacAddress().value(), MAC_ADDRESS);
EXPECT_EQ(info.getDhcpServerAddress().value(), DHCP_SERVER_ADDRESS);
EXPECT_EQ(info.getIsStaticIP().value(), IS_STATIC_IP);
}
TEST(NetworkInfoTest, test_gettersAfterReset) {
NetworkInfo info;
info.setConnectionType(CONNECTION_TYPE);
info.setEssid(ESSID);
info.setIsStaticIP(IS_STATIC_IP);
EXPECT_TRUE(info.setBssid(BSSID));
EXPECT_TRUE(info.setIpAddress(IP_ADDRESS));
EXPECT_TRUE(info.setSubnetMask(SUBNET_MASK));
EXPECT_TRUE(info.setMacAddress(MAC_ADDRESS));
EXPECT_TRUE(info.setDhcpServerAddress(DHCP_SERVER_ADDRESS));
info.resetConnectionType();
info.resetEssid();
info.resetBssid();
info.resetIpAddress();
info.resetSubnetMask();
info.resetMacAddress();
info.resetDhcpServerAddress();
info.resetIsStaticIP();
EXPECT_FALSE(info.getConnectionType().hasValue());
EXPECT_FALSE(info.getEssid().hasValue());
EXPECT_FALSE(info.getBssid().hasValue());
EXPECT_FALSE(info.getIpAddress().hasValue());
EXPECT_FALSE(info.getSubnetMask().hasValue());
EXPECT_FALSE(info.getMacAddress().hasValue());
EXPECT_FALSE(info.getDhcpServerAddress().hasValue());
EXPECT_FALSE(info.getIsStaticIP().hasValue());
}
} // namespace test
} // namespace settings
} // namespace alexaClientSDK