[DEV] set test in gtest
This commit is contained in:
parent
63a83873f8
commit
95296e1d06
569
ejson/test.cpp
569
ejson/test.cpp
@ -1,569 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <etk/types.h>
|
||||
#include <ejson/debug.h>
|
||||
#include <ejson/ejson.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ejson::test"
|
||||
|
||||
class testCheck {
|
||||
public:
|
||||
std::string m_ref;
|
||||
std::string m_input;
|
||||
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
||||
testCheck() {};
|
||||
void set(const std::string& _ref, int32_t _pos, const std::string& _input) {
|
||||
m_ref = _ref;
|
||||
m_input = _input;
|
||||
m_errorPos = _pos;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<testCheck> l_list;
|
||||
|
||||
void init() {
|
||||
std::string reference;
|
||||
std::string input;
|
||||
testCheck check;
|
||||
|
||||
// == ====================================================
|
||||
check.set("test ejson::Doc", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
reference = "{\n}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ \t\r }\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test ejson::null", -2, "");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n\t\"tmpElement\": null\n}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ tmpElement:null }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ \t\ntmpElement:null \t\n }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"tmpElement:null\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test ejson::boolean", -2, "");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n\t\"tmpElement\": true\n}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ tmpElement:true }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ \t\ntmpElement:true \t\n }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"tmpElement:true\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n\t\"tmpElement\": false\n}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ tmpElement:false }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ \t\ntmpElement:false \t\n }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"tmpElement:false\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test ejson::number", -2, "");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n\t\"tmpElement\": 956256\n}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ tmpElement:956256 }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{ \t\ntmpElement:956256 \t\n }\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"tmpElement:956256\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": 956256\n}\n",
|
||||
-1,
|
||||
"{tmpElement:956256}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": -956256\n}\n",
|
||||
-1,
|
||||
"{tmpElement:-956256}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": -956256\n}\n",
|
||||
-1,
|
||||
"{tmpElement:-956256}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": -956.256000\n}\n",
|
||||
-1,
|
||||
"{tmpElement:-956.256}\n");
|
||||
l_list.push_back(check);
|
||||
/*
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": -956956544454621184\n}\n",
|
||||
-1,
|
||||
"{tmpElement:-956956544454621354.256}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("{\n\t\"tmpElement\": 0.000002\n}\n",
|
||||
-1,
|
||||
"{tmpElement:+.000001565464}\n");
|
||||
l_list.push_back(check);
|
||||
*/
|
||||
|
||||
|
||||
// == ====================================================
|
||||
check.set("test ejson::all", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
reference = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": [\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" },\n"
|
||||
" { \"value\": \"New\", \"onclick\": \"CreateNewDoc()\" },\n"
|
||||
" { \"value\": \"Open\", \"onclick\": \"OpenDoc()\" },\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"{\n"
|
||||
" menu: {\n"
|
||||
" id: \"file\",\n"
|
||||
" value: \"File\",\n"
|
||||
" popup: {\n"
|
||||
" menuitem: [\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"New\",\n"
|
||||
" onclick: \"CreateNewDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Open\",\n"
|
||||
" onclick: \"OpenDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"menu: {\n"
|
||||
" id: \"file\",\n"
|
||||
" value: \"File\",\n"
|
||||
" popup: {\n"
|
||||
" menuitem: [\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"New\",\n"
|
||||
" onclick: \"CreateNewDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Open\",\n"
|
||||
" onclick: \"OpenDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
l_list.push_back(check);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
reference = "{\n"
|
||||
" \"glossary\": {\n"
|
||||
" \"title\": \"example glossary\",\n"
|
||||
" \"GlossDiv\": {\n"
|
||||
" \"title\": \"S\",\n"
|
||||
" \"GlossList\": {\n"
|
||||
" \"GlossEntry\": {\n"
|
||||
" \"ID\": \"SGML\",\n"
|
||||
" \"SortAs\": \"SGML\",\n"
|
||||
" \"GlossTerm\": \"Standard Generalized Markup Language\",\n"
|
||||
" \"Acronym\": \"SGML\",\n"
|
||||
" \"Abbrev\": \"ISO 8879:1986\",\n"
|
||||
" \"GlossDef\": {\n"
|
||||
" \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n"
|
||||
" \"GlossSeeAlso\": [ \"GML\", \"XML\" ]\n"
|
||||
" },\n"
|
||||
" \"GlossSee\": \"markup\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": [\n"
|
||||
" { \"value\": \"New\", \"onclick\": \"CreateNewDoc()\" },\n"
|
||||
" { \"value\": \"Open\", \"onclick\": \"OpenDoc()\" },\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n"
|
||||
" \"widget\": {\n"
|
||||
" \"debug\": \"on\",\n"
|
||||
" \"window\": {\n"
|
||||
" \"title\": \"Sample Konfabulator Widget\",\n"
|
||||
" \"name\": \"main_window\",\n"
|
||||
" \"width\": 500,\n"
|
||||
" \"height\": 500\n"
|
||||
" },\n"
|
||||
" \"image\": {\n"
|
||||
" \"src\": \"Images/Sun.png\",\n"
|
||||
" \"name\": \"sun1\",\n"
|
||||
" \"hOffset\": 250,\n"
|
||||
" \"vOffset\": 250,\n"
|
||||
" \"alignment\": \"center\"\n"
|
||||
" },\n"
|
||||
" \"text\": {\n"
|
||||
" \"data\": \"Click Here\",\n"
|
||||
" \"size\": 36,\n"
|
||||
" \"style\": \"bold\",\n"
|
||||
" \"name\": \"text1\",\n"
|
||||
" \"hOffset\": 250,\n"
|
||||
" \"vOffset\": 100,\n"
|
||||
" \"alignment\": \"center\",\n"
|
||||
" \"onMouseUp\": \"sun1.opacity = (sun1.opacity / 100) * 90;\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n"
|
||||
" \"web-app\": {\n"
|
||||
" \"servlet\": [\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxCDS\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.CDSServlet\",\n"
|
||||
" \"init-param\": {\n"
|
||||
" \"configGlossary:installationAt\": \"Philadelphia, PA\",\n"
|
||||
" \"configGlossary:adminEmail\": \"ksm@pobox.com\",\n"
|
||||
" \"configGlossary:poweredBy\": \"Cofax\",\n"
|
||||
" \"configGlossary:poweredByIcon\": \"/images/cofax.gif\",\n"
|
||||
" \"configGlossary:staticPath\": \"/content/static\",\n"
|
||||
" \"templateProcessorClass\": \"org.cofax.WysiwygTemplate\",\n"
|
||||
" \"templateLoaderClass\": \"org.cofax.FilesTemplateLoader\",\n"
|
||||
" \"templatePath\": \"templates\",\n"
|
||||
" \"templateOverridePath\": \"\",\n"
|
||||
" \"defaultListTemplate\": \"listTemplate.htm\",\n"
|
||||
" \"defaultFileTemplate\": \"articleTemplate.htm\",\n"
|
||||
" \"useJSP\": false,\n"
|
||||
" \"jspListTemplate\": \"listTemplate.jsp\",\n"
|
||||
" \"jspFileTemplate\": \"articleTemplate.jsp\",\n"
|
||||
" \"cachePackageTagsTrack\": 200,\n"
|
||||
" \"cachePackageTagsStore\": 200,\n"
|
||||
" \"cachePackageTagsRefresh\": 60,\n"
|
||||
" \"cacheTemplatesTrack\": 100,\n"
|
||||
" \"cacheTemplatesStore\": 50,\n"
|
||||
" \"cacheTemplatesRefresh\": 15,\n"
|
||||
" \"cachePagesTrack\": 200,\n"
|
||||
" \"cachePagesStore\": 100,\n"
|
||||
" \"cachePagesRefresh\": 10,\n"
|
||||
" \"cachePagesDirtyRead\": 10,\n"
|
||||
" \"searchEngineListTemplate\": \"forSearchEnginesList.htm\",\n"
|
||||
" \"searchEngineFileTemplate\": \"forSearchEngines.htm\",\n"
|
||||
" \"searchEngineRobotsDb\": \"WEB-INF/robots.db\",\n"
|
||||
" \"useDataStore\": true,\n"
|
||||
" \"dataStoreClass\": \"org.cofax.SqlDataStore\",\n"
|
||||
" \"redirectionClass\": \"org.cofax.SqlRedirection\",\n"
|
||||
" \"dataStoreName\": \"cofax\",\n"
|
||||
" \"dataStoreDriver\": \"com.microsoft.jdbc.sqlserver.SQLServerDriver\",\n"
|
||||
" \"dataStoreUrl\": \"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon\",\n"
|
||||
" \"dataStoreUser\": \"sa\",\n"
|
||||
" \"dataStorePassword\": \"dataStoreTestQuery\",\n"
|
||||
" \"dataStoreTestQuery\": \"SET NOCOUNT ON;select test='test';\",\n"
|
||||
" \"dataStoreLogFile\": \"/usr/local/tomcat/logs/datastore.log\",\n"
|
||||
" \"dataStoreInitConns\": 10,\n"
|
||||
" \"dataStoreMaxConns\": 100,\n"
|
||||
" \"dataStoreConnUsageLimit\": 100,\n"
|
||||
" \"dataStoreLogLevel\": \"debug\",\n"
|
||||
" \"maxUrlLength\": 500\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxEmail\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.EmailServlet\",\n"
|
||||
" \"init-param\": { \"mailHost\": \"mail1\", \"mailHostOverride\": \"mail2\" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxAdmin\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.AdminServlet\"\n"
|
||||
" },\n"
|
||||
" { \"servlet-name\": \"fileServlet\", \"servlet-class\": \"org.cofax.cds.FileServlet\" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxTools\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cms.CofaxToolsServlet\",\n"
|
||||
" \"init-param\": {\n"
|
||||
" \"templatePath\": \"toolstemplates/\",\n"
|
||||
" \"log\": 1,\n"
|
||||
" \"logLocation\": \"/usr/local/tomcat/logs/CofaxTools.log\",\n"
|
||||
" \"logMaxSize\": \"\",\n"
|
||||
" \"dataLog\": 1,\n"
|
||||
" \"dataLogLocation\": \"/usr/local/tomcat/logs/dataLog.log\",\n"
|
||||
" \"dataLogMaxSize\": \"\",\n"
|
||||
" \"removePageCache\": \"/content/admin/remove?cache=pages&id=\",\n"
|
||||
" \"removeTemplateCache\": \"/content/admin/remove?cache=templates&id=\",\n"
|
||||
" \"fileTransferFolder\": \"/usr/local/tomcat/webapps/content/fileTransferFolder\",\n"
|
||||
" \"lookInContext\": 1,\n"
|
||||
" \"adminGroupID\": 4,\n"
|
||||
" \"betaServer\": true\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" ],\n"
|
||||
" \"servlet-mapping\": {\n"
|
||||
" \"cofaxCDS\": \"/\",\n"
|
||||
" \"cofaxEmail\": \"/cofaxutil/aemail/*\",\n"
|
||||
" \"cofaxAdmin\": \"/admin/*\",\n"
|
||||
" \"fileServlet\": \"/static/*\",\n"
|
||||
" \"cofaxTools\": \"/tools/*\"\n"
|
||||
" },\n"
|
||||
" \"taglib\": { \"taglib-uri\": \"cofax.tld\", \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
reference = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"header\": \"SVG Viewer\",\n"
|
||||
" \"items\": [\n"
|
||||
" { \"id\": \"Open\" },\n"
|
||||
" { \"id\": \"OpenNew\", \"label\": \"Open New\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"ZoomIn\", \"label\": \"Zoom In\" },\n"
|
||||
" { \"id\": \"ZoomOut\", \"label\": \"Zoom Out\" },\n"
|
||||
" { \"id\": \"OriginalView\", \"label\": \"Original View\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Quality\" },\n"
|
||||
" { \"id\": \"Pause\" },\n"
|
||||
" { \"id\": \"Mute\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Find\", \"label\": \"Find...\" },\n"
|
||||
" { \"id\": \"FindAgain\", \"label\": \"Find Again\" },\n"
|
||||
" { \"id\": \"Copy\" },\n"
|
||||
" { \"id\": \"CopyAgain\", \"label\": \"Copy Again\" },\n"
|
||||
" { \"id\": \"CopySVG\", \"label\": \"Copy SVG\" },\n"
|
||||
" { \"id\": \"ViewSVG\", \"label\": \"View SVG\" },\n"
|
||||
" { \"id\": \"ViewSource\", \"label\": \"View Source\" },\n"
|
||||
" { \"id\": \"SaveAs\", \"label\": \"Save As\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Help\" },\n"
|
||||
" { \"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
reference);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
etk::log::setLevel(etk::log::logLevelInfo);
|
||||
|
||||
|
||||
init();
|
||||
int32_t countError = 0;
|
||||
int32_t countSeparator = 0;
|
||||
int32_t sectionID = 0;
|
||||
for (int32_t iii=0 ; iii<l_list.size() ; iii++) {
|
||||
int32_t jjj= iii-countSeparator+1;
|
||||
if (l_list[iii].m_errorPos == -2) {
|
||||
countSeparator++;
|
||||
sectionID = 0;
|
||||
JSON_INFO("-------------------------------------------------------------");
|
||||
JSON_INFO("-- " << l_list[iii].m_ref);
|
||||
JSON_INFO("-------------------------------------------------------------");
|
||||
continue;
|
||||
}
|
||||
sectionID++;
|
||||
ejson::Document doc;
|
||||
std::string out("");
|
||||
//JSON_DEBUG("parse : \n" << l_list[iii].m_input);
|
||||
if (false == doc.parse(l_list[iii].m_input)) {
|
||||
if (l_list[iii].m_errorPos == 1) {
|
||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Parsing in error (correct result)");
|
||||
} else {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be OK");
|
||||
JSON_ERROR("parse : \n" << l_list[iii].m_input);
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 1) {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be in error ...");
|
||||
JSON_ERROR("parse : \n" << l_list[iii].m_input);
|
||||
doc.display();
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
if (false == doc.generate(out)) {
|
||||
if (l_list[iii].m_errorPos == 2) {
|
||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } generate in error (correct result)");
|
||||
} else {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } generate output might be OK");
|
||||
JSON_ERROR("generate : \n" << out);
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 2) {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Generating might be in error ...");
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_ref != out) {
|
||||
if (l_list[iii].m_errorPos == 3) {
|
||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Result in error (normal case)");
|
||||
} else {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output");
|
||||
std::vector<std::string> tmpout = etk::split(out, '\n');
|
||||
std::vector<std::string> tmpref = etk::split(l_list[iii].m_ref, '\n');
|
||||
//JSON_ERROR("generate : \n" << out);
|
||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
|
||||
if (jjj<tmpref.size()) {
|
||||
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
||||
}
|
||||
if (jjj<tmpout.size()) {
|
||||
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
|
||||
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
||||
}
|
||||
}
|
||||
}
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 3) {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR} checking result might be in error...");
|
||||
std::vector<std::string> tmpout = etk::split(out, '\n');
|
||||
std::vector<std::string> tmpref = etk::split(l_list[iii].m_ref, '\n');
|
||||
//JSON_ERROR("generate : \n" << out);
|
||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
|
||||
if (jjj<tmpref.size()) {
|
||||
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
||||
}
|
||||
if (jjj<tmpout.size()) {
|
||||
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
|
||||
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
||||
}
|
||||
}
|
||||
}
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK }");
|
||||
}
|
||||
if (countError>0) {
|
||||
JSON_ERROR("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||
} else {
|
||||
JSON_INFO("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ def create(target):
|
||||
|
||||
# add the file to compile:
|
||||
myModule.add_src_file([
|
||||
'ejson/test.cpp'])
|
||||
'test/test.cpp'])
|
||||
|
||||
myModule.add_module_depend(['ejson'])
|
||||
myModule.add_module_depend(['ejson', 'gtest'])
|
||||
|
||||
now = datetime.datetime.now()
|
||||
versionID=str(now.year-2012)+"."+str(now.month)+"."+str(now.day)
|
||||
|
54
test/test.cpp
Normal file
54
test/test.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <etk/types.h>
|
||||
#include <etk/archive/Archive.h>
|
||||
#include <ejson/debug.h>
|
||||
#include <ejson/ejson.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#include "testDocument.h"
|
||||
#include "testBoolean.h"
|
||||
#include "testNull.h"
|
||||
#include "testNumber.h"
|
||||
#include "testAll.h"
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ejson::test"
|
||||
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
// init Google test :
|
||||
::testing::InitGoogleTest(&argc, const_cast<char **>(argv));
|
||||
// the only one init for etk:
|
||||
etk::log::setLevel(etk::log::logLevelNone);
|
||||
for (int32_t iii=0; iii<argc ; ++iii) {
|
||||
std::string data = argv[iii];
|
||||
if (data == "-l0") {
|
||||
etk::log::setLevel(etk::log::logLevelNone);
|
||||
} else if (data == "-l1") {
|
||||
etk::log::setLevel(etk::log::logLevelCritical);
|
||||
} else if (data == "-l2") {
|
||||
etk::log::setLevel(etk::log::logLevelError);
|
||||
} else if (data == "-l3") {
|
||||
etk::log::setLevel(etk::log::logLevelWarning);
|
||||
} else if (data == "-l4") {
|
||||
etk::log::setLevel(etk::log::logLevelInfo);
|
||||
} else if (data == "-l5") {
|
||||
etk::log::setLevel(etk::log::logLevelDebug);
|
||||
} else if (data == "-l6") {
|
||||
etk::log::setLevel(etk::log::logLevelVerbose);
|
||||
}
|
||||
}
|
||||
etk::setArgZero(argv[0]);
|
||||
etk::initDefaultFolder("ejson_test");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
316
test/testAll.h
Normal file
316
test/testAll.h
Normal file
@ -0,0 +1,316 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_ALL_H__
|
||||
#define __EJSON_TEST_ALL_H__
|
||||
|
||||
#include "testCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(TestAll, testBaseObject) {
|
||||
std::string base = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
|
||||
static std::string refOutputAll( "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": [\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" },\n"
|
||||
" { \"value\": \"New\", \"onclick\": \"CreateNewDoc()\" },\n"
|
||||
" { \"value\": \"Open\", \"onclick\": \"OpenDoc()\" },\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
TEST(TestAll, testList) {
|
||||
localTest(refOutputAll, refOutputAll, -1);
|
||||
}
|
||||
|
||||
TEST(TestAll, testIndentedList) {
|
||||
localTest(refOutputAll,
|
||||
"{\n"
|
||||
" menu: {\n"
|
||||
" id: \"file\",\n"
|
||||
" value: \"File\",\n"
|
||||
" popup: {\n"
|
||||
" menuitem: [\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"New\",\n"
|
||||
" onclick: \"CreateNewDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Open\",\n"
|
||||
" onclick: \"OpenDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n",
|
||||
-1);
|
||||
}
|
||||
|
||||
TEST(TestAll, testIndentedListWithNoBasicObject) {
|
||||
localTest(refOutputAll,
|
||||
"menu: {\n"
|
||||
" id: \"file\",\n"
|
||||
" value: \"File\",\n"
|
||||
" popup: {\n"
|
||||
" menuitem: [\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"New\",\n"
|
||||
" onclick: \"CreateNewDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Open\",\n"
|
||||
" onclick: \"OpenDoc()\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" value: \"Close\",\n"
|
||||
" onclick: \"CloseDoc()\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
"}\n",
|
||||
-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(TestAll, testGeneric1) {
|
||||
std::string base = "{\n"
|
||||
" \"glossary\": {\n"
|
||||
" \"title\": \"example glossary\",\n"
|
||||
" \"GlossDiv\": {\n"
|
||||
" \"title\": \"S\",\n"
|
||||
" \"GlossList\": {\n"
|
||||
" \"GlossEntry\": {\n"
|
||||
" \"ID\": \"SGML\",\n"
|
||||
" \"SortAs\": \"SGML\",\n"
|
||||
" \"GlossTerm\": \"Standard Generalized Markup Language\",\n"
|
||||
" \"Acronym\": \"SGML\",\n"
|
||||
" \"Abbrev\": \"ISO 8879:1986\",\n"
|
||||
" \"GlossDef\": {\n"
|
||||
" \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n"
|
||||
" \"GlossSeeAlso\": [ \"GML\", \"XML\" ]\n"
|
||||
" },\n"
|
||||
" \"GlossSee\": \"markup\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
|
||||
TEST(TestAll, testGeneric2) {
|
||||
std::string base = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"id\": \"file\",\n"
|
||||
" \"value\": \"File\",\n"
|
||||
" \"popup\": {\n"
|
||||
" \"menuitem\": [\n"
|
||||
" { \"value\": \"New\", \"onclick\": \"CreateNewDoc()\" },\n"
|
||||
" { \"value\": \"Open\", \"onclick\": \"OpenDoc()\" },\n"
|
||||
" { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
TEST(TestAll, testGeneric3) {
|
||||
std::string base = "{\n"
|
||||
" \"widget\": {\n"
|
||||
" \"debug\": \"on\",\n"
|
||||
" \"window\": {\n"
|
||||
" \"title\": \"Sample Konfabulator Widget\",\n"
|
||||
" \"name\": \"main_window\",\n"
|
||||
" \"width\": 500,\n"
|
||||
" \"height\": 500\n"
|
||||
" },\n"
|
||||
" \"image\": {\n"
|
||||
" \"src\": \"Images/Sun.png\",\n"
|
||||
" \"name\": \"sun1\",\n"
|
||||
" \"hOffset\": 250,\n"
|
||||
" \"vOffset\": 250,\n"
|
||||
" \"alignment\": \"center\"\n"
|
||||
" },\n"
|
||||
" \"text\": {\n"
|
||||
" \"data\": \"Click Here\",\n"
|
||||
" \"size\": 36,\n"
|
||||
" \"style\": \"bold\",\n"
|
||||
" \"name\": \"text1\",\n"
|
||||
" \"hOffset\": 250,\n"
|
||||
" \"vOffset\": 100,\n"
|
||||
" \"alignment\": \"center\",\n"
|
||||
" \"onMouseUp\": \"sun1.opacity = (sun1.opacity / 100) * 90;\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
|
||||
|
||||
TEST(TestAll, testGeneric4) {
|
||||
std::string base = "{\n"
|
||||
" \"web-app\": {\n"
|
||||
" \"servlet\": [\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxCDS\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.CDSServlet\",\n"
|
||||
" \"init-param\": {\n"
|
||||
" \"configGlossary:installationAt\": \"Philadelphia, PA\",\n"
|
||||
" \"configGlossary:adminEmail\": \"ksm@pobox.com\",\n"
|
||||
" \"configGlossary:poweredBy\": \"Cofax\",\n"
|
||||
" \"configGlossary:poweredByIcon\": \"/images/cofax.gif\",\n"
|
||||
" \"configGlossary:staticPath\": \"/content/static\",\n"
|
||||
" \"templateProcessorClass\": \"org.cofax.WysiwygTemplate\",\n"
|
||||
" \"templateLoaderClass\": \"org.cofax.FilesTemplateLoader\",\n"
|
||||
" \"templatePath\": \"templates\",\n"
|
||||
" \"templateOverridePath\": \"\",\n"
|
||||
" \"defaultListTemplate\": \"listTemplate.htm\",\n"
|
||||
" \"defaultFileTemplate\": \"articleTemplate.htm\",\n"
|
||||
" \"useJSP\": false,\n"
|
||||
" \"jspListTemplate\": \"listTemplate.jsp\",\n"
|
||||
" \"jspFileTemplate\": \"articleTemplate.jsp\",\n"
|
||||
" \"cachePackageTagsTrack\": 200,\n"
|
||||
" \"cachePackageTagsStore\": 200,\n"
|
||||
" \"cachePackageTagsRefresh\": 60,\n"
|
||||
" \"cacheTemplatesTrack\": 100,\n"
|
||||
" \"cacheTemplatesStore\": 50,\n"
|
||||
" \"cacheTemplatesRefresh\": 15,\n"
|
||||
" \"cachePagesTrack\": 200,\n"
|
||||
" \"cachePagesStore\": 100,\n"
|
||||
" \"cachePagesRefresh\": 10,\n"
|
||||
" \"cachePagesDirtyRead\": 10,\n"
|
||||
" \"searchEngineListTemplate\": \"forSearchEnginesList.htm\",\n"
|
||||
" \"searchEngineFileTemplate\": \"forSearchEngines.htm\",\n"
|
||||
" \"searchEngineRobotsDb\": \"WEB-INF/robots.db\",\n"
|
||||
" \"useDataStore\": true,\n"
|
||||
" \"dataStoreClass\": \"org.cofax.SqlDataStore\",\n"
|
||||
" \"redirectionClass\": \"org.cofax.SqlRedirection\",\n"
|
||||
" \"dataStoreName\": \"cofax\",\n"
|
||||
" \"dataStoreDriver\": \"com.microsoft.jdbc.sqlserver.SQLServerDriver\",\n"
|
||||
" \"dataStoreUrl\": \"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon\",\n"
|
||||
" \"dataStoreUser\": \"sa\",\n"
|
||||
" \"dataStorePassword\": \"dataStoreTestQuery\",\n"
|
||||
" \"dataStoreTestQuery\": \"SET NOCOUNT ON;select test='test';\",\n"
|
||||
" \"dataStoreLogFile\": \"/usr/local/tomcat/logs/datastore.log\",\n"
|
||||
" \"dataStoreInitConns\": 10,\n"
|
||||
" \"dataStoreMaxConns\": 100,\n"
|
||||
" \"dataStoreConnUsageLimit\": 100,\n"
|
||||
" \"dataStoreLogLevel\": \"debug\",\n"
|
||||
" \"maxUrlLength\": 500\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxEmail\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.EmailServlet\",\n"
|
||||
" \"init-param\": { \"mailHost\": \"mail1\", \"mailHostOverride\": \"mail2\" }\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxAdmin\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cds.AdminServlet\"\n"
|
||||
" },\n"
|
||||
" { \"servlet-name\": \"fileServlet\", \"servlet-class\": \"org.cofax.cds.FileServlet\" },\n"
|
||||
" {\n"
|
||||
" \"servlet-name\": \"cofaxTools\",\n"
|
||||
" \"servlet-class\": \"org.cofax.cms.CofaxToolsServlet\",\n"
|
||||
" \"init-param\": {\n"
|
||||
" \"templatePath\": \"toolstemplates/\",\n"
|
||||
" \"log\": 1,\n"
|
||||
" \"logLocation\": \"/usr/local/tomcat/logs/CofaxTools.log\",\n"
|
||||
" \"logMaxSize\": \"\",\n"
|
||||
" \"dataLog\": 1,\n"
|
||||
" \"dataLogLocation\": \"/usr/local/tomcat/logs/dataLog.log\",\n"
|
||||
" \"dataLogMaxSize\": \"\",\n"
|
||||
" \"removePageCache\": \"/content/admin/remove?cache=pages&id=\",\n"
|
||||
" \"removeTemplateCache\": \"/content/admin/remove?cache=templates&id=\",\n"
|
||||
" \"fileTransferFolder\": \"/usr/local/tomcat/webapps/content/fileTransferFolder\",\n"
|
||||
" \"lookInContext\": 1,\n"
|
||||
" \"adminGroupID\": 4,\n"
|
||||
" \"betaServer\": true\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" ],\n"
|
||||
" \"servlet-mapping\": {\n"
|
||||
" \"cofaxCDS\": \"/\",\n"
|
||||
" \"cofaxEmail\": \"/cofaxutil/aemail/*\",\n"
|
||||
" \"cofaxAdmin\": \"/admin/*\",\n"
|
||||
" \"fileServlet\": \"/static/*\",\n"
|
||||
" \"cofaxTools\": \"/tools/*\"\n"
|
||||
" },\n"
|
||||
" \"taglib\": { \"taglib-uri\": \"cofax.tld\", \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
|
||||
|
||||
TEST(TestAll, testGeneric5) {
|
||||
std::string base = "{\n"
|
||||
" \"menu\": {\n"
|
||||
" \"header\": \"SVG Viewer\",\n"
|
||||
" \"items\": [\n"
|
||||
" { \"id\": \"Open\" },\n"
|
||||
" { \"id\": \"OpenNew\", \"label\": \"Open New\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"ZoomIn\", \"label\": \"Zoom In\" },\n"
|
||||
" { \"id\": \"ZoomOut\", \"label\": \"Zoom Out\" },\n"
|
||||
" { \"id\": \"OriginalView\", \"label\": \"Original View\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Quality\" },\n"
|
||||
" { \"id\": \"Pause\" },\n"
|
||||
" { \"id\": \"Mute\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Find\", \"label\": \"Find...\" },\n"
|
||||
" { \"id\": \"FindAgain\", \"label\": \"Find Again\" },\n"
|
||||
" { \"id\": \"Copy\" },\n"
|
||||
" { \"id\": \"CopyAgain\", \"label\": \"Copy Again\" },\n"
|
||||
" { \"id\": \"CopySVG\", \"label\": \"Copy SVG\" },\n"
|
||||
" { \"id\": \"ViewSVG\", \"label\": \"View SVG\" },\n"
|
||||
" { \"id\": \"ViewSource\", \"label\": \"View Source\" },\n"
|
||||
" { \"id\": \"SaveAs\", \"label\": \"Save As\" },\n"
|
||||
" null,\n"
|
||||
" { \"id\": \"Help\" },\n"
|
||||
" { \"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
localTest(base, base, -1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
52
test/testBoolean.h
Normal file
52
test/testBoolean.h
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_BOOLEAN_H__
|
||||
#define __EJSON_TEST_BOOLEAN_H__
|
||||
|
||||
#include "testCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
static std::string refOutputBoolean1("{\n\t\"tmpElement\": true\n}\n");
|
||||
TEST(TestBoolean, testBaseTrue) {
|
||||
localTest(refOutputBoolean1, "{ tmpElement:true }\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testTabbedTrue) {
|
||||
localTest(refOutputBoolean1, "{ \t\ntmpElement:true \t\n }\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testNoneTrue) {
|
||||
localTest(refOutputBoolean1, "tmpElement:true\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testBaseTrue1) {
|
||||
localTest(refOutputBoolean1, "{ tmpElement:TRUE }\n", 1);
|
||||
}
|
||||
TEST(TestBoolean, testBaseTrue2) {
|
||||
localTest(refOutputBoolean1, "{ tmpElement:True }\n", 1);
|
||||
}
|
||||
|
||||
|
||||
static std::string refOutputBoolean2("{\n\t\"tmpElement\": false\n}\n");
|
||||
TEST(TestBoolean, testBaseFalse) {
|
||||
localTest(refOutputBoolean2, "{ tmpElement:false }\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testTabbedFalse) {
|
||||
localTest(refOutputBoolean2, "{ \t\ntmpElement:false \t\n }\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testNoneFalse) {
|
||||
localTest(refOutputBoolean2, "tmpElement:false\n", -1);
|
||||
}
|
||||
TEST(TestBoolean, testBaseFalse1) {
|
||||
localTest(refOutputBoolean2, "{ tmpElement:FALSE }\n", 1);
|
||||
}
|
||||
TEST(TestBoolean, testBaseFalse2) {
|
||||
localTest(refOutputBoolean2, "{ tmpElement:False }\n", 1);
|
||||
}
|
||||
|
||||
#endif
|
60
test/testCommon.h
Normal file
60
test/testCommon.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_COMMON_H__
|
||||
#define __EJSON_TEST_COMMON_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ejson/debug.h>
|
||||
#include <ejson/ejson.h>
|
||||
|
||||
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
||||
static void localTest(const std::string& _ref, const std::string& _input, int32_t _errorPos) {
|
||||
ejson::Document doc;
|
||||
bool retParse = doc.parse(_input);
|
||||
if (_errorPos == 1) {
|
||||
EXPECT_EQ(retParse, false);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(retParse, true);
|
||||
}
|
||||
std::string out("");
|
||||
bool retGenerate = doc.generate(out);
|
||||
if (_errorPos == 2) {
|
||||
EXPECT_EQ(retGenerate, false);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(retGenerate, true);
|
||||
}
|
||||
if (_errorPos == 3) {
|
||||
EXPECT_NE(_ref, out);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(_ref, out);
|
||||
/*
|
||||
JSON_ERROR("[TEST] {ERROR } different output");
|
||||
std::vector<std::string> tmpout = etk::split(out, '\n');
|
||||
std::vector<std::string> tmpref = etk::split(_ref, '\n');
|
||||
//JSON_ERROR("generate : \n" << out);
|
||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
|
||||
if (jjj<tmpref.size()) {
|
||||
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
||||
}
|
||||
if (jjj<tmpout.size()) {
|
||||
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
|
||||
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
26
test/testDocument.h
Normal file
26
test/testDocument.h
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_DOCUMENT_H__
|
||||
#define __EJSON_TEST_DOCUMENT_H__
|
||||
|
||||
#include "testCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static std::string refOutputDocument("{\n}\n");
|
||||
TEST(TestDocument, testEmptyDoc) {
|
||||
localTest(refOutputDocument, "{}\n", -1);
|
||||
}
|
||||
|
||||
TEST(TestDocument, testTabbedDoc) {
|
||||
localTest(refOutputDocument, "{ \t\r }\n", -1);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
30
test/testNull.h
Normal file
30
test/testNull.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_NULL_H__
|
||||
#define __EJSON_TEST_NULL_H__
|
||||
|
||||
#include "testCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
static std::string refOutputNull("{\n\t\"tmpElement\": null\n}\n");
|
||||
TEST(TestNull, testBasicNullElement) {
|
||||
localTest(refOutputNull, "{ tmpElement:null }\n", -1);
|
||||
}
|
||||
|
||||
TEST(TestNull, testTabbedNullElement) {
|
||||
localTest(refOutputNull, "{ \t\ntmpElement:null \t\n }\n", -1);
|
||||
}
|
||||
|
||||
TEST(TestNull, testTabbedNullElementNoPThese) {
|
||||
localTest(refOutputNull, "tmpElement:null\n", -1);
|
||||
}
|
||||
|
||||
#endif
|
33
test/testNumber.h
Normal file
33
test/testNumber.h
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EJSON_TEST_NUMBER_H__
|
||||
#define __EJSON_TEST_NUMBER_H__
|
||||
|
||||
#include "testCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static std::string refOutputNumber("{\n\t\"tmpElement\": 956256\n}\n");
|
||||
TEST(TestNumber, testBase) {
|
||||
localTest(refOutputNumber, "{ tmpElement:956256 }\n", -1);
|
||||
}
|
||||
TEST(TestNumber, testTabbed) {
|
||||
localTest(refOutputNumber, "{ \t\ntmpElement:956256 \t\n }\n", -1);
|
||||
}
|
||||
TEST(TestNumber, testNone) {
|
||||
localTest(refOutputNumber, "tmpElement:956256\n", -1);
|
||||
}
|
||||
TEST(TestNumber, testNegative) {
|
||||
localTest("{\n\t\"tmpElement\": -956256\n}\n", "{tmpElement:-956256}\n", -1);
|
||||
}
|
||||
TEST(TestNumber, testFloat) {
|
||||
localTest("{\n\t\"tmpElement\": -956.256000\n}\n", "{tmpElement : -956.256}\n", -1);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user