Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #403, patches for older system compatibility #404

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions unit-test/cf_codec_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ void Test_CF_CFDP_GetValueEncodedSize(void)
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(16777216), 4);
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT32_MAX), 4);

#ifdef UINT64_C
/*
* This next case uses UINT64_C macro to force promotion so the +1 is done as 64-bit,
* otherwise the UINT32_MAX is a 32-bit value and +1 results in 0.
* otherwise the UINT32_MAX is a 32-bit value and +1 results in 0. Not all systems have
* UINT64_C so these will be skipped in that case.
*/
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT32_MAX + UINT64_C(1)), 5);
#endif
#ifdef UINT64_MAX
UtAssert_UINT32_EQ(CF_CFDP_GetValueEncodedSize(UINT64_MAX), 8);
#endif
}

void Test_CF_EncodeIntegerInSize(void)
Expand Down Expand Up @@ -1305,4 +1310,4 @@ void UtTest_Setup(void)

Add_CF_Encode_tests();
Add_CF_Decode_tests();
}
}
32 changes: 0 additions & 32 deletions unit-test/utilities/cf_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,38 +448,6 @@ int Any_int_Except(int exception)
return random_val;
}

int Any_int_GreaterThan(int floor) /* NOTE: INTMAX_MAX will fail, and is invalid value */
{
int random_val;
bool coin_toss;

if (floor > 0)
{
random_val = (int)(rand() % (INTMAX_MAX - floor - 1)); /* -1 for greater than */

random_val += floor + 1;
}
else
{
coin_toss = rand() % 2;

if (coin_toss == HEADS)
{
random_val = (int)(rand() % (-floor)); /* floor is negative, -floor inverts to positive */
/* 0 to INTMAX_MAX becomes -1 to INTMAX_MIN */
random_val *= -1; /* flip sign */
random_val += -1; /* subtract 1, 0 becomes -1 */
}
else
{
random_val = (int)(rand() % (INTMAX_MAX)); /* floor is negative, random will be positive so any positive (or
zero) will work */
}
}

return random_val;
}

int Any_int_Negative(void)
{
return ((rand() % MAX_INT) * -1) - 1; /* *-1 flips sign, -1 for 0 and MIN_INT */
Expand Down
1 change: 0 additions & 1 deletion unit-test/utilities/cf_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ uint64 Any_uint64_Except(uint64 exception);
unsigned int Any_unsigned_int(void);
int Any_int(void);
int Any_int_Except(int exception);
int Any_int_GreaterThan(int floor);
int Any_int_Negative(void);
int Any_int_Positive(void);
int Any_int_PositiveExcept(int exception);
Expand Down