-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add std::source_location to ChipError for C++20 builds (#32935)
* Add std::source_location to ChipError for C++20 builds * Fix errors due to CHIP_ERROR default constructor no longer being trivial * Restyled by clang-format * A few more fixes * Replace semicolon with comma * Add enum->int cast * Add tests and simplify constructor * Convert to gtest * Restyled by clang-format * Restyled by gn --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
14 changed files
with
200 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 <string> | ||
|
||
#include <lib/core/CHIPError.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace chip { | ||
namespace { | ||
|
||
TEST(ChipErrorTest, RangeConstructor) | ||
{ | ||
ChipError error(ChipError::Range::kSDK, /*value=*/1, __FILE__, __LINE__); | ||
#if CHIP_CONFIG_ERROR_SOURCE | ||
EXPECT_EQ(error.GetFile(), __FILE__); | ||
EXPECT_EQ(error.GetLine(), 30u); | ||
#if __cplusplus >= 202002L | ||
std::source_location location = error.GetSourceLocation(); | ||
EXPECT_EQ(location.line(), 30u); | ||
EXPECT_EQ(location.file_name(), __FILE__); | ||
#endif // __cplusplus >= 202002L | ||
#endif // CHIP_CONFIG_ERROR_SOURCE | ||
} | ||
|
||
TEST(ChipErrorTest, SdkPartConstructor) | ||
{ | ||
ChipError error(ChipError::SdkPart::kCore, /*code=*/1, __FILE__, __LINE__); | ||
#if CHIP_CONFIG_ERROR_SOURCE | ||
EXPECT_EQ(error.GetFile(), __FILE__); | ||
EXPECT_EQ(error.GetLine(), 44u); | ||
#if __cplusplus >= 202002L | ||
std::source_location location = error.GetSourceLocation(); | ||
EXPECT_EQ(location.line(), 44u); | ||
EXPECT_EQ(location.file_name(), __FILE__); | ||
#endif // __cplusplus >= 202002L | ||
#endif // CHIP_CONFIG_ERROR_SOURCE | ||
} | ||
|
||
TEST(ChipErrorTest, StorageTypeConstructor) | ||
{ | ||
ChipError error(/*error=*/1, __FILE__, __LINE__); | ||
EXPECT_EQ(error.AsInteger(), 1u); | ||
#if CHIP_CONFIG_ERROR_SOURCE | ||
EXPECT_EQ(error.GetFile(), __FILE__); | ||
EXPECT_EQ(error.GetLine(), 58u); | ||
#if __cplusplus >= 202002L | ||
std::source_location location = error.GetSourceLocation(); | ||
EXPECT_EQ(location.line(), 58u); | ||
EXPECT_EQ(location.file_name(), __FILE__); | ||
#endif // __cplusplus >= 202002L | ||
#endif // CHIP_CONFIG_ERROR_SOURCE | ||
} | ||
|
||
} // namespace | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.