mirror of
https://github.com/Wessel/c-websocket-server.git
synced 2026-07-18 14:34:19 +02:00
feat: Populate repo
This commit is contained in:
19
tests/json.test.c
Normal file
19
tests/json.test.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* Libtap for tests */
|
||||
#include "../include/libtap.h"
|
||||
|
||||
#include "../include/json.h"
|
||||
#include "../include/macros.h"
|
||||
|
||||
void run_json_tests(int argc, char* argv[], char* env[]) {
|
||||
/* Unit test for parsing JSON object*/
|
||||
printf("\033[0;35m--Tests for parsing JSON object--\033[0;0m\n");
|
||||
|
||||
char* json_string = "{ \"auth\": 1, \"payload\": { \"sensorId\": \"LDR_1\", \"sensorData\": \"55\" } }";
|
||||
Envelope envelope;
|
||||
int status_code = parse_envelope_json(json_string, &envelope);
|
||||
dbg("status_code(%d)\nEnvelope { auth: %s, payload: Message { sensorId: %s, sensorData: %s } }\n", status_code, envelope.auth, envelope.payload.sensorId, envelope.payload.sensorData);
|
||||
|
||||
ok(status_code == 0, "`parse_envelope_json` returned `json_string` casted as `Envelope`.");
|
||||
like(envelope.payload.sensorId, "LDR_1", "`envelope.payload.sensorId is the same as `json_string` (`LDR_1`)");
|
||||
like(envelope.payload.sensorData, "55", "`envelope.payload.sensorData is the same as `json_string` (`55`)");
|
||||
}
|
||||
Reference in New Issue
Block a user