From 95296e1d06327ae0f963aaeaf16380bcdbaa344e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 12 Jan 2015 21:12:44 +0100 Subject: [PATCH] [DEV] set test in gtest --- ejson/test.cpp | 569 -------------------------------------------- lutin_ejsontest.py | 4 +- test/test.cpp | 54 +++++ test/testAll.h | 316 ++++++++++++++++++++++++ test/testBoolean.h | 52 ++++ test/testCommon.h | 60 +++++ test/testDocument.h | 26 ++ test/testNull.h | 30 +++ test/testNumber.h | 33 +++ 9 files changed, 573 insertions(+), 571 deletions(-) delete mode 100644 ejson/test.cpp create mode 100644 test/test.cpp create mode 100644 test/testAll.h create mode 100644 test/testBoolean.h create mode 100644 test/testCommon.h create mode 100644 test/testDocument.h create mode 100644 test/testNull.h create mode 100644 test/testNumber.h diff --git a/ejson/test.cpp b/ejson/test.cpp deleted file mode 100644 index 3060d45..0000000 --- a/ejson/test.cpp +++ /dev/null @@ -1,569 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#include -#include -#include -#include - -#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 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 tmpout = etk::split(out, '\n'); - std::vector 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=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 tmpout = etk::split(out, '\n'); - std::vector 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=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; -} - diff --git a/lutin_ejsontest.py b/lutin_ejsontest.py index a682049..c085e3b 100644 --- a/lutin_ejsontest.py +++ b/lutin_ejsontest.py @@ -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) diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..4ce4931 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,54 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#include +#include +#include +#include +#include +#include +#include + +#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(argv)); + // the only one init for etk: + etk::log::setLevel(etk::log::logLevelNone); + for (int32_t iii=0; iii + +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 + + diff --git a/test/testBoolean.h b/test/testBoolean.h new file mode 100644 index 0000000..058709e --- /dev/null +++ b/test/testBoolean.h @@ -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 + + +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 \ No newline at end of file diff --git a/test/testCommon.h b/test/testCommon.h new file mode 100644 index 0000000..00704ea --- /dev/null +++ b/test/testCommon.h @@ -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 +#include +#include + +// _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 tmpout = etk::split(out, '\n'); + std::vector 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=tmpref.size() || tmpref[jjj] != tmpout[jjj]) { + JSON_ERROR("[" << jjj << "] " << tmpout[jjj] ); + } + } + } + */ + } +} + +#endif \ No newline at end of file diff --git a/test/testDocument.h b/test/testDocument.h new file mode 100644 index 0000000..4b5f734 --- /dev/null +++ b/test/testDocument.h @@ -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 + +static std::string refOutputDocument("{\n}\n"); +TEST(TestDocument, testEmptyDoc) { + localTest(refOutputDocument, "{}\n", -1); +} + +TEST(TestDocument, testTabbedDoc) { + localTest(refOutputDocument, "{ \t\r }\n", -1); +} + + +#endif \ No newline at end of file diff --git a/test/testNull.h b/test/testNull.h new file mode 100644 index 0000000..fd180f4 --- /dev/null +++ b/test/testNull.h @@ -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 + + +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 \ No newline at end of file diff --git a/test/testNumber.h b/test/testNumber.h new file mode 100644 index 0000000..672948b --- /dev/null +++ b/test/testNumber.h @@ -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 + +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 \ No newline at end of file