Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
833 B

#include <string.h>
#include "unity_fixture.h"
TEST_GROUP(sprintf);
static char output[100];
static const char *expected;
// This is run before each test
TEST_SETUP(sprintf) {
memset(output, 0xaa, sizeof(output));
expected = "";
}
// This id run after each test
TEST_TEAR_DOWN(sprintf) {
}
static void expect(const char *s) {
expected = s;
}
static void given(int charsWritten) {
TEST_ASSERT_EQUAL(strlen(expected), charsWritten);
TEST_ASSERT_EQUAL_STRING(expected, &output[1]);
TEST_ASSERT_EQUAL_HEX8(0xaa, output[strlen(expected)+2]);
TEST_ASSERT_EQUAL_HEX8(0xaa, output[0]);
}
TEST(sprintf, NoFormatOperations) {
expect("hey");
given(sprintf(&output[1], "%s", expected));
}
TEST(sprintf, InsertString) {
expect("Hello world\n");
given(sprintf(&output[1], "Hello %s\n", "world"));
}