From 02008bcccdeed44f87b6a0dfa85557f5aa7a4dde Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:30:09 +0530 Subject: [PATCH] Removed using namespace std from all files (#35741) * Removed using namespace std from all files * Fix compilation * Found some more files were using namespace std * Fix TV app * Use std::to_underlying with c++23 and later * Addressed review comments --- .../src/static-supported-modes-manager.cpp | 1 - .../static-supported-temperature-levels.cpp | 1 - .../audio-output/AudioOutputManager.cpp | 1 - .../media-input/MediaInputManager.cpp | 1 - .../media-playback/MediaPlaybackManager.cpp | 1 - .../TargetNavigatorManager.cpp | 1 - .../linux/static-supported-modes-manager.cpp | 1 - .../static-supported-temperature-levels.cpp | 1 - .../static-supported-temperature-levels.cpp | 1 - .../account-login/AccountLoginManager.cpp | 19 +++---- .../ApplicationBasicManager.cpp | 1 - .../audio-output/AudioOutputManager.cpp | 1 - .../ContentAppObserver.cpp | 1 - .../content-control/ContentController.cpp | 1 - .../AppContentLauncherManager.cpp | 14 ++--- .../AppMediaPlaybackManager.cpp | 9 ++- .../include/messages/MessagesManager.cpp | 1 - .../TargetNavigatorManager.cpp | 9 ++- .../android/java/ContentLauncherManager.cpp | 1 - .../ApplicationLauncherManager.cpp | 1 - .../account-login/AccountLoginManager.cpp | 7 +-- .../ApplicationBasicManager.cpp | 1 - .../ApplicationLauncherManager.cpp | 1 - .../audio-output/AudioOutputManager.cpp | 1 - .../ContentAppObserver.cpp | 1 - .../content-control/ContentController.cpp | 1 - .../ContentLauncherManager.cpp | 15 +++-- .../media-input/MediaInputManager.cpp | 5 +- .../media-playback/MediaPlaybackManager.cpp | 1 - .../clusters/messages/MessagesManager.cpp | 1 - .../TargetNavigatorManager.cpp | 1 - .../ContentAppObserver.cpp | 5 +- .../core/CastingPlayerDiscovery.cpp | 1 - .../dishwasher-alarm-server.cpp | 1 - .../mode-select-server/mode-select-server.cpp | 1 - .../refrigerator-alarm-server.cpp | 1 - .../resource-monitoring-server.cpp | 2 - .../tests/FuzzPacketParsingPW.cpp | 11 ++-- .../minimal_mdns/tests/TestAdvertiser.cpp | 1 - .../minimal_mdns/tests/TestRecordData.cpp | 17 +++--- .../minimal_mdns/tests/TestResponseSender.cpp | 1 - src/lib/support/TypeTraits.h | 10 ++++ src/platform/Tizen/SystemInfo.cpp | 2 - src/platform/stm32/CHIPMem-Platform.cpp | 2 - src/setup_payload/tests/TestQRCode.cpp | 55 +++++++++---------- src/setup_payload/tests/TestQRCodeTLV.cpp | 25 ++++----- 46 files changed, 100 insertions(+), 137 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp index 94345600cf53fd..59bccf11faa481 100644 --- a/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp @@ -1,7 +1,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ModeSelect; diff --git a/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp b/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp index 6019006c2a2868..5ed8a0c40f5e89 100644 --- a/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::TemperatureControl; diff --git a/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp b/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp index 06a123a6549679..65df8db9ff0bb2 100644 --- a/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp +++ b/examples/chef/common/clusters/audio-output/AudioOutputManager.cpp @@ -20,7 +20,6 @@ #ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER #include "AudioOutputManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::AudioOutput; using chip::app::AttributeValueEncoder; diff --git a/examples/chef/common/clusters/media-input/MediaInputManager.cpp b/examples/chef/common/clusters/media-input/MediaInputManager.cpp index 53cc22cd65cce8..4d11d9934ae8ab 100644 --- a/examples/chef/common/clusters/media-input/MediaInputManager.cpp +++ b/examples/chef/common/clusters/media-input/MediaInputManager.cpp @@ -22,7 +22,6 @@ #ifdef MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER #include "MediaInputManager.h" -using namespace std; using namespace chip; using namespace chip::app::Clusters::MediaInput; using Protocols::InteractionModel::Status; diff --git a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp index db3af119c5b286..cf8bcda33cd757 100644 --- a/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp +++ b/examples/chef/common/clusters/media-playback/MediaPlaybackManager.cpp @@ -22,7 +22,6 @@ #ifdef MATTER_DM_PLUGIN_MEDIA_PLAYBACK_SERVER #include "MediaPlaybackManager.h" -using namespace std; using namespace chip; using namespace chip::app; using namespace chip::app::DataModel; diff --git a/examples/chef/common/clusters/target-navigator/TargetNavigatorManager.cpp b/examples/chef/common/clusters/target-navigator/TargetNavigatorManager.cpp index be20f92f53a8fe..1f2dcdedb048e6 100644 --- a/examples/chef/common/clusters/target-navigator/TargetNavigatorManager.cpp +++ b/examples/chef/common/clusters/target-navigator/TargetNavigatorManager.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::TargetNavigator; diff --git a/examples/placeholder/linux/static-supported-modes-manager.cpp b/examples/placeholder/linux/static-supported-modes-manager.cpp index 94345600cf53fd..59bccf11faa481 100644 --- a/examples/placeholder/linux/static-supported-modes-manager.cpp +++ b/examples/placeholder/linux/static-supported-modes-manager.cpp @@ -1,7 +1,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ModeSelect; diff --git a/examples/placeholder/linux/static-supported-temperature-levels.cpp b/examples/placeholder/linux/static-supported-temperature-levels.cpp index de8933fdf649ea..4b65317e8cc58f 100644 --- a/examples/placeholder/linux/static-supported-temperature-levels.cpp +++ b/examples/placeholder/linux/static-supported-temperature-levels.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::TemperatureControl; diff --git a/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp b/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp index 8678e5f3d009d0..a7198c0cf0a3b6 100644 --- a/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp +++ b/examples/refrigerator-app/refrigerator-common/src/static-supported-temperature-levels.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::TemperatureControl; diff --git a/examples/tv-app/android/include/account-login/AccountLoginManager.cpp b/examples/tv-app/android/include/account-login/AccountLoginManager.cpp index 2aa0b313b0eda1..a7e9c9fd627c1a 100644 --- a/examples/tv-app/android/include/account-login/AccountLoginManager.cpp +++ b/examples/tv-app/android/include/account-login/AccountLoginManager.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; using namespace chip::app::Clusters; using namespace chip::app::Clusters::AccountLogin; using Status = chip::Protocols::InteractionModel::Status; @@ -31,12 +30,12 @@ using Status = chip::Protocols::InteractionModel::Status; namespace { const auto loginTempAccountIdentifierFieldId = - to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier)); -const auto loginSetupPINFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN)); -const auto loginNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode)); -const auto logoutNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode)); + std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier)); +const auto loginSetupPINFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN)); +const auto loginNodeFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode)); +const auto logoutNodeFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode)); -string charSpanToString(const CharSpan & charSpan) +std::string charSpanToString(const CharSpan & charSpan) { return { charSpan.data(), charSpan.size() }; } @@ -45,12 +44,12 @@ std::string serializeLoginCommand(AccountLogin::Commands::Login::Type cmd) { return R"({")" + loginTempAccountIdentifierFieldId + R"(":")" + charSpanToString(cmd.tempAccountIdentifier) + R"(",)" + R"(")" + loginSetupPINFieldId + R"(":")" + charSpanToString(cmd.setupPIN) + R"(",)" + R"(")" + loginNodeFieldId + R"(":")" + - to_string(cmd.node.Value()) + R"("})"; + std::to_string(cmd.node.Value()) + R"("})"; } std::string serializeLogoutCommand(AccountLogin::Commands::Logout::Type cmd) { - return R"({")" + logoutNodeFieldId + R"(":")" + to_string(cmd.node.Value()) + R"("})"; + return R"({")" + logoutNodeFieldId + R"(":")" + std::to_string(cmd.node.Value()) + R"("})"; } } // namespace @@ -128,7 +127,7 @@ bool AccountLoginManager::HandleLogout(const chip::Optional & node void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper & helper, const CharSpan & tempAccountIdentifier) { - string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); GetSetupPINResponse response; ChipLogProgress(Zcl, "temporary account id: %s returning pin: %s", tempAccountIdentifierString.c_str(), mSetupPin); @@ -144,7 +143,7 @@ void AccountLoginManager::GetSetupPin(char * setupPin, size_t setupPinSize, cons // Other methods in this class do not need to be changed beecause those will get routed to java layer // upstream. ChipLogProgress(DeviceLayer, "AccountLoginManager::GetSetupPin called for endpoint %d", mEndpointId); - string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); if (mCommandDelegate == nullptr) { // For the dummy content apps to work. diff --git a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp index d94177155f4fde..80e11460bd88e3 100644 --- a/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp +++ b/examples/tv-app/android/include/application-basic/ApplicationBasicManager.cpp @@ -18,7 +18,6 @@ #include "ApplicationBasicManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::ApplicationBasic; diff --git a/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp b/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp index 1b8a6a36c84912..77a1e2111b44be 100644 --- a/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp +++ b/examples/tv-app/android/include/audio-output/AudioOutputManager.cpp @@ -18,7 +18,6 @@ #include "AudioOutputManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::AudioOutput; diff --git a/examples/tv-app/android/include/content-app-observer/ContentAppObserver.cpp b/examples/tv-app/android/include/content-app-observer/ContentAppObserver.cpp index 7145ba24305f21..158da869c07b67 100644 --- a/examples/tv-app/android/include/content-app-observer/ContentAppObserver.cpp +++ b/examples/tv-app/android/include/content-app-observer/ContentAppObserver.cpp @@ -20,7 +20,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters::ContentAppObserver; diff --git a/examples/tv-app/android/include/content-control/ContentController.cpp b/examples/tv-app/android/include/content-control/ContentController.cpp index edf2550c489d62..4883d4f78086e8 100644 --- a/examples/tv-app/android/include/content-control/ContentController.cpp +++ b/examples/tv-app/android/include/content-control/ContentController.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; diff --git a/examples/tv-app/android/include/content-launcher/AppContentLauncherManager.cpp b/examples/tv-app/android/include/content-launcher/AppContentLauncherManager.cpp index 671daab4b239c4..ab98213f068ac3 100644 --- a/examples/tv-app/android/include/content-launcher/AppContentLauncherManager.cpp +++ b/examples/tv-app/android/include/content-launcher/AppContentLauncherManager.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; @@ -32,7 +31,8 @@ using namespace chip::app::Clusters::ContentLauncher; using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate; AppContentLauncherManager::AppContentLauncherManager(ContentAppAttributeDelegate * attributeDelegate, - list acceptHeaderList, uint32_t supportedStreamingProtocols) : + std::list acceptHeaderList, + uint32_t supportedStreamingProtocols) : mAttributeDelegate(attributeDelegate) { mAcceptHeaderList = acceptHeaderList; @@ -46,7 +46,7 @@ void AppContentLauncherManager::HandleLaunchContent(CommandResponseHelper -using namespace std; using namespace chip; using namespace chip::app; using namespace chip::app::DataModel; @@ -204,7 +203,7 @@ uint64_t AppMediaPlaybackManager::HandleMediaRequestGetAttribute(chip::Attribute Json::Value value; if (reader.parse(resStr, value)) { - std::string attrId = to_string(attributeId); + std::string attrId = std::to_string(attributeId); ChipLogProgress(Zcl, "AppMediaPlaybackManager::HandleMediaRequestGetAttribute response parsing done. reading attr %s", attrId.c_str()); if (!value[attrId].empty() && value[attrId].isUInt()) @@ -250,14 +249,14 @@ CHIP_ERROR AppMediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncod Json::Value value; if (reader.parse(resStr, value)) { - std::string attrId = to_string(chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::Id); + std::string attrId = std::to_string(chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::Id); ChipLogProgress(Zcl, "AppContentLauncherManager::HandleGetSampledPosition response parsing done. reading attr %s", attrId.c_str()); if (!value[attrId].empty() && value[attrId].isObject()) { - std::string updatedAt = to_string( + std::string updatedAt = std::to_string( static_cast(chip::app::Clusters::MediaPlayback::Structs::PlaybackPositionStruct::Fields::kUpdatedAt)); - std::string position = to_string( + std::string position = std::to_string( static_cast(chip::app::Clusters::MediaPlayback::Structs::PlaybackPositionStruct::Fields::kPosition)); if (!value[attrId][updatedAt].empty() && !value[attrId][position].empty() && value[attrId][updatedAt].isUInt() && value[attrId][position].isUInt()) diff --git a/examples/tv-app/android/include/messages/MessagesManager.cpp b/examples/tv-app/android/include/messages/MessagesManager.cpp index 00848c67312751..a4fdaa53291394 100644 --- a/examples/tv-app/android/include/messages/MessagesManager.cpp +++ b/examples/tv-app/android/include/messages/MessagesManager.cpp @@ -17,7 +17,6 @@ #include "MessagesManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::Messages; diff --git a/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.cpp b/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.cpp index fe7884227880df..3b84a050d3e51a 100644 --- a/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.cpp +++ b/examples/tv-app/android/include/target-navigator/TargetNavigatorManager.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::TargetNavigator; using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate; @@ -53,16 +52,16 @@ CHIP_ERROR TargetNavigatorManager::HandleGetTargetList(AttributeValueEncoder & a Json::Value value; if (reader.parse(resStr, value)) { - std::string attrId = to_string(chip::app::Clusters::TargetNavigator::Attributes::TargetList::Id); + std::string attrId = std::to_string(chip::app::Clusters::TargetNavigator::Attributes::TargetList::Id); ChipLogProgress(Zcl, "TargetNavigatorManager::HandleNavigateTarget response parsing done. reading attr %s", attrId.c_str()); if (value[attrId].isArray()) { return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { int i = 0; - std::string targetId = to_string(static_cast( + std::string targetId = std::to_string(static_cast( chip::app::Clusters::TargetNavigator::Structs::TargetInfoStruct::Fields::kIdentifier)); - std::string targetName = to_string( + std::string targetName = std::to_string( static_cast(chip::app::Clusters::TargetNavigator::Structs::TargetInfoStruct::Fields::kName)); for (Json::Value & entry : value[attrId]) { @@ -118,7 +117,7 @@ uint8_t TargetNavigatorManager::HandleGetCurrentTarget() Json::Value value; if (reader.parse(resStr, value)) { - std::string attrId = to_string(chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::Id); + std::string attrId = std::to_string(chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::Id); ChipLogProgress(Zcl, "TargetNavigatorManager::HandleGetCurrentTarget response parsing done. reading attr %s", attrId.c_str()); if (value[attrId].isUInt() && value[attrId].asUInt() < 256) diff --git a/examples/tv-app/android/java/ContentLauncherManager.cpp b/examples/tv-app/android/java/ContentLauncherManager.cpp index 9aacc2d6e56b22..b1c3a8cac64a4b 100644 --- a/examples/tv-app/android/java/ContentLauncherManager.cpp +++ b/examples/tv-app/android/java/ContentLauncherManager.cpp @@ -27,7 +27,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::DataModel; using namespace chip::app::Clusters::ContentLauncher; diff --git a/examples/tv-app/android/java/application-launcher/ApplicationLauncherManager.cpp b/examples/tv-app/android/java/application-launcher/ApplicationLauncherManager.cpp index 8ee91292a5e76a..9267a086c64c56 100644 --- a/examples/tv-app/android/java/application-launcher/ApplicationLauncherManager.cpp +++ b/examples/tv-app/android/java/application-launcher/ApplicationLauncherManager.cpp @@ -27,7 +27,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ApplicationLauncher; diff --git a/examples/tv-app/tv-common/clusters/account-login/AccountLoginManager.cpp b/examples/tv-app/tv-common/clusters/account-login/AccountLoginManager.cpp index 9264553c14d002..21c96255ea6f37 100644 --- a/examples/tv-app/tv-common/clusters/account-login/AccountLoginManager.cpp +++ b/examples/tv-app/tv-common/clusters/account-login/AccountLoginManager.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace chip::app::Clusters::AccountLogin; AccountLoginManager::AccountLoginManager(const char * setupPin) @@ -32,8 +31,8 @@ AccountLoginManager::AccountLoginManager(const char * setupPin) bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPin, const chip::Optional & nodeId) { - string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); - string setupPinString(setupPin.data(), setupPin.size()); + std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + std::string setupPinString(setupPin.data(), setupPin.size()); ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str()); ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str()); @@ -57,7 +56,7 @@ bool AccountLoginManager::HandleLogout(const chip::Optional & node void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper & helper, const CharSpan & tempAccountIdentifier) { - string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); + std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size()); GetSetupPINResponse response; ChipLogProgress(Zcl, "temporary account id: %s returning pin: %s", tempAccountIdentifierString.c_str(), mSetupPin); diff --git a/examples/tv-app/tv-common/clusters/application-basic/ApplicationBasicManager.cpp b/examples/tv-app/tv-common/clusters/application-basic/ApplicationBasicManager.cpp index d94177155f4fde..80e11460bd88e3 100644 --- a/examples/tv-app/tv-common/clusters/application-basic/ApplicationBasicManager.cpp +++ b/examples/tv-app/tv-common/clusters/application-basic/ApplicationBasicManager.cpp @@ -18,7 +18,6 @@ #include "ApplicationBasicManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::ApplicationBasic; diff --git a/examples/tv-app/tv-common/clusters/application-launcher/ApplicationLauncherManager.cpp b/examples/tv-app/tv-common/clusters/application-launcher/ApplicationLauncherManager.cpp index c915856f48fd4d..3a4960970f06ba 100644 --- a/examples/tv-app/tv-common/clusters/application-launcher/ApplicationLauncherManager.cpp +++ b/examples/tv-app/tv-common/clusters/application-launcher/ApplicationLauncherManager.cpp @@ -18,7 +18,6 @@ #include "ApplicationLauncherManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ApplicationLauncher; diff --git a/examples/tv-app/tv-common/clusters/audio-output/AudioOutputManager.cpp b/examples/tv-app/tv-common/clusters/audio-output/AudioOutputManager.cpp index 1b8a6a36c84912..77a1e2111b44be 100644 --- a/examples/tv-app/tv-common/clusters/audio-output/AudioOutputManager.cpp +++ b/examples/tv-app/tv-common/clusters/audio-output/AudioOutputManager.cpp @@ -18,7 +18,6 @@ #include "AudioOutputManager.h" -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::AudioOutput; diff --git a/examples/tv-app/tv-common/clusters/content-app-observer/ContentAppObserver.cpp b/examples/tv-app/tv-common/clusters/content-app-observer/ContentAppObserver.cpp index a6010a54b0a0f5..9c42fe3f11a525 100644 --- a/examples/tv-app/tv-common/clusters/content-app-observer/ContentAppObserver.cpp +++ b/examples/tv-app/tv-common/clusters/content-app-observer/ContentAppObserver.cpp @@ -20,7 +20,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters::ContentAppObserver; diff --git a/examples/tv-app/tv-common/clusters/content-control/ContentController.cpp b/examples/tv-app/tv-common/clusters/content-control/ContentController.cpp index 19317a71b7cfaf..352b204bab65cb 100644 --- a/examples/tv-app/tv-common/clusters/content-control/ContentController.cpp +++ b/examples/tv-app/tv-common/clusters/content-control/ContentController.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; diff --git a/examples/tv-app/tv-common/clusters/content-launcher/ContentLauncherManager.cpp b/examples/tv-app/tv-common/clusters/content-launcher/ContentLauncherManager.cpp index f0519619c2052a..74dd6de8c8071a 100644 --- a/examples/tv-app/tv-common/clusters/content-launcher/ContentLauncherManager.cpp +++ b/examples/tv-app/tv-common/clusters/content-launcher/ContentLauncherManager.cpp @@ -23,13 +23,12 @@ #include #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; using namespace chip::app::Clusters::ContentLauncher; -ContentLauncherManager::ContentLauncherManager(list acceptHeaderList, uint32_t supportedStreamingProtocols) +ContentLauncherManager::ContentLauncherManager(std::list acceptHeaderList, uint32_t supportedStreamingProtocols) { mAcceptHeaderList = acceptHeaderList; mSupportedStreamingProtocols = supportedStreamingProtocols; @@ -103,7 +102,7 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper -using namespace std; using namespace chip; using namespace chip::app::Clusters::MediaInput; @@ -76,8 +75,8 @@ bool MediaInputManager::HandleShowInputStatus() ChipLogProgress(Zcl, " MediaInputManager::HandleShowInputStatus()"); for (auto const & inputInfo : this->mInputs) { - string name(inputInfo.name.data(), inputInfo.name.size()); - string desc(inputInfo.description.data(), inputInfo.description.size()); + std::string name(inputInfo.name.data(), inputInfo.name.size()); + std::string desc(inputInfo.description.data(), inputInfo.description.size()); ChipLogProgress(Zcl, " [%d] type=%d selected=%d name=%s desc=%s", inputInfo.index, static_cast(inputInfo.inputType), (mCurrentInput == inputInfo.index ? 1 : 0), name.c_str(), desc.c_str()); diff --git a/examples/tv-app/tv-common/clusters/media-playback/MediaPlaybackManager.cpp b/examples/tv-app/tv-common/clusters/media-playback/MediaPlaybackManager.cpp index 0e79c6b2a3e9a3..91159021842e75 100644 --- a/examples/tv-app/tv-common/clusters/media-playback/MediaPlaybackManager.cpp +++ b/examples/tv-app/tv-common/clusters/media-playback/MediaPlaybackManager.cpp @@ -21,7 +21,6 @@ #include -using namespace std; using namespace chip::app::DataModel; using namespace chip::app::Clusters::MediaPlayback; using namespace chip::Uint8; diff --git a/examples/tv-app/tv-common/clusters/messages/MessagesManager.cpp b/examples/tv-app/tv-common/clusters/messages/MessagesManager.cpp index 681cd56d6647fa..181c37ca0c3d5a 100644 --- a/examples/tv-app/tv-common/clusters/messages/MessagesManager.cpp +++ b/examples/tv-app/tv-common/clusters/messages/MessagesManager.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app; using namespace chip::app::Clusters::Messages; diff --git a/examples/tv-app/tv-common/clusters/target-navigator/TargetNavigatorManager.cpp b/examples/tv-app/tv-common/clusters/target-navigator/TargetNavigatorManager.cpp index dced0371fb9f39..03932528e57b0d 100644 --- a/examples/tv-app/tv-common/clusters/target-navigator/TargetNavigatorManager.cpp +++ b/examples/tv-app/tv-common/clusters/target-navigator/TargetNavigatorManager.cpp @@ -21,7 +21,6 @@ #include -using namespace std; using namespace chip::app; using namespace chip::app::Clusters::TargetNavigator; diff --git a/examples/tv-casting-app/tv-casting-common/clusters/content-app-observer/ContentAppObserver.cpp b/examples/tv-casting-app/tv-casting-common/clusters/content-app-observer/ContentAppObserver.cpp index a6010a54b0a0f5..5be511a575a515 100644 --- a/examples/tv-casting-app/tv-casting-common/clusters/content-app-observer/ContentAppObserver.cpp +++ b/examples/tv-casting-app/tv-casting-common/clusters/content-app-observer/ContentAppObserver.cpp @@ -20,7 +20,6 @@ #include #include -using namespace std; using namespace chip; using namespace chip::app::Clusters::ContentAppObserver; @@ -35,8 +34,8 @@ void ContentAppObserverManager::HandleContentAppMessage(chip::app::CommandRespon { ChipLogProgress(Zcl, "ContentAppObserverManager::HandleContentAppMessage"); - string dataString(data.HasValue() ? data.Value().data() : "", data.HasValue() ? data.Value().size() : 0); - string encodingHintString(encodingHint.data(), encodingHint.size()); + std::string dataString(data.HasValue() ? data.Value().data() : "", data.HasValue() ? data.Value().size() : 0); + std::string encodingHintString(encodingHint.data(), encodingHint.size()); ChipLogProgress(Zcl, "ContentAppObserverManager::HandleContentAppMessage TEST CASE hint=%s data=%s ", encodingHintString.c_str(), dataString.c_str()); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index 81d1f78fe1b33a..4dee3550f3e0bb 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -25,7 +25,6 @@ namespace core { using namespace chip::System; using namespace chip::Controller; using namespace chip::Dnssd; -using namespace std; CastingPlayerDiscovery * CastingPlayerDiscovery::_castingPlayerDiscovery = nullptr; diff --git a/src/app/clusters/dishwasher-alarm-server/dishwasher-alarm-server.cpp b/src/app/clusters/dishwasher-alarm-server/dishwasher-alarm-server.cpp index b3c9b8edbccf34..672df0af786d3d 100644 --- a/src/app/clusters/dishwasher-alarm-server/dishwasher-alarm-server.cpp +++ b/src/app/clusters/dishwasher-alarm-server/dishwasher-alarm-server.cpp @@ -33,7 +33,6 @@ using namespace chip::app::Clusters::DishwasherAlarm; using namespace chip::app::Clusters::DishwasherAlarm::Attributes; using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; -using namespace std; static constexpr size_t kDishwasherAlarmDelegateTableSize = MATTER_DM_DISHWASHER_ALARM_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; diff --git a/src/app/clusters/mode-select-server/mode-select-server.cpp b/src/app/clusters/mode-select-server/mode-select-server.cpp index 5f247bb4b2e95d..813d16d965148e 100644 --- a/src/app/clusters/mode-select-server/mode-select-server.cpp +++ b/src/app/clusters/mode-select-server/mode-select-server.cpp @@ -37,7 +37,6 @@ #include #endif // MATTER_DM_PLUGIN_ON_OFF -using namespace std; using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index 620e113177c1c7..751bd768cdf8ee 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -32,7 +32,6 @@ using namespace chip::app::Clusters::RefrigeratorAlarm::Attributes; using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; -using namespace std; RefrigeratorAlarmServer RefrigeratorAlarmServer::instance; RefrigeratorAlarmServer & RefrigeratorAlarmServer::Instance() diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index b8d885599245a4..6c581ff72a9e19 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -34,8 +34,6 @@ #include #include -// using namespace std; -using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; diff --git a/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp b/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp index aec550b26e026a..0ea5de55013994 100644 --- a/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/FuzzPacketParsingPW.cpp @@ -10,7 +10,6 @@ namespace { using namespace fuzztest; -using namespace std; using namespace chip; using namespace mdns::Minimal; @@ -65,16 +64,16 @@ void PacketParserFuzz(const std::vector & bytes) mdns::Minimal::ParsePacket(packet, &delegate); } -FUZZ_TEST(MinimalmDNS, PacketParserFuzz).WithDomains(Arbitrary>()); +FUZZ_TEST(MinimalmDNS, PacketParserFuzz).WithDomains(Arbitrary>()); class TxtRecordAccumulator : public TxtRecordDelegate { public: - using DataType = vector>; + using DataType = std::vector>; void OnRecord(const BytesRange & name, const BytesRange & value) override { - mData.push_back(make_pair(AsString(name), AsString(value))); + mData.push_back(std::make_pair(AsString(name), AsString(value))); } DataType & Data() { return mData; } @@ -83,9 +82,9 @@ class TxtRecordAccumulator : public TxtRecordDelegate private: DataType mData; - static string AsString(const BytesRange & range) + static std::string AsString(const BytesRange & range) { - return string(reinterpret_cast(range.Start()), reinterpret_cast(range.End())); + return std::string(reinterpret_cast(range.Start()), reinterpret_cast(range.End())); } }; diff --git a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp index ea85f74d2be11a..6b626be3631d33 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp @@ -38,7 +38,6 @@ namespace { -using namespace std; using namespace chip; using namespace chip::Dnssd; using namespace mdns::Minimal; diff --git a/src/lib/dnssd/minimal_mdns/tests/TestRecordData.cpp b/src/lib/dnssd/minimal_mdns/tests/TestRecordData.cpp index dcd48959be01ea..ae9e37e42ad960 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestRecordData.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestRecordData.cpp @@ -26,7 +26,6 @@ namespace { -using namespace std; using namespace chip; using namespace mdns::Minimal; @@ -205,11 +204,11 @@ TEST(TestRecordData, PtrRecordComplexParsing) class TxtRecordAccumulator : public TxtRecordDelegate { public: - using DataType = vector>; + using DataType = std::vector>; void OnRecord(const BytesRange & name, const BytesRange & value) override { - mData.push_back(make_pair(AsString(name), AsString(value))); + mData.push_back(std::make_pair(AsString(name), AsString(value))); } DataType & Data() { return mData; } @@ -218,9 +217,9 @@ class TxtRecordAccumulator : public TxtRecordDelegate private: DataType mData; - static string AsString(const BytesRange & range) + static std::string AsString(const BytesRange & range) { - return string(reinterpret_cast(range.Start()), reinterpret_cast(range.End())); + return std::string(reinterpret_cast(range.Start()), reinterpret_cast(range.End())); } }; @@ -237,9 +236,9 @@ TEST(TestRecordData, TxtRecord) EXPECT_TRUE(ParseTxtRecord(BytesRange(record, record + sizeof(record)), &accumulator)); EXPECT_EQ(accumulator.Data().size(), 4u); - EXPECT_EQ(accumulator.Data()[0], (make_pair("some", ""))); - EXPECT_EQ(accumulator.Data()[1], (make_pair("foo", "bar"))); - EXPECT_EQ(accumulator.Data()[2], (make_pair("x", "y=z"))); - EXPECT_EQ(accumulator.Data()[3], (make_pair("a", ""))); + EXPECT_EQ(accumulator.Data()[0], (std::make_pair("some", ""))); + EXPECT_EQ(accumulator.Data()[1], (std::make_pair("foo", "bar"))); + EXPECT_EQ(accumulator.Data()[2], (std::make_pair("x", "y=z"))); + EXPECT_EQ(accumulator.Data()[3], (std::make_pair("a", ""))); } } // namespace diff --git a/src/lib/dnssd/minimal_mdns/tests/TestResponseSender.cpp b/src/lib/dnssd/minimal_mdns/tests/TestResponseSender.cpp index abfceb52080f13..c08b6c82b84b8c 100644 --- a/src/lib/dnssd/minimal_mdns/tests/TestResponseSender.cpp +++ b/src/lib/dnssd/minimal_mdns/tests/TestResponseSender.cpp @@ -34,7 +34,6 @@ namespace { -using namespace std; using namespace chip; using namespace mdns::Minimal; using namespace mdns::Minimal::test; diff --git a/src/lib/support/TypeTraits.h b/src/lib/support/TypeTraits.h index e8718a223e4294..4d326027a17753 100644 --- a/src/lib/support/TypeTraits.h +++ b/src/lib/support/TypeTraits.h @@ -26,8 +26,17 @@ #include +#if __has_include() // For C++23 and later, include if available +#include // Contains std::to_underlying +#endif + namespace chip { +#if __cplusplus >= 202300L + +using to_underlying = std::to_underlying; + +#else /** * @brief Implemented std::to_underlying introduced in C++23. */ @@ -37,6 +46,7 @@ constexpr std::underlying_type_t to_underlying(T e) static_assert(std::is_enum::value, "to_underlying called to non-enum values."); return static_cast>(e); } +#endif /** * @brief This template is not designed to be used directly. A common pattern to check the presence of a member of a class is: diff --git a/src/platform/Tizen/SystemInfo.cpp b/src/platform/Tizen/SystemInfo.cpp index e9ac7d7b1b1675..dd4f9f83ec8d0a 100644 --- a/src/platform/Tizen/SystemInfo.cpp +++ b/src/platform/Tizen/SystemInfo.cpp @@ -26,8 +26,6 @@ #include "ErrorUtils.h" -using namespace std; - namespace chip { namespace DeviceLayer { namespace Internal { diff --git a/src/platform/stm32/CHIPMem-Platform.cpp b/src/platform/stm32/CHIPMem-Platform.cpp index b9bf90f429f444..cbf52cfde94a84 100644 --- a/src/platform/stm32/CHIPMem-Platform.cpp +++ b/src/platform/stm32/CHIPMem-Platform.cpp @@ -67,8 +67,6 @@ extern "C" void memMonitoringTrackFree(void * ptr, size_t size); #define USE_FREERTOS -using namespace std; - // Define the new operator for C++ to use the freeRTOS memory management // functions. // diff --git a/src/setup_payload/tests/TestQRCode.cpp b/src/setup_payload/tests/TestQRCode.cpp index e5d68227c2956e..ce5048489113e6 100644 --- a/src/setup_payload/tests/TestQRCode.cpp +++ b/src/setup_payload/tests/TestQRCode.cpp @@ -32,7 +32,6 @@ #include using namespace chip; -using namespace std; namespace { @@ -121,7 +120,7 @@ TEST(TestQRCode, TestPayloadByteArrayRep) { SetupPayload payload = GetDefaultPayload(); - string expected = " 0000 000000000000000100000000000 000010000000 00000001 00 0000000000000001 0000000000001100 000"; + std::string expected = " 0000 000000000000000100000000000 000010000000 00000001 00 0000000000000001 0000000000001100 000"; EXPECT_TRUE(CompareBinary(payload, expected)); } @@ -130,7 +129,7 @@ TEST(TestQRCode, TestPayloadBase38Rep) SetupPayload payload = GetDefaultPayload(); QRCodeSetupPayloadGenerator generator(payload); - string result; + std::string result; CHIP_ERROR err = generator.payloadBase38Representation(result); bool didSucceed = err == CHIP_NO_ERROR; EXPECT_EQ(didSucceed, true); @@ -241,10 +240,10 @@ TEST(TestQRCode, TestBase38) base38Encode(ByteSpan((uint8_t *) "Hello World!", sizeof("Hello World!") - 1), encodedSpan); EXPECT_STREQ(encodedBuf, "KKHF3W2S013OPM3EJX11"); - vector decoded = vector(); + std::vector decoded = std::vector(); EXPECT_EQ(base38Decode("KKHF3W2S013OPM3EJX11", decoded), CHIP_NO_ERROR); - string hello_world; + std::string hello_world; for (uint8_t b : decoded) { hello_world += static_cast(b); @@ -347,8 +346,8 @@ TEST(TestQRCode, TestSetupPayloadVerify) TEST(TestQRCode, TestInvalidQRCodePayload_WrongCharacterSet) { - string invalidString = kDefaultPayloadQRCode; - invalidString.back() = ' '; // space is not contained in the base38 alphabet + std::string invalidString = kDefaultPayloadQRCode; + invalidString.back() = ' '; // space is not contained in the base38 alphabet QRCodeSetupPayloadParser parser = QRCodeSetupPayloadParser(invalidString); SetupPayload payload; @@ -360,7 +359,7 @@ TEST(TestQRCode, TestInvalidQRCodePayload_WrongCharacterSet) TEST(TestQRCode, TestInvalidQRCodePayload_WrongLength) { - string invalidString = kDefaultPayloadQRCode; + std::string invalidString = kDefaultPayloadQRCode; invalidString.pop_back(); QRCodeSetupPayloadParser parser = QRCodeSetupPayloadParser(invalidString); @@ -395,7 +394,7 @@ TEST(TestQRCode, TestQRCodeToPayloadGeneration) SetupPayload payload = GetDefaultPayload(); QRCodeSetupPayloadGenerator generator(payload); - string base38Rep; + std::string base38Rep; CHIP_ERROR err = generator.payloadBase38Representation(base38Rep); bool didSucceed = err == CHIP_NO_ERROR; EXPECT_EQ(didSucceed, true); @@ -422,7 +421,7 @@ TEST(TestQRCode, TestGenerateWithShortDiscriminatorInvalid) EXPECT_FALSE(payload.isValidQRCodePayload()); // QRCodeSetupPayloadGenerator should therefore return an error - string base38Rep; + std::string base38Rep; QRCodeSetupPayloadGenerator generator(payload); EXPECT_EQ(generator.payloadBase38Representation(base38Rep), CHIP_ERROR_INVALID_ARGUMENT); @@ -441,7 +440,7 @@ TEST(TestQRCode, TestGenerateWithoutRendezvousInformation) EXPECT_FALSE(payload.isValidQRCodePayload()); // QRCodeSetupPayloadGenerator should therefore return an error - string base38Rep; + std::string base38Rep; QRCodeSetupPayloadGenerator generator(payload); EXPECT_EQ(generator.payloadBase38Representation(base38Rep), CHIP_ERROR_INVALID_ARGUMENT); @@ -452,23 +451,23 @@ TEST(TestQRCode, TestGenerateWithoutRendezvousInformation) TEST(TestQRCode, TestExtractPayload) { - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("H:")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("ASMT:")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC%")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%DDD")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%DDD")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:%")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("A%")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:%")), string("")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:ABC")), string("ABC")); - EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("ABC")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("MT:ABC")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("MT:")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("H:")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("ASMT:")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("Z%MT:ABC%")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("Z%MT:ABC")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%Z%MT:ABC")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%Z%MT:ABC%")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%Z%MT:ABC%DDD")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("MT:ABC%DDD")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("MT:ABC%")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%MT:")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%MT:%")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("A%")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("MT:%")), std::string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("%MT:ABC")), std::string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(std::string("ABC")), std::string("")); } } // namespace diff --git a/src/setup_payload/tests/TestQRCodeTLV.cpp b/src/setup_payload/tests/TestQRCodeTLV.cpp index 7ea2b974070275..3cada5cb505264 100644 --- a/src/setup_payload/tests/TestQRCodeTLV.cpp +++ b/src/setup_payload/tests/TestQRCodeTLV.cpp @@ -24,7 +24,6 @@ #include using namespace chip; -using namespace std; namespace { @@ -38,7 +37,7 @@ class TestQRCodeTLV : public ::testing::Test TEST_F(TestQRCodeTLV, TestOptionalDataAddRemove) { SetupPayload payload = GetDefaultPayload(); - vector optionalData; + std::vector optionalData; CHIP_ERROR err; optionalData = payload.getAllOptionalVendorData(); @@ -86,11 +85,11 @@ TEST_F(TestQRCodeTLV, TestSimpleWrite) SetupPayload inPayload = GetDefaultPayload(); QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; CHIP_ERROR err = generator.payloadBase38Representation(result); EXPECT_EQ(err, CHIP_NO_ERROR); - string result2; + std::string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); EXPECT_EQ(err, CHIP_NO_ERROR); @@ -103,7 +102,7 @@ TEST_F(TestQRCodeTLV, TestSimpleRead) SetupPayload outPayload; QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; CHIP_ERROR err = generator.payloadBase38Representation(result); EXPECT_EQ(err, CHIP_NO_ERROR); @@ -139,7 +138,7 @@ TEST_F(TestQRCodeTLV, TestSerialNumberAddRemove) { SetupPayload inPayload = GetDefaultPayload(); - string sn; + std::string sn; EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_ERROR_KEY_NOT_FOUND); EXPECT_EQ(inPayload.removeSerialNumber(), CHIP_ERROR_KEY_NOT_FOUND); @@ -149,7 +148,7 @@ TEST_F(TestQRCodeTLV, TestSerialNumberAddRemove) EXPECT_EQ(inPayload.addSerialNumber(kSerialNumberDefaultUInt32Value), CHIP_NO_ERROR); EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_NO_ERROR); - EXPECT_EQ(sn, to_string(kSerialNumberDefaultUInt32Value)); + EXPECT_EQ(sn, std::to_string(kSerialNumberDefaultUInt32Value)); EXPECT_EQ(inPayload.removeSerialNumber(), CHIP_NO_ERROR); EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_ERROR_KEY_NOT_FOUND); @@ -164,7 +163,7 @@ TEST_F(TestQRCodeTLV, TestOptionalDataWriteSerial) EXPECT_EQ(err, CHIP_NO_ERROR); QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; err = generator.payloadBase38Representation(result); EXPECT_NE(err, CHIP_NO_ERROR); @@ -172,7 +171,7 @@ TEST_F(TestQRCodeTLV, TestOptionalDataWriteSerial) err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); EXPECT_EQ(err, CHIP_NO_ERROR); - string result2; + std::string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); EXPECT_EQ(err, CHIP_NO_ERROR); @@ -184,12 +183,12 @@ TEST_F(TestQRCodeTLV, TestOptionalDataWrite) SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; uint8_t optionalInfo[kDefaultBufferSizeInBytes]; CHIP_ERROR err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); EXPECT_EQ(err, CHIP_NO_ERROR); - string result2; + std::string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); EXPECT_EQ(err, CHIP_NO_ERROR); @@ -235,7 +234,7 @@ TEST_F(TestQRCodeTLV, TestOptionalDataWriteNoBuffer) SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; CHIP_ERROR err = generator.payloadBase38Representation(result); EXPECT_NE(err, CHIP_NO_ERROR); } @@ -245,7 +244,7 @@ TEST_F(TestQRCodeTLV, TestOptionalDataWriteSmallBuffer) SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); QRCodeSetupPayloadGenerator generator(inPayload); - string result; + std::string result; uint8_t optionalInfo[kSmallBufferSizeInBytes]; CHIP_ERROR err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); EXPECT_NE(err, CHIP_NO_ERROR);