add tests
This commit is contained in:
parent
1e3b41e8ea
commit
39601c183a
13
Makefile
Normal file
13
Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
JANSSON_CFLAGS := $(shell pkg-config --cflags jansson)
|
||||
JANSSON_LIBS := $(shell pkg-config --libs jansson)
|
||||
|
||||
all: test
|
||||
|
||||
test-bin: test.cc janssonxx.h Makefile
|
||||
$(CXX) -o $@ -g -O0 -Wall $(JANSSON_CFLAGS) $< $(JANSSON_LIBS)
|
||||
|
||||
test: test-bin
|
||||
./test-bin
|
||||
|
||||
clean:
|
||||
rm -f test-bin
|
66
test.cc
Normal file
66
test.cc
Normal file
@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "janssonxx.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define ASSERT_OP(lhs, rhs, op, m) \
|
||||
do { \
|
||||
if(!((lhs) op (rhs))) { \
|
||||
std::cerr << std::boolalpha; \
|
||||
std::cerr << __FILE__ << '[' << __LINE__ << "]: ERROR: " << (m) << std::endl; \
|
||||
std::cerr << "\ttest: " << #lhs << ' ' << #op << ' ' << #rhs << std::endl; \
|
||||
std::cerr << "\tresult: " << (lhs) << ' ' << #op << ' ' << (rhs) << std::endl; \
|
||||
return 1; \
|
||||
} \
|
||||
} while(0)
|
||||
#define ASSERT_EQ(lhs, rhs, m) ASSERT_OP(lhs, rhs, ==, m)
|
||||
#define ASSERT_NE(lhs, rhs, m) ASSERT_OP(lhs, rhs, !=, m)
|
||||
#define ASSERT_TRUE(p, m) ASSERT_OP(p, true, ==, m)
|
||||
#define ASSERT_FALSE(p, m) ASSERT_OP(p, true, !=, m)
|
||||
|
||||
int main() {
|
||||
jansson::Value e1(jansson::Value::load_file("test.json"));
|
||||
jansson::Value e2(e1);
|
||||
jansson::Value e3;
|
||||
jansson::Value e4(jansson::Value::load_string("{\"foo\": true, \"bar\": \"test\"}"));
|
||||
|
||||
ASSERT_TRUE(e1.is_object(), "e1 is not an object");
|
||||
ASSERT_TRUE(e2.is_object(), "e2 is not an object");
|
||||
ASSERT_TRUE(e3.is_undefined(), "e3 has a defined value");
|
||||
ASSERT_TRUE(e4.is_object(), "e4 is not an object");
|
||||
|
||||
ASSERT_EQ(e1.size(), 1, "e1 has too many properties");
|
||||
ASSERT_EQ(e2.size(), 1, "e2 has too many properties");
|
||||
ASSERT_EQ(e4.size(), 2, "e4 does not have 2 elements");
|
||||
|
||||
ASSERT_TRUE(e1.get("web-app").is_object(), "e1[0].web-app is not an object");
|
||||
ASSERT_EQ(e1.get("web-app").get("servlet").at(0).get("servlet-class").as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value");
|
||||
ASSERT_EQ(e1["web-app"]["servlet"][0]["servlet-class"].as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value");
|
||||
|
||||
ASSERT_EQ(e4["foo"].as_boolean(), true, "property has incorrect value");
|
||||
|
||||
jansson::Iterator i(e1.get("web-app"));
|
||||
ASSERT_EQ(i.key(), "taglib", "first iterator result has incorrect key");
|
||||
i.next();
|
||||
ASSERT_EQ(i.key(), "servlet", "first iterator result has incorrect key");
|
||||
i.next();
|
||||
ASSERT_EQ(i.key(), "servlet-mapping", "first iterator result has incorrect key");
|
||||
i.next();
|
||||
ASSERT_FALSE(i.valid(), "iterator has more values than expected");
|
||||
|
||||
e3 = 12.34;
|
||||
ASSERT_TRUE(e3.is_number(), "e3 is not a number after assignment");
|
||||
ASSERT_EQ(e3.as_real(), 12.34, "e3 has incorrect value after assignment");
|
||||
|
||||
e3 = true;
|
||||
ASSERT_TRUE(e3.is_boolean(), "e3 is not a boolean after assignment");
|
||||
ASSERT_EQ(e3.as_boolean(), true, "e3 has incorrect value after assignment");
|
||||
|
||||
e3 = "foobar";
|
||||
ASSERT_TRUE(e3.is_string(), "e3 is not a string after assignment");
|
||||
ASSERT_EQ(e3.as_string(), "foobar", "e3 has incorrect value after assignment");
|
||||
|
||||
return 0;
|
||||
}
|
88
test.json
Normal file
88
test.json
Normal file
@ -0,0 +1,88 @@
|
||||
{"web-app": {
|
||||
"servlet": [
|
||||
{
|
||||
"servlet-name": "cofaxCDS",
|
||||
"servlet-class": "org.cofax.cds.CDSServlet",
|
||||
"init-param": {
|
||||
"configGlossary:installationAt": "Philadelphia, PA",
|
||||
"configGlossary:adminEmail": "ksm@pobox.com",
|
||||
"configGlossary:poweredBy": "Cofax",
|
||||
"configGlossary:poweredByIcon": "/images/cofax.gif",
|
||||
"configGlossary:staticPath": "/content/static",
|
||||
"templateProcessorClass": "org.cofax.WysiwygTemplate",
|
||||
"templateLoaderClass": "org.cofax.FilesTemplateLoader",
|
||||
"templatePath": "templates",
|
||||
"templateOverridePath": "",
|
||||
"defaultListTemplate": "listTemplate.htm",
|
||||
"defaultFileTemplate": "articleTemplate.htm",
|
||||
"useJSP": false,
|
||||
"jspListTemplate": "listTemplate.jsp",
|
||||
"jspFileTemplate": "articleTemplate.jsp",
|
||||
"cachePackageTagsTrack": 200,
|
||||
"cachePackageTagsStore": 200,
|
||||
"cachePackageTagsRefresh": 60,
|
||||
"cacheTemplatesTrack": 100,
|
||||
"cacheTemplatesStore": 50,
|
||||
"cacheTemplatesRefresh": 15,
|
||||
"cachePagesTrack": 200,
|
||||
"cachePagesStore": 100,
|
||||
"cachePagesRefresh": 10,
|
||||
"cachePagesDirtyRead": 10,
|
||||
"searchEngineListTemplate": "forSearchEnginesList.htm",
|
||||
"searchEngineFileTemplate": "forSearchEngines.htm",
|
||||
"searchEngineRobotsDb": "WEB-INF/robots.db",
|
||||
"useDataStore": true,
|
||||
"dataStoreClass": "org.cofax.SqlDataStore",
|
||||
"redirectionClass": "org.cofax.SqlRedirection",
|
||||
"dataStoreName": "cofax",
|
||||
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
|
||||
"dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
|
||||
"dataStoreUser": "sa",
|
||||
"dataStorePassword": "dataStoreTestQuery",
|
||||
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
|
||||
"dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
|
||||
"dataStoreInitConns": 10,
|
||||
"dataStoreMaxConns": 100,
|
||||
"dataStoreConnUsageLimit": 100,
|
||||
"dataStoreLogLevel": "debug",
|
||||
"maxUrlLength": 500}},
|
||||
{
|
||||
"servlet-name": "cofaxEmail",
|
||||
"servlet-class": "org.cofax.cds.EmailServlet",
|
||||
"init-param": {
|
||||
"mailHost": "mail1",
|
||||
"mailHostOverride": "mail2"}},
|
||||
{
|
||||
"servlet-name": "cofaxAdmin",
|
||||
"servlet-class": "org.cofax.cds.AdminServlet"},
|
||||
|
||||
{
|
||||
"servlet-name": "fileServlet",
|
||||
"servlet-class": "org.cofax.cds.FileServlet"},
|
||||
{
|
||||
"servlet-name": "cofaxTools",
|
||||
"servlet-class": "org.cofax.cms.CofaxToolsServlet",
|
||||
"init-param": {
|
||||
"templatePath": "toolstemplates/",
|
||||
"log": 1,
|
||||
"logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
|
||||
"logMaxSize": "",
|
||||
"dataLog": 1,
|
||||
"dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
|
||||
"dataLogMaxSize": "",
|
||||
"removePageCache": "/content/admin/remove?cache=pages&id=",
|
||||
"removeTemplateCache": "/content/admin/remove?cache=templates&id=",
|
||||
"fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
|
||||
"lookInContext": 1,
|
||||
"adminGroupID": 4,
|
||||
"betaServer": true}}],
|
||||
"servlet-mapping": {
|
||||
"cofaxCDS": "/",
|
||||
"cofaxEmail": "/cofaxutil/aemail/*",
|
||||
"cofaxAdmin": "/admin/*",
|
||||
"fileServlet": "/static/*",
|
||||
"cofaxTools": "/tools/*"},
|
||||
|
||||
"taglib": {
|
||||
"taglib-uri": "cofax.tld",
|
||||
"taglib-location": "/WEB-INF/tlds/cofax.tld"}}}
|
Loading…
Reference in New Issue
Block a user