first commit

This commit is contained in:
Bronson Graansma
2018-08-07 13:57:09 -04:00
commit 7c4cf8d4d3
22 changed files with 2230 additions and 0 deletions

5
Makefile Normal file
View File

@@ -0,0 +1,5 @@
test:
gcc test.c -Wall -pedantic -std=c11 -g -o libjsontest
clean:
rm -rf libjsontest libjsontest.dSYM testout/got/tests/*

1722
libjson.h Normal file
View File

File diff suppressed because it is too large Load Diff

40
test.c Normal file
View File

@@ -0,0 +1,40 @@
#include "libjson.h"
#include <string.h>
int main(int argc, char** argv) {
char* raw = NULL;
char buf[1024] = {0};
FILE* fp = stdin;
if(argc > 1) {
if(argc > 2) {
printf("Usage: ./libjsontest filename.json\n");
return 1;
}
if(!(fp = fopen(argv[1], "r"))) {
printf("Failed to open %s\n", argv[1]);
return 1;
}
}
while(fgets(buf, 1023, fp)) {
raw = libjson_extendString(raw, strlen(buf));
strcat(raw, buf);
}
if(argc == 2) {
fclose(fp);
}
JSONObject json = o_parseJSONObject(raw);
free(raw);
char* string = o_JSONObjectToString(json);
o_destroyJSONObject(&json);
printf("%s", string);
free(string);
return 0;
}

11
test.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
for file in tests/*.json; do
./libjsontest $file > testout/got/$file
if cmp --silent testout/got/$file testout/exp/$file; then
echo "\033[0;32m$file\033[0m"
else
echo "\033[0;31m$file\033[0m"
fi
done

View File

@@ -0,0 +1 @@
{"clients":[{"id":"59761c23b30d971669fb42ff","isActive":true,"age":36,"name":"Dunlap Hubbard","gender":"male","company":"CEDWARD","email":"dunlaphubbard@cedward.com","phone":"+1 (890) 543-2508","address":"169 Rutledge Street, Konterra, Northern Mariana Islands, 8551"},{"id":"59761c233d8d0f92a6b0570d","isActive":true,"age":24,"name":"Kirsten Sellers","gender":"female","company":"EMERGENT","email":"kirstensellers@emergent.com","phone":"+1 (831) 564-2190","address":"886 Gallatin Place, Fannett, Arkansas, 4656"},{"id":"59761c23fcb6254b1a06dad5","isActive":true,"age":30,"name":"Acosta Robbins","gender":"male","company":"ORGANICA","email":"acostarobbins@organica.com","phone":"+1 (882) 441-3367","address":"697 Linden Boulevard, Sattley, Idaho, 1035"}]}

View File

@@ -0,0 +1 @@
{"colors":[{"color":"black","category":"hue","type":"primary","code":{"rgba":[255,255,255,1],"hex":"#000"}},{"color":"white","category":"value","code":{"rgba":[0,0,0,1],"hex":"#FFF"}},{"color":"red","category":"hue","type":"primary","code":{"rgba":[255,0,0,1],"hex":"#FF0"}},{"color":"blue","category":"hue","type":"primary","code":{"rgba":[0,0,255,1],"hex":"#00F"}},{"color":"yellow","category":"hue","type":"primary","code":{"rgba":[255,255,0,1],"hex":"#FF0"}},{"color":"green","category":"hue","type":"secondary","code":{"rgba":[0,255,0,1],"hex":"#0F0"}}]}

View File

@@ -0,0 +1 @@
{"total":25,"limit":10,"skip":0,"data":[{"_id":"5968fcad629fa84ab65a5247","first_name":"Sabrina","last_name":"Mayert","address":"69756 Wendy Junction","phone":"1-406-866-3476 x478","email":"donny54@yahoo.com","updatedAt":"2017-07-14T17:17:33.010Z","createdAt":"2017-07-14T17:17:33.010Z","__v":0},{"_id":"5968fcad629fa84ab65a5246","first_name":"Taryn","last_name":"Dietrich","address":"42080 Federico Greens","phone":"(197) 679-7020 x98462","email":"betty_schaefer1@gmail.com","updatedAt":"2017-07-14T17:17:33.006Z","createdAt":"2017-07-14T17:17:33.006Z","__v":0}]}

View File

@@ -0,0 +1 @@
{"as":"AS16509 Amazon.com, Inc.","city":"Boardman","country":"United States","countryCode":"US","isp":"Amazon","lat":45.8696,"lon":-119.688,"org":"Amazon","query":"54.148.84.95","region":"OR","regionName":"Oregon","status":"success","timezone":"America\/Los_Angeles","zip":"97818"}

View File

@@ -0,0 +1 @@
{"inventory":[{"_id":{"$oid":"5968dd23fc13ae04d9000001"},"product_name":"sildenafil citrate","supplier":"Wisozk Inc","quantity":261,"unit_cost":"$10.47"},{"_id":{"$oid":"5968dd23fc13ae04d9000002"},"product_name":"Mountain Juniperus ashei","supplier":"Keebler-Hilpert","quantity":292,"unit_cost":"$8.74"},{"_id":{"$oid":"5968dd23fc13ae04d9000003"},"product_name":"Dextromathorphan HBr","supplier":"Schmitt-Weissnat","quantity":211,"unit_cost":"$20.53"}]}

View File

@@ -0,0 +1 @@
{"results":[{"address_components":[{"long_name":"130","short_name":"130","types":["subpremise"]},{"long_name":"8703","short_name":"8703","types":["street_number"]},{"long_name":"North Owasso Expressway","short_name":"N Owasso Expy","types":["route"]},{"long_name":"Owasso","short_name":"Owasso","types":["locality","political"]},{"long_name":"Tulsa County","short_name":"Tulsa County","types":["administrative_area_level_2","political"]},{"long_name":"Oklahoma","short_name":"OK","types":["administrative_area_level_1","political"]},{"long_name":"United States","short_name":"US","types":["country","political"]},{"long_name":"74055","short_name":"74055","types":["postal_code"]}],"formatted_address":"8703 N Owasso Expy #130, Owasso, OK 74055, USA","geometry":{"location":{"lat":36.28038850000001,"lng":-95.84539679999999},"location_type":"ROOFTOP","viewport":{"northeast":{"lat":36.28173748029151,"lng":-95.84404781970848},"southwest":{"lat":36.27903951970851,"lng":-95.8467457802915}}},"place_id":"ChIJFxYi1Y_wtocRpd7C_DtxySM","types":["establishment","point_of_interest"]}],"status":"OK"}

View File

@@ -0,0 +1 @@
{"tweets":[{"created_at":"Thu Jun 22 21:00:00 +0000 2017","id":877994604561387500,"id_str":"877994604561387520","text":"Creating a Grocery List Manager Using Angular, Part 1: Add &amp; Display Items https://t.co/xFox78juL1 #Angular","truncated":false,"entities":{"hashtags":[{"text":"Angular","indices":[103,111]}],"symbols":[],"user_mentions":[],"urls":[{"url":"https://t.co/xFox78juL1","expanded_url":"http://buff.ly/2sr60pf","display_url":"buff.ly/2sr60pf","indices":[79,102]}]},"source":"<a href=\"http://bufferapp.com\" rel=\"nofollow\">Buffer</a>","user":{"id":772682964,"id_str":"772682964","name":"SitePoint JavaScript","screen_name":"SitePointJS","location":"Melbourne, Australia","description":"Keep up with JavaScript tutorials, tips, tricks and articles at SitePoint.","url":"http://t.co/cCH13gqeUK","entities":{"url":{"urls":[{"url":"http://t.co/cCH13gqeUK","expanded_url":"http://sitepoint.com/javascript","display_url":"sitepoint.com/javascript","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":2145,"friends_count":18,"listed_count":328,"created_at":"Wed Aug 22 02:06:33 +0000 2012","favourites_count":57,"utc_offset":43200,"time_zone":"Wellington"}}]}

View File

@@ -0,0 +1 @@
{"blogs":[{"id":157538,"date":"2017-07-21T10:30:34","date_gmt":"2017-07-21T17:30:34","guid":{"rendered":"https://www.sitepoint.com/?p=157538"},"modified":"2017-07-23T21:56:35","modified_gmt":"2017-07-24T04:56:35","slug":"why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it","status":"publish","type":"post","link":"https://www.sitepoint.com/why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it/","title":{"rendered":"Why the IoT Threatens Your WordPress Site (and How to Fix It)"},"content":{},"excerpt":{},"author":72546,"featured_media":157542,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6132],"tags":[1798,6298]}]}

View File

@@ -0,0 +1 @@
{"kind":"youtube#searchListResponse","etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/PaiEDiVxOyCWelLPuuwa9LKz3Gk\"","nextPageToken":"CAUQAA","regionCode":"KE","pageInfo":{"totalResults":4249,"resultsPerPage":5},"items":[{"kind":"youtube#searchResult","etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/QpOIr3QKlV5EUlzfFcVvDiJT0hw\"","id":{"kind":"youtube#channel","channelId":"UCJowOS1R0FnhipXVqEnYU1A"}},{"kind":"youtube#searchResult","etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/AWutzVOt_5p1iLVifyBdfoSTf9E\"","id":{"kind":"youtube#video","videoId":"Eqa2nAAhHN0"}},{"kind":"youtube#searchResult","etag":"\"m2yskBQFythfE4irbTIeOgYYfBU/2dIR9BTfr7QphpBuY3hPU-h5u-4\"","id":{"kind":"youtube#video","videoId":"IirngItQuVs"}}]}

37
tests/clients.json Normal file
View File

@@ -0,0 +1,37 @@
{
"clients": [
{
"id": "59761c23b30d971669fb42ff",
"isActive": true,
"age": 36,
"name": "Dunlap Hubbard",
"gender": "male",
"company": "CEDWARD",
"email": "dunlaphubbard@cedward.com",
"phone": "+1 (890) 543-2508",
"address": "169 Rutledge Street, Konterra, Northern Mariana Islands, 8551"
},
{
"id": "59761c233d8d0f92a6b0570d",
"isActive": true,
"age": 24,
"name": "Kirsten Sellers",
"gender": "female",
"company": "EMERGENT",
"email": "kirstensellers@emergent.com",
"phone": "+1 (831) 564-2190",
"address": "886 Gallatin Place, Fannett, Arkansas, 4656"
},
{
"id": "59761c23fcb6254b1a06dad5",
"isActive": true,
"age": 30,
"name": "Acosta Robbins",
"gender": "male",
"company": "ORGANICA",
"email": "acostarobbins@organica.com",
"phone": "+1 (882) 441-3367",
"address": "697 Linden Boulevard, Sattley, Idaho, 1035"
}
]
}

87
tests/colors.json Normal file
View File

@@ -0,0 +1,87 @@
{
"colors": [
{
"color": "black",
"category": "hue",
"type": "primary",
"code": {
"rgba": [
255,
255,
255,
1
],
"hex": "#000"
}
},
{
"color": "white",
"category": "value",
"code": {
"rgba": [
0,
0,
0,
1
],
"hex": "#FFF"
}
},
{
"color": "red",
"category": "hue",
"type": "primary",
"code": {
"rgba": [
255,
0,
0,
1
],
"hex": "#FF0"
}
},
{
"color": "blue",
"category": "hue",
"type": "primary",
"code": {
"rgba": [
0,
0,
255,
1
],
"hex": "#00F"
}
},
{
"color": "yellow",
"category": "hue",
"type": "primary",
"code": {
"rgba": [
255,
255,
0,
1
],
"hex": "#FF0"
}
},
{
"color": "green",
"category": "hue",
"type": "secondary",
"code": {
"rgba": [
0,
255,
0,
1
],
"hex": "#0F0"
}
}
]
}

29
tests/contacts.json Normal file
View File

@@ -0,0 +1,29 @@
{
"total": 25,
"limit": 10,
"skip": 0,
"data": [
{
"_id": "5968fcad629fa84ab65a5247",
"first_name": "Sabrina",
"last_name": "Mayert",
"address": "69756 Wendy Junction",
"phone": "1-406-866-3476 x478",
"email": "donny54@yahoo.com",
"updatedAt": "2017-07-14T17:17:33.010Z",
"createdAt": "2017-07-14T17:17:33.010Z",
"__v": 0
},
{
"_id": "5968fcad629fa84ab65a5246",
"first_name": "Taryn",
"last_name": "Dietrich",
"address": "42080 Federico Greens",
"phone": "(197) 679-7020 x98462",
"email": "betty_schaefer1@gmail.com",
"updatedAt": "2017-07-14T17:17:33.006Z",
"createdAt": "2017-07-14T17:17:33.006Z",
"__v": 0
}
]
}

16
tests/geoip.json Normal file
View File

@@ -0,0 +1,16 @@
{
"as": "AS16509 Amazon.com, Inc.",
"city": "Boardman",
"country": "United States",
"countryCode": "US",
"isp": "Amazon",
"lat": 45.8696,
"lon": -119.688,
"org": "Amazon",
"query": "54.148.84.95",
"region": "OR",
"regionName": "Oregon",
"status": "success",
"timezone": "America\/Los_Angeles",
"zip": "97818"
}

31
tests/inventory.json Normal file
View File

@@ -0,0 +1,31 @@
{
"inventory": [
{
"_id": {
"$oid": "5968dd23fc13ae04d9000001"
},
"product_name": "sildenafil citrate",
"supplier": "Wisozk Inc",
"quantity": 261,
"unit_cost": "$10.47"
},
{
"_id": {
"$oid": "5968dd23fc13ae04d9000002"
},
"product_name": "Mountain Juniperus ashei",
"supplier": "Keebler-Hilpert",
"quantity": 292,
"unit_cost": "$8.74"
},
{
"_id": {
"$oid": "5968dd23fc13ae04d9000003"
},
"product_name": "Dextromathorphan HBr",
"supplier": "Schmitt-Weissnat",
"quantity": 211,
"unit_cost": "$20.53"
}
]
}

92
tests/maps.json Normal file
View File

@@ -0,0 +1,92 @@
{
"results": [
{
"address_components": [
{
"long_name": "130",
"short_name": "130",
"types": [
"subpremise"
]
},
{
"long_name": "8703",
"short_name": "8703",
"types": [
"street_number"
]
},
{
"long_name": "North Owasso Expressway",
"short_name": "N Owasso Expy",
"types": [
"route"
]
},
{
"long_name": "Owasso",
"short_name": "Owasso",
"types": [
"locality",
"political"
]
},
{
"long_name": "Tulsa County",
"short_name": "Tulsa County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Oklahoma",
"short_name": "OK",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "74055",
"short_name": "74055",
"types": [
"postal_code"
]
}
],
"formatted_address": "8703 N Owasso Expy #130, Owasso, OK 74055, USA",
"geometry": {
"location": {
"lat": 36.28038850000001,
"lng": -95.84539679999999
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 36.28173748029151,
"lng": -95.84404781970848
},
"southwest": {
"lat": 36.27903951970851,
"lng": -95.8467457802915
}
}
},
"place_id": "ChIJFxYi1Y_wtocRpd7C_DtxySM",
"types": [
"establishment",
"point_of_interest"
]
}
],
"status": "OK"
}

74
tests/twitter.json Normal file
View File

@@ -0,0 +1,74 @@
{
"tweets": [
{
"created_at": "Thu Jun 22 21:00:00 +0000 2017",
"id": 877994604561387500,
"id_str": "877994604561387520",
"text": "Creating a Grocery List Manager Using Angular, Part 1: Add &amp; Display Items https://t.co/xFox78juL1 #Angular",
"truncated": false,
"entities": {
"hashtags": [
{
"text": "Angular",
"indices": [
103,
111
]
}
],
"symbols": [
],
"user_mentions": [
],
"urls": [
{
"url": "https://t.co/xFox78juL1",
"expanded_url": "http://buff.ly/2sr60pf",
"display_url": "buff.ly/2sr60pf",
"indices": [
79,
102
]
}
]
},
"source": "<a href=\"http://bufferapp.com\" rel=\"nofollow\">Buffer</a>",
"user": {
"id": 772682964,
"id_str": "772682964",
"name": "SitePoint JavaScript",
"screen_name": "SitePointJS",
"location": "Melbourne, Australia",
"description": "Keep up with JavaScript tutorials, tips, tricks and articles at SitePoint.",
"url": "http://t.co/cCH13gqeUK",
"entities": {
"url": {
"urls": [
{
"url": "http://t.co/cCH13gqeUK",
"expanded_url": "http://sitepoint.com/javascript",
"display_url": "sitepoint.com/javascript",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": [
]
}
},
"protected": false,
"followers_count": 2145,
"friends_count": 18,
"listed_count": 328,
"created_at": "Wed Aug 22 02:06:33 +0000 2012",
"favourites_count": 57,
"utc_offset": 43200,
"time_zone": "Wellington"
}
}
]
}

41
tests/wordpress.json Normal file
View File

@@ -0,0 +1,41 @@
{
"blogs": [
{
"id": 157538,
"date": "2017-07-21T10:30:34",
"date_gmt": "2017-07-21T17:30:34",
"guid": {
"rendered": "https://www.sitepoint.com/?p=157538"
},
"modified": "2017-07-23T21:56:35",
"modified_gmt": "2017-07-24T04:56:35",
"slug": "why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it",
"status": "publish",
"type": "post",
"link": "https://www.sitepoint.com/why-the-iot-threatens-your-wordpress-site-and-how-to-fix-it/",
"title": {
"rendered": "Why the IoT Threatens Your WordPress Site (and How to Fix It)"
},
"content": {
},
"excerpt": {
},
"author": 72546,
"featured_media": 157542,
"comment_status": "open",
"ping_status": "closed",
"sticky": false,
"template": "",
"format": "standard",
"meta": [
],
"categories": [
6132
],
"tags": [
1798,
6298
]
}
]
}

36
tests/youtube.json Normal file
View File

@@ -0,0 +1,36 @@
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/PaiEDiVxOyCWelLPuuwa9LKz3Gk\"",
"nextPageToken": "CAUQAA",
"regionCode": "KE",
"pageInfo": {
"totalResults": 4249,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/QpOIr3QKlV5EUlzfFcVvDiJT0hw\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCJowOS1R0FnhipXVqEnYU1A"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/AWutzVOt_5p1iLVifyBdfoSTf9E\"",
"id": {
"kind": "youtube#video",
"videoId": "Eqa2nAAhHN0"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/2dIR9BTfr7QphpBuY3hPU-h5u-4\"",
"id": {
"kind": "youtube#video",
"videoId": "IirngItQuVs"
}
}
]
}