本文整理汇总了C++中JsonDestroy函数的典型用法代码示例。如果您正苦于以下问题:C++ JsonDestroy函数的具体用法?C++ JsonDestroy怎么用?C++ JsonDestroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JsonDestroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_merge_array
static void test_merge_array(void)
{
JsonElement *a = JsonArrayCreate(2);
JsonArrayAppendString(a, "a");
JsonArrayAppendString(a, "b");
JsonElement *b = JsonArrayCreate(2);
JsonArrayAppendString(b, "c");
JsonArrayAppendString(b, "d");
JsonElement *c = JsonMerge(a, b);
assert_int_equal(2, JsonLength(a));
assert_int_equal(2, JsonLength(b));
assert_int_equal(4, JsonLength(c));
assert_string_equal("a", JsonArrayGetAsString(c, 0));
assert_string_equal("b", JsonArrayGetAsString(c, 1));
assert_string_equal("c", JsonArrayGetAsString(c, 2));
assert_string_equal("d", JsonArrayGetAsString(c, 3));
JsonDestroy(a);
JsonDestroy(b);
JsonDestroy(c);
}
示例2: test_copy_compare
static void test_copy_compare(void)
{
JsonElement *bench = LoadTestFile("benchmark.json");
assert_true(bench != NULL);
JsonElement *copy = JsonCopy(bench);
assert_true(copy != NULL);
assert_int_equal(0, JsonCompare(copy, bench));
JsonDestroy(bench);
JsonDestroy(copy);
}
示例3: test_parse_escaped_string
static void test_parse_escaped_string(void)
{
{
const char *data = "\"\\\\\"";
const char *original = data;
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_string_equal("\\", JsonPrimitiveGetAsString(json));
char *out = JsonToString(json);
assert_string_equal(original, out);
free(out);
JsonDestroy(json);
}
{
// included by paranoia from Redmine #5773
const char *data = "\"/\\\\//\\\\/\\\\\"";
const char *original = data;
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_string_equal("/\\//\\/\\", JsonPrimitiveGetAsString(json));
char *out = JsonToString(json);
assert_string_equal(original, out);
free(out);
JsonDestroy(json);
}
{
const char *data = "\"x\\tx\"";
const char *original = data;
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_string_equal("x\tx", JsonPrimitiveGetAsString(json));
char *out = JsonToString(json);
assert_string_equal(original, out);
free(out);
JsonDestroy(json);
}
}
示例4: RvalDestroy
void RvalDestroy(Rval rval)
{
if (rval.item == NULL)
{
return;
}
switch (rval.type)
{
case RVAL_TYPE_SCALAR:
ThreadLock(cft_lock);
free(RvalScalarValue(rval));
ThreadUnlock(cft_lock);
return;
case RVAL_TYPE_LIST:
RlistDestroy(RvalRlistValue(rval));
return;
case RVAL_TYPE_FNCALL:
FnCallDestroy(RvalFnCallValue(rval));
break;
case RVAL_TYPE_CONTAINER:
JsonDestroy(RvalContainerValue(rval));
break;
case RVAL_TYPE_NOPROMISEE:
return;
}
}
示例5: test_detach_key_from_object
static void test_detach_key_from_object(void)
{
JsonElement *object = JsonObjectCreate(3);
JsonObjectAppendInteger(object, "one", 1);
JsonObjectAppendInteger(object, "two", 2);
JsonObjectAppendInteger(object, "three", 3);
JsonElement *detached = JsonObjectDetachKey(object, "two");
assert_int_equal(2, JsonLength(object));
JsonDestroy(object);
assert_int_equal(1, JsonLength(detached));
JsonDestroy(detached);
}
示例6: test_show_object_compound_compact
static void test_show_object_compound_compact(void)
{
JsonElement *json = JsonObjectCreate(10);
JsonObjectAppendString(json, "first", "one");
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "third", "three");
JsonObjectAppendObject(json, "second", inner);
}
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "fifth", "five");
JsonObjectAppendObject(json, "fourth", inner);
}
Writer *writer = StringWriter();
JsonWriteCompact(writer, json);
char *output = StringWriterClose(writer);
assert_string_equal("{\"first\":\"one\",\"second\":{\"third\":\"three\"},\"fourth\":{\"fifth\":\"five\"}}", output);
JsonDestroy(json);
free(output);
}
示例7: test_new_delete
static void test_new_delete(void)
{
JsonElement *json = JsonObjectCreate(10);
JsonObjectAppendString(json, "first", "one");
JsonDestroy(json);
}
示例8: WritePolicyValidatedFile
/**
* @brief Writes a file with a contained timestamp to mark a policy file as validated
* @param filename the filename
* @return True if successful.
*/
static bool WritePolicyValidatedFile(ARG_UNUSED const GenericAgentConfig *config, const char *filename)
{
if (!MakeParentDirectory(filename, true))
{
Log(LOG_LEVEL_ERR, "While writing policy validated marker file '%s', could not create directory (MakeParentDirectory: %s)", filename, GetErrorStr());
return false;
}
int fd = creat(filename, 0600);
if (fd == -1)
{
Log(LOG_LEVEL_ERR, "While writing policy validated marker file '%s', could not create file (creat: %s)", filename, GetErrorStr());
return false;
}
JsonElement *info = JsonObjectCreate(3);
JsonObjectAppendInteger(info, "timestamp", time(NULL));
Writer *w = FileWriter(fdopen(fd, "w"));
JsonWrite(w, info, 0);
WriterClose(w);
JsonDestroy(info);
Log(LOG_LEVEL_VERBOSE, "Saved policy validated marker file '%s'", filename);
return true;
}
示例9: test_show_object_compound
static void test_show_object_compound(void)
{
JsonElement *json = JsonObjectCreate(10);
JsonObjectAppendString(json, "first", "one");
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "third", "three");
JsonObjectAppendObject(json, "second", inner);
}
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "fifth", "five");
JsonObjectAppendObject(json, "fourth", inner);
}
Writer *writer = StringWriter();
JsonWrite(writer, json, 0);
char *output = StringWriterClose(writer);
assert_string_equal(OBJECT_COMPOUND, output);
JsonDestroy(json);
free(output);
}
示例10: WriteReleaseIdFile
/**
* @brief Writes a file with a contained release ID based on git SHA,
* or file checksum if git SHA is not available.
* @param filename the release_id file
* @param dirname the directory to checksum or get the Git hash
* @return True if successful
*/
static bool WriteReleaseIdFile(const char *filename, const char *dirname)
{
char release_id[GENERIC_AGENT_CHECKSUM_SIZE];
bool have_release_id =
GeneratePolicyReleaseID(release_id, sizeof(release_id), dirname);
if (!have_release_id)
{
return false;
}
int fd = creat(filename, 0600);
if (fd == -1)
{
Log(LOG_LEVEL_ERR, "While writing policy release ID file '%s', could not create file (creat: %s)", filename, GetErrorStr());
return false;
}
JsonElement *info = JsonObjectCreate(3);
JsonObjectAppendString(info, "releaseId", release_id);
Writer *w = FileWriter(fdopen(fd, "w"));
JsonWrite(w, info, 0);
WriterClose(w);
JsonDestroy(info);
Log(LOG_LEVEL_VERBOSE, "Saved policy release ID file '%s'", filename);
return true;
}
示例11: test_parse_array_diverse
static void test_parse_array_diverse(void)
{
{
const char *data = "[1, \"snookie\", 1.0, {}, [], true, false, null ]";
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_true(json);
JsonDestroy(json);
}
{
const char *data = "[1,\"snookie\",1.0,{},[],true,false,null]";
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_true(json);
JsonDestroy(json);
}
}
示例12: test_parse_object_diverse
static void test_parse_object_diverse(void)
{
{
const char *data = "{ \"a\": 1, \"b\": \"snookie\", \"c\": 1.0, \"d\": {}, \"e\": [], \"f\": true, \"g\": false, \"h\": null }";
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_true(json);
JsonDestroy(json);
}
{
const char *data = "{\"a\":1,\"b\":\"snookie\",\"c\":1.0,\"d\":{},\"e\":[],\"f\":true,\"g\":false,\"h\":null}";
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_true(json);
JsonDestroy(json);
}
}
示例13: test_parse_array_extra_closing
static void test_parse_array_extra_closing(void)
{
const char *data = " []]";
JsonElement *json = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &json));
assert_true(json);
JsonDestroy(json);
}
示例14: test_parse_tzz_evil_key
static void test_parse_tzz_evil_key(void)
{
const char *data = "{ \"third key! can? be$ anything&\": [ \"a\", \"b\", \"c\" ]}";
JsonElement *obj = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &obj));
assert_string_equal("b", JsonArrayGetAsString(JsonObjectGetAsArray(obj, "third key! can? be$ anything&"), 1));
JsonDestroy(obj);
}
示例15: test_parse_array_simple
static void test_parse_array_simple(void)
{
const char *data = ARRAY_SIMPLE;
JsonElement *arr = NULL;
assert_int_equal(JSON_PARSE_OK, JsonParse(&data, &arr));
assert_string_equal(JsonArrayGetAsString(arr, 1), "two");
assert_string_equal(JsonArrayGetAsString(arr, 0), "one");
JsonDestroy(arr);
}