forked from google-ai-edge/mediapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an HasError method and a test for ErrorReporter
Using error_reporter.message().empty() is inefficient since that will allocate a std::string. This CL adds a HasError() method that directly tests the underlying buffer. Uses the new method in TfLiteModelLoader. PiperOrigin-RevId: 617797494
- Loading branch information
1 parent
bab2d51
commit 7f8985d
Showing
5 changed files
with
74 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "mediapipe/util/tflite/error_reporter.h" | ||
|
||
#include <string> | ||
|
||
#include "mediapipe/framework/port/gtest.h" | ||
|
||
namespace mediapipe::util::tflite { | ||
namespace { | ||
|
||
TEST(ErrorReporterTest, ReportNoErrors) { | ||
ErrorReporter error_reporter; | ||
EXPECT_FALSE(error_reporter.HasError()); | ||
EXPECT_TRUE(error_reporter.message().empty()); | ||
EXPECT_TRUE(error_reporter.previous_message().empty()); | ||
} | ||
|
||
TEST(ErrorReporterTest, ReportOneError) { | ||
ErrorReporter error_reporter; | ||
error_reporter.Report("error %i", 1); | ||
EXPECT_TRUE(error_reporter.HasError()); | ||
EXPECT_EQ(error_reporter.message(), "error 1"); | ||
EXPECT_TRUE(error_reporter.previous_message().empty()); | ||
} | ||
|
||
TEST(ErrorReporterTest, ReportTwoErrors) { | ||
ErrorReporter error_reporter; | ||
error_reporter.Report("error %i", 1); | ||
error_reporter.Report("error %i", 2); | ||
EXPECT_TRUE(error_reporter.HasError()); | ||
EXPECT_EQ(error_reporter.message(), "error 2"); | ||
EXPECT_EQ(error_reporter.previous_message(), "error 1"); | ||
} | ||
|
||
TEST(ErrorReporterTest, ReportThreeErrors) { | ||
ErrorReporter error_reporter; | ||
error_reporter.Report("error %i", 1); | ||
error_reporter.Report("error %i", 2); | ||
error_reporter.Report("error %i", 3); | ||
EXPECT_TRUE(error_reporter.HasError()); | ||
EXPECT_EQ(error_reporter.message(), "error 3"); | ||
EXPECT_EQ(error_reporter.previous_message(), "error 2"); | ||
} | ||
|
||
TEST(ErrorReporterTest, VeryLongErrorIsTruncated) { | ||
ErrorReporter error_reporter; | ||
std::string long_error; | ||
long_error.resize(ErrorReporter::kBufferSize * 2, 'x'); | ||
error_reporter.Report(long_error.c_str()); | ||
EXPECT_TRUE(error_reporter.HasError()); | ||
EXPECT_EQ(error_reporter.message(), | ||
long_error.substr(0, ErrorReporter::kBufferSize - 1)); | ||
} | ||
|
||
} // namespace | ||
} // namespace mediapipe::util::tflite |
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