Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.
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
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ REMOVED - A function/class has been removed.
Forthcoming
-----------
### New Features
* Added MicrostrainTest test wrapper framework
### Interface Changes
### Bug Fixes

Expand Down
15 changes: 11 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
# Dependencies
# ---------------------------------------------------------------

set(MICROSTRAIN_TEST_USE_UNITY ON CACHE BOOL "" FORCE)
set(MICROSTRAIN_TEST_USE_DOCTEST ON CACHE BOOL "" FORCE)
# TODO: Will be moved to separate repo
add_subdirectory("microstrain_test")
include(FetchContent)

set(MICROSTRAIN_TEST_FRAMEWORK_C "unity" CACHE STRING "" FORCE)
set(MICROSTRAIN_TEST_FRAMEWORK_CPP "doctest" CACHE STRING "" FORCE)

FetchContent_Declare(microstrain_test
GIT_REPOSITORY https://github.com/LORD-MicroStrain/microstrain_test.git
GIT_TAG v0.2.7
)

FetchContent_MakeAvailable(microstrain_test)

# ---------------------------------------------------------------
# Target templates
Expand Down
172 changes: 86 additions & 86 deletions test/c/microstrain/strings.unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatentation, A_zero_terminated_string_can_be_c

const bool ok = microstrain_string_concat(buffer, sizeof(buffer), &index, string, string_length);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, string_length);
TEST_ASSERT_EQUAL_CHAR(buffer[5], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "12345\0____");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, string_length);
ASSERT_EQUAL_CHAR(buffer[5], '\0');
ASSERT_EQUAL_STRING(buffer, "12345\0____");
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_an_empty_buffer_fails_gracefully_if_buffer_too_small)
Expand All @@ -31,10 +31,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_an_empty_b

const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, string, string_length);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, string_length);
TEST_ASSERT_EQUAL_CHAR(buffer[3], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "123\0______");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, string_length);
ASSERT_EQUAL_CHAR(buffer[3], '\0');
ASSERT_EQUAL_STRING(buffer, "123\0______");
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_computes_required_buffer_size_when_buffer_is_null)
Expand All @@ -45,8 +45,8 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_computes_requ

const bool ok = microstrain_string_concat(NULL, 0, &index, string, string_length);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, string_length);
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, string_length);
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, A_zero_terminated_string_can_be_concatenated_to_a_non_empty_buffer)
Expand All @@ -58,10 +58,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, A_zero_terminated_string_can_be_co

const bool ok = microstrain_string_concat(buffer, sizeof(buffer), &index, "6789", 4);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 9);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "123456789\0");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 9);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "123456789\0");
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empty_buffer_fails_gracefully_if_buffer_too_small)
Expand All @@ -73,10 +73,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empt

const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, "89ABCDEF", 8);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 16);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "012345678\0##########"); // TODO: I don't think characters after the null terminator are compared.
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 16);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "012345678\0##########"); // TODO: I don't think characters after the null terminator are compared.
// Should they be?

}
Expand All @@ -92,10 +92,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, String_concatenation_to_a_non_empt

const bool ok = microstrain_string_concat(buffer, fake_buffer_size, &index, msg, msg_size);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 18);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "012345678\0__________");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 18);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "012345678\0__________");
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_work)
Expand All @@ -112,10 +112,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_wor
ok &= microstrain_string_concat_l(buffer, sizeof(buffer), &index, "long ");
ok &= microstrain_string_concat_l(buffer, sizeof(buffer), &index, "test...");

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 27);
TEST_ASSERT_EQUAL_CHAR(buffer[27], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "This is a very long test...");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 27);
ASSERT_EQUAL_CHAR(buffer[27], '\0');
ASSERT_EQUAL_STRING(buffer, "This is a very long test...");
}

MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_fail_gracefully_when_buffer_too_small)
Expand All @@ -133,10 +133,10 @@ MICROSTRAIN_TEST_CASE(C_string_concatenation, Multiple_string_concatenations_fai
ok &= microstrain_string_concat_l(buffer, fake_buffer_size, &index, "long ");
ok &= microstrain_string_concat_l(buffer, fake_buffer_size, &index, "test...");

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 27);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "This is a");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 27);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "This is a");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written_to_an_empty_buffer)
Expand All @@ -147,10 +147,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written

const bool ok = microstrain_string_format(buffer, sizeof(buffer), &index, "%d==0x%x", 4096, 0x1000);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 4+2+2+4);
TEST_ASSERT_EQUAL_CHAR(buffer[12], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "4096==0x1000\0_______");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 4+2+2+4);
ASSERT_EQUAL_CHAR(buffer[12], '\0');
ASSERT_EQUAL_STRING(buffer, "4096==0x1000\0_______");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_fails_gracefully_when_buffer_is_too_small)
Expand All @@ -161,10 +161,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_fails_gracefully_wh

const bool ok = microstrain_string_format(buffer, 10, &index, "%d==0x%x", 4096, 0x1000);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 4+2+2+4);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "4096==0x1\0__________");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 4+2+2+4);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "4096==0x1\0__________");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_calculates_required_buffer_size_if_buffer_is_null)
Expand All @@ -173,8 +173,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_calculates_required

const bool ok = microstrain_string_format(NULL, 0, &index, "%d==0x%x", 4096, 0x1000);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 4+2+2+4);
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 4+2+2+4);
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written_to_a_non_empty_buffer)
Expand All @@ -186,10 +186,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_string_can_be_formatted_and_written

const bool ok = microstrain_string_format(buffer, sizeof(buffer), &index, "%d==0x%x", 4096, 0x1000);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 6+4+2+2+4);
TEST_ASSERT_EQUAL_CHAR(buffer[18], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Test: 4096==0x1000\0_");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 6+4+2+2+4);
ASSERT_EQUAL_CHAR(buffer[18], '\0');
ASSERT_EQUAL_STRING(buffer, "Test: 4096==0x1000\0_");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_to_a_non_empty_buffer_fails_gracefully_if_buffer_too_small)
Expand All @@ -201,10 +201,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, String_formatting_to_a_non_empty_buff

const bool ok = microstrain_string_format(buffer, 10, &index, "%d==0x%x", 4096, 0x1000);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 6+4+2+2+4);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Test: 409\0__________");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 6+4+2+2+4);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "Test: 409\0__________");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_work)
Expand All @@ -220,10 +220,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_work)
ok &= microstrain_string_format(buffer, 50, &index, "C=%s", "abcdefg");
ok &= microstrain_string_format(buffer, 50, &index, "]");

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1);
TEST_ASSERT_EQUAL_CHAR(buffer[38], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xABCD, C=abcdefg]");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1);
ASSERT_EQUAL_CHAR(buffer[38], '\0');
ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xABCD, C=abcdefg]");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_fail_gracefully_when_buffer_too_small)
Expand All @@ -239,10 +239,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Multiple_string_formattings_fail_grac
ok &= microstrain_string_format(buffer, 25, &index, "C=%s", "abcdefg");
ok &= microstrain_string_format(buffer, 25, &index, "]");

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1);
TEST_ASSERT_EQUAL_CHAR(buffer[24], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xAB");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 9+2+5+2+4+4+2+2+7+1);
ASSERT_EQUAL_CHAR(buffer[24], '\0');
ASSERT_EQUAL_STRING(buffer, "Values: [A=54321, B=0xAB");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_and_written_to_a_string_buffer)
Expand All @@ -254,10 +254,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 0);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 2+2+2+2);
TEST_ASSERT_EQUAL_CHAR(buffer[8], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "A1B2C3D4");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 2+2+2+2);
ASSERT_EQUAL_CHAR(buffer[8], '\0');
ASSERT_EQUAL_STRING(buffer, "A1B2C3D4");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group1_and_written_to_a_string_buffer)
Expand All @@ -269,10 +269,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 1);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 2+1+2+1+2+1+2);
TEST_ASSERT_EQUAL_CHAR(buffer[11], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "A1 B2 C3 D4");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 2+1+2+1+2+1+2);
ASSERT_EQUAL_CHAR(buffer[11], '\0');
ASSERT_EQUAL_STRING(buffer, "A1 B2 C3 D4");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group2_and_written_to_a_string_buffer)
Expand All @@ -284,10 +284,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 2);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 2+2+1+2+2);
TEST_ASSERT_EQUAL_CHAR(buffer[9], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 2+2+1+2+2);
ASSERT_EQUAL_CHAR(buffer[9], '\0');
ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_partial_group2_and_written_to_a_string_buffer)
Expand All @@ -299,10 +299,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 2);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 2+2+1+2+2+1+2);
TEST_ASSERT_EQUAL_CHAR(buffer[12], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4 E5");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 2+2+1+2+2+1+2);
ASSERT_EQUAL_CHAR(buffer[12], '\0');
ASSERT_EQUAL_STRING(buffer, "A1B2 C3D4 E5");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_with_group4_and_written_to_a_string_buffer)
Expand All @@ -314,10 +314,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 4);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 2+2+2+2+1+2+2+2+2);
TEST_ASSERT_EQUAL_CHAR(buffer[17], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "A8B9CEDF 01234567");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 2+2+2+2+1+2+2+2+2);
ASSERT_EQUAL_CHAR(buffer[17], '\0');
ASSERT_EQUAL_STRING(buffer, "A8B9CEDF 01234567");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_handles_no_data_properly)
Expand All @@ -328,8 +328,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_handles_no_data_prope

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 10, &index, NULL, 0, 0);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 0);
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 0);
}

MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadecimal_and_written_to_a_non_empty_string_buffer)
Expand All @@ -342,10 +342,10 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, A_byte_array_can_formatted_as_hexadec

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 25, &index, data, sizeof(data), 0);

TEST_ASSERT_TRUE(ok);
TEST_ASSERT_EQUAL_INT(index, 6+2+2+2+2);
TEST_ASSERT_EQUAL_CHAR(buffer[14], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Data: A1B2C3D4");
ASSERT_TRUE(ok);
ASSERT_EQUAL_INT(index, 6+2+2+2+2);
ASSERT_EQUAL_CHAR(buffer[14], '\0');
ASSERT_EQUAL_STRING(buffer, "Data: A1B2C3D4");
}

MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_fails_gracefully_when_buffer_too_small)
Expand All @@ -358,8 +358,8 @@ MICROSTRAIN_TEST_CASE(C_string_formatting, Byte_formatting_fails_gracefully_when

const bool ok = microstrain_string_bytes_to_hex_str(buffer, 10, &index, data, sizeof(data), 0);

TEST_ASSERT_FALSE(ok);
TEST_ASSERT_EQUAL_INT(index, 6+2+2+2+2);
TEST_ASSERT_EQUAL_CHAR(buffer[6], '\0');
TEST_ASSERT_EQUAL_STRING(buffer, "Data: ");
ASSERT_FALSE(ok);
ASSERT_EQUAL_INT(index, 6+2+2+2+2);
ASSERT_EQUAL_CHAR(buffer[6], '\0');
ASSERT_EQUAL_STRING(buffer, "Data: ");
}
Loading