Flesh out the repository with example and tests
This commit is contained in:
parent
546eaa5d4d
commit
05c45bbc81
8 changed files with 165 additions and 57 deletions
52
tests/json_test.c
Normal file
52
tests/json_test.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unity.h>
|
||||
|
||||
#include <json.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue