|
Packit Service |
def718 |
/*
|
|
Packit Service |
def718 |
* gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
|
|
Packit Bot |
f5502f |
#include "config.h"
|
|
Packit Bot |
f5502f |
#include <assert.h>
|
|
Packit Service |
def718 |
#include <stdio.h>
|
|
Packit Bot |
f5502f |
#include <stdlib.h>
|
|
Packit Service |
def718 |
#include <string.h>
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#include "json_inttypes.h"
|
|
Packit Service |
def718 |
#include "json_object.h"
|
|
Packit Service |
def718 |
#include "json_tokener.h"
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
void print_hex(const char* s)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
const char *iter = s;
|
|
Packit Service |
def718 |
unsigned char ch;
|
|
Packit Service |
def718 |
while ((ch = *iter++) != 0)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
if( ',' != ch)
|
|
Packit Service |
def718 |
printf("%x ", ch);
|
|
Packit Service |
def718 |
else
|
|
Packit Service |
def718 |
printf( ",");
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
putchar('\n');
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
|
|
Packit Bot |
f5502f |
static void test_lot_of_adds(void);
|
|
Packit Bot |
f5502f |
static void test_lot_of_adds()
|
|
Packit Bot |
f5502f |
{
|
|
Packit Bot |
f5502f |
int ii;
|
|
Packit Bot |
f5502f |
char key[50];
|
|
Packit Bot |
f5502f |
json_object *jobj = json_object_new_object();
|
|
Packit Bot |
f5502f |
assert(jobj != NULL);
|
|
Packit Bot |
f5502f |
for (ii = 0; ii < 500; ii++)
|
|
Packit Bot |
f5502f |
{
|
|
Packit Bot |
f5502f |
snprintf(key, sizeof(key), "k%d", ii);
|
|
Packit Bot |
f5502f |
json_object *iobj = json_object_new_int(ii);
|
|
Packit Bot |
f5502f |
assert(iobj != NULL);
|
|
Packit Bot |
f5502f |
if (json_object_object_add(jobj, key, iobj))
|
|
Packit Bot |
f5502f |
{
|
|
Packit Bot |
f5502f |
fprintf(stderr, "FAILED to add object #%d\n", ii);
|
|
Packit Bot |
f5502f |
abort();
|
|
Packit Bot |
f5502f |
}
|
|
Packit Bot |
f5502f |
}
|
|
Packit Bot |
f5502f |
printf("%s\n", json_object_to_json_string(jobj));
|
|
Packit Bot |
f5502f |
assert(json_object_object_length(jobj) == 500);
|
|
Packit Bot |
f5502f |
json_object_put(jobj);
|
|
Packit Bot |
f5502f |
}
|
|
Packit Bot |
f5502f |
|
|
Packit Service |
def718 |
int main(void)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
|
|
Packit Service |
def718 |
const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
|
|
Packit Service |
def718 |
struct json_object *parse_result = json_tokener_parse(input);
|
|
Packit Service |
def718 |
const char *unjson = json_object_get_string(parse_result);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
printf("input: %s\n", input);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
int strings_match = !strcmp( expected, unjson);
|
|
Packit Service |
def718 |
int retval = 0;
|
|
Packit Service |
def718 |
if (strings_match)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
printf("JSON parse result is correct: %s\n", unjson);
|
|
Packit Service |
def718 |
puts("PASS");
|
|
Packit Service |
def718 |
} else {
|
|
Packit Service |
def718 |
printf("JSON parse result doesn't match expected string\n");
|
|
Packit Service |
def718 |
printf("expected string bytes: ");
|
|
Packit Service |
def718 |
print_hex(expected);
|
|
Packit Service |
def718 |
printf("parsed string bytes: ");
|
|
Packit Service |
def718 |
print_hex(unjson);
|
|
Packit Service |
def718 |
puts("FAIL");
|
|
Packit Service |
def718 |
retval = 1;
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
json_object_put(parse_result);
|
|
Packit Bot |
f5502f |
|
|
Packit Bot |
f5502f |
test_lot_of_adds();
|
|
Packit Bot |
f5502f |
|
|
Packit Service |
def718 |
return retval;
|
|
Packit Service |
def718 |
}
|