Skip to content

Commit

Permalink
use int32max
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Jun 18, 2024
1 parent a7c3253 commit 318b630
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" { // only need to export C interface if
Expand All @@ -23,8 +24,8 @@ enum LDLogLevel {
LD_LOG_INFO = 1,
LD_LOG_WARN = 2,
LD_LOG_ERROR = 3,
LD_LOG_MAXVAL = 0x7FFFFFFF /* This is not a valid log level, it is used to
* ensure the enum is at least 32 bits. */
LD_UNUSED_MAXVALUE = INT32_MAX /* Used to ensure the underlying type is
* at least 32 bits. */
};

/**
Expand Down
4 changes: 2 additions & 2 deletions libs/common/tests/logging_c_binding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ TEST(LogLevelTests, LogLevelToString) {
ASSERT_STREQ("info", LDLogLevel_Name(LD_LOG_INFO, "unknown"));
ASSERT_STREQ("warn", LDLogLevel_Name(LD_LOG_WARN, "unknown"));
ASSERT_STREQ("error", LDLogLevel_Name(LD_LOG_ERROR, "unknown"));
ASSERT_STREQ("unknown", LDLogLevel_Name(LD_LOG_MAXVAL, "unknown"));
ASSERT_STREQ("unknown", LDLogLevel_Name(LD_UNUSED_MAXVALUE, "unknown"));
}

TEST(LogLevelTests, LogLevelToEnum) {
constexpr auto unknown = LD_LOG_MAXVAL;
LDLogLevel unknown = LD_UNUSED_MAXVALUE;
ASSERT_EQ(LD_LOG_DEBUG, LDLogLevel_Enum("debug", unknown));
ASSERT_EQ(LD_LOG_INFO, LDLogLevel_Enum("info", unknown));
ASSERT_EQ(LD_LOG_WARN, LDLogLevel_Enum("warn", unknown));
Expand Down

0 comments on commit 318b630

Please sign in to comment.