#include #include #include #include static FILE* tmp = nullptr; static char buffer[256]; static Json json; void setUp() { tmp = tmpfile(); TEST_ASSERT_NOT_NULL(tmp); json = json_init(tmp, MINIFIED); } void tearDown() { json_free(&json); if (tmp) { fclose(tmp); tmp = nullptr; } } void test_json_add_string() { json_add_string(&json, "string"); fflush(tmp); rewind(tmp); char buffer[256]; auto n = fread(buffer, 1, sizeof(buffer) - 1, tmp); buffer[n] = '\0'; TEST_ASSERT_EQUAL_STRING("\"string\"", buffer); } int main() { UNITY_BEGIN(); { RUN_TEST(test_json_add_string); } return UNITY_END(); }