Gateway C ABI
Loading...
Searching...
No Matches
json_testing.h File Reference

Plugin testing library. This library provides the the implementation of the GCJsonCallbacks to test configuration parsing of a plugin. Without this functionality, the plugin would have to mock every related json function, which would be cumbersome. More...

#include "json.h"

Go to the source code of this file.

Functions

GCJsonCallbacks gcGetJsonCallbacks (const char *json_data)
 Get the JSON callbacks from a JSON string.
 
void gcFreeJsonCallbacks (GCJsonCallbacks)
 Free the JSON callbacks.
 

Detailed Description

Plugin testing library. This library provides the the implementation of the GCJsonCallbacks to test configuration parsing of a plugin. Without this functionality, the plugin would have to mock every related json function, which would be cumbersome.

Installing the library

Each plugin is responsible for building and linking the testing library (which is implemented in Rust).

Building

# The binary will be placed at ./target/debug/libgc_testing_clib.so
cargo build --package gc_testing_clib --target-dir ./target

Copy/linking the include files

Linking the include files is highly recommended in order to keep it updated to the latest version. The include files are located in the include directory.

Linking the library

# Assumes that the library is built in the "target/debug" directory and the include files are in the "include"
directory gcc *.c -Iinclude -Ltarget/debug -lgc_testing_clib -o target/test.out

Usage

The library provides the following functions:

The return value of gcGetJsonCallbacks can be used to create the GCPluginInterface.

GCJsonCallbacks createInterfaceMock(const char* json_data, GCPluginInterface interface){
GCJsonCallbacks* json_callbacks = gcGetJsonCallbacks(json_data);
GCPluginConfig pluginConfig = {
.subscribedDatapointsCount = 0,
.subscribedDatapoints = NULL,
.ownDatapointsCount = 0,
.ownDatapoints = NULL,
.pluginJsonConfig = *json_callbacks;
}
interface->config = pluginConfig; interface->ctx = NULL;
interface->publishDatapointValueCallback = NULL;
interface->logSystemCallback = NULL;
interface->logAuditCallback = NULL;
interface->releaseDatapointValueCallback = NULL;
interface->getLastDatapointValueCallback = NULL;
return json_callbacks;
}
int main(){
GCPluginInterface interface;
GCJsonCallbacks json_callbacks = createInterfaceMock("{\"key\":\"value\"}", interface);
// Use the interface to test configuration parsing
gcFreeJsonCallbacks(json_callbacks);
}
GCJsonCallbacks gcGetJsonCallbacks(const char *json_data)
Get the JSON callbacks from a JSON string.
void gcFreeJsonCallbacks(GCJsonCallbacks)
Free the JSON callbacks.
The JSON configuration data and parsing callbacks.
Definition json.h:65
The plugin interface.
Definition abi.h:359
const GCCoreCtx ctx
Core Context.
Definition abi.h:451
tPublishDatapointValue publishDatapointValueCallback
Callback used to publish datapoint values.
Definition abi.h:368
tReleaseDatapointValue releaseDatapointValueCallback
Callback used to release a datapoint value.
Definition abi.h:397
tAuditLog logAuditCallback
Definition abi.h:387
const GCPluginConfig config
Configuration and related functions.
Definition abi.h:444
tSystemLog logSystemCallback
Definition abi.h:382
tGetLastDatapointValue getLastDatapointValueCallback
Callback used to get the last value of a datapoint.
Definition abi.h:410
Holds the configuration and related functions.
Definition abi.h:328

Function Documentation

◆ gcFreeJsonCallbacks()

void gcFreeJsonCallbacks ( GCJsonCallbacks )

Free the JSON callbacks.

This function will free the JSON callbacks and the data field.

Parameters
callbacksThe JSON callbacks

◆ gcGetJsonCallbacks()

GCJsonCallbacks gcGetJsonCallbacks ( const char * json_data)

Get the JSON callbacks from a JSON string.

This function will copy the JSON string and set it as the data field of the GCJsonCallbacks. The data can then be used by the various JSON callbacks.

Once the data is no longer needed, it should be freed using gcFreeJsonCallbacks.

Parameters
json_dataThe JSON string
Returns
The JSON callbacks