Skip to content

Commit

Permalink
added EXPECT_ERROR_ID_EQ in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankaa19 authored Dec 4, 2024
1 parent 9921e8f commit d6d1b4c
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions test/function/facility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "test/helper/assert.hpp"
#include <stddef.h>
#include <string.h>
#include <private/error.h>

namespace {

Expand Down Expand Up @@ -61,8 +62,7 @@ namespace {
STUMPLESS_FOREACH_FACILITY( CHECK_FACILITY_ENUM )
}

//Old test
/*

TEST( GetFacilityEnum, LowercaseFacility ) {
int result;

Expand Down Expand Up @@ -112,13 +112,14 @@ namespace {
EXPECT_EQ( result, STUMPLESS_FACILITY_ALERT );
EXPECT_NO_ERROR;
}
*/


TEST( GetFacilityEnum, NoSuchFacility ) {
int result;

result = stumpless_get_facility_enum( "an_invalid_facility" );
EXPECT_EQ( result, -1 );
EXPECT_ERROR_ID_EQ(STUMPLESS_INVALID_FACILITY);
}


Expand All @@ -129,13 +130,15 @@ TEST(GetFacilityString, InvalidFacility) {
// Check that the fallback string is returned
result = stumpless_get_facility_string(invalid_facility);
EXPECT_STREQ(result, "NO_SUCH_FACILITY");
EXPECT_ERROR_ID_EQ(STUMPLESS_INVALID_FACILITY);
}

TEST(GetFacilityEnum, NullFacilityString) {
enum stumpless_facility facility = stumpless_get_facility_enum(NULL);

// Check that the function returns -1 for NULL input
EXPECT_EQ(facility, -1);
EXPECT_EQ(facility, -STUMPLESS_ARGUMENT_EMPTY);
EXPECT_ERROR_ID_EQ(STUMPLESS_ARGUMENT_EMPTY);
}

TEST(GetFacilityEnumFromBuffer, NullFacilityBuffer) {
Expand All @@ -144,6 +147,7 @@ TEST(GetFacilityString, InvalidFacility) {

// Verify the function returns -1 for NULL input
EXPECT_EQ(facility, -1);
EXPECT_ERROR_ID_EQ(STUMPLESS_ARGUMENT_EMPTY);
}

TEST(GetFacilityEnum, InvalidFacilityString) {
Expand All @@ -154,6 +158,7 @@ TEST(GetFacilityString, InvalidFacility) {

// Validate that the function returns -1 for invalid input
EXPECT_EQ(result, -1);
EXPECT_ERROR_ID_EQ(STUMPLESS_INVALID_FACILITY);
}

TEST(GetFacilityEnumFromBuffer, InvalidFacilityBuffer) {
Expand All @@ -164,6 +169,7 @@ TEST(GetFacilityString, InvalidFacility) {

// Validate that the function returns -1 for invalid input
EXPECT_EQ(result, -1);
EXPECT_ERROR_ID_EQ(STUMPLESS_INVALID_FACILITY);
}

TEST(GetFacilityEnumFromBuffer, ValidFacilities) {
Expand Down Expand Up @@ -191,8 +197,25 @@ TEST(GetFacilityString, InvalidFacility) {
for (const auto &test_case : test_cases) {
int result = stumpless_get_facility_enum_from_buffer(
test_case.facility_buffer, strlen(test_case.facility_buffer));
EXPECT_EQ(result, test_case.expected_enum);
EXPECT_EQ(result, test_case.expected_enum
EXPECT_FALSE(stumpless_has_error());
}
}


TEST(GetFacilityEnumFromBuffer, InvalidFacility) {
const char *invalid_facility = "INVALID";

// Call the function with an invalid facility
int result = stumpless_get_facility_enum_from_buffer(
invalid_facility, strlen(invalid_facility));

// Verify the function returns -1 for invalid input
EXPECT_EQ(result, -1);

// Verify the correct error is set
EXPECT_TRUE(stumpless_has_error());
EXPECT_ERROR_ID_EQ(STUMPLESS_INVALID_FACILITY);
}

}

0 comments on commit d6d1b4c

Please sign in to comment.