Skip to content

Commit

Permalink
test: NDEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
lee.fordyce committed Jul 3, 2024
1 parent 1171416 commit b398049
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/packager/live_packager_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void lp_removeCustomLogSink();

/// When the return value is not NULL, clients will need to free this memory
char** lp_getErrorMessages(int* num_messages);
void lp_flushMessage();
void lp_freeErrorMessages(char** messages, int num_messages);

#ifdef __cplusplus
Expand Down
5 changes: 0 additions & 5 deletions packager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ target_link_libraries(packager_test

# Disabled by default, otherwise build live packager unit tests if BUILD_LIVE_TEST is on.
if(BUILD_LIVE_TEST AND NOT MSVC)
set(IS_DEBUG_BUILD CMAKE_BUILD_TYPE STREQUAL "Debug")
# Indication to the code that this is a debug build
if (${IS_DEBUG_BUILD})
add_compile_definitions(__DEBUG__)
endif ()
add_executable(live_packager_test
live_packager_test.cc
)
Expand Down
6 changes: 6 additions & 0 deletions packager/live_packager_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ char** lp_getErrorMessages(int* num_messages) {
return out_messages;
}

void lp_flushMessage() {
if (custom_sink) {
custom_sink->Flush();
}
}

void lp_freeErrorMessages(char** messages, int num_messages) {
if (!messages) {
return;
Expand Down
5 changes: 5 additions & 0 deletions packager/live_packager_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ void LogCollectorSink::Send(const absl::LogEntry& entry) {
}
}

void LogCollectorSink::Flush() {
messages_.clear();
}

const std::vector<std::string>& LogCollectorSink::GetMessages() const {
return messages_;
}
Expand All @@ -41,6 +45,7 @@ void InstallCustomLogSink(absl::LogSink& sink) {
}

void RemoveCustomLogSink(absl::LogSink& sink) {
absl::FlushLogSinks();
absl::RemoveLogSink(&sink);
}

Expand Down
2 changes: 2 additions & 0 deletions packager/live_packager_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LogCollectorSink : public absl::LogSink {

virtual void Send(const absl::LogEntry& entry) override;

virtual void Flush() override;

const std::vector<std::string>& GetMessages() const;

private:
Expand Down
8 changes: 7 additions & 1 deletion packager/live_packager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ TEST(LivePackagerLoggingTest, InvalidDecryptKeyID) {
SegmentBuffer out;
ASSERT_NE(Status::OK, live_packager.Package(init_seg, media_seg, out));

#ifdef __DEBUG__
#ifdef NDEBUG
const std::vector<std::string> expected_errors = {
"(ERROR): Error retrieving decryption key: 14 (INTERNAL_ERROR): Key for "
"key_id=00000000621f2afe7ab2c868d5fd2e2e was not found.",
Expand All @@ -1579,12 +1579,18 @@ TEST(LivePackagerLoggingTest, InvalidDecryptKeyID) {

int num_errors = 0;
const auto messages = lp_getErrorMessages(&num_errors);
ASSERT_TRUE(messages);
ASSERT_EQ(expected_errors.size(), num_errors);
for (int i(0); i < num_errors; ++i) {
ASSERT_NE(nullptr, messages[i]);
EXPECT_EQ(expected_errors[i], std::string(messages[i]));
}
lp_freeErrorMessages(messages, num_errors);

lp_flushMessage();
const auto empty_messages = lp_getErrorMessages(&num_errors);
ASSERT_EQ(0, num_errors);
ASSERT_TRUE(!empty_messages);
lp_removeCustomLogSink();
}

Expand Down

0 comments on commit b398049

Please sign in to comment.