From de347f6c9885ca330a4092b688726d41c48dc807 Mon Sep 17 00:00:00 2001 From: jvelilla Date: Sat, 24 May 2008 15:04:36 +0000 Subject: [PATCH] eJson tests initial import --- json_test/application.e | 162 ++++++++++++++++++++++++++++ json_test/json_glossary_example.txt | 22 ++++ json_test/json_menu2_example.txt | 27 +++++ json_test/json_menu_example.txt | 11 ++ json_test/json_test.ecf | 24 +++++ json_test/json_webxml_example.txt | 88 +++++++++++++++ json_test/json_widget_example.txt | 26 +++++ json_test/test_json_parser.e | 160 +++++++++++++++++++++++++++ json_test/test_json_reader.e | 41 +++++++ 9 files changed, 561 insertions(+) create mode 100644 json_test/application.e create mode 100644 json_test/json_glossary_example.txt create mode 100644 json_test/json_menu2_example.txt create mode 100644 json_test/json_menu_example.txt create mode 100644 json_test/json_test.ecf create mode 100644 json_test/json_webxml_example.txt create mode 100644 json_test/json_widget_example.txt create mode 100644 json_test/test_json_parser.e create mode 100644 json_test/test_json_reader.e diff --git a/json_test/application.e b/json_test/application.e new file mode 100644 index 00000000..05f1b16d --- /dev/null +++ b/json_test/application.e @@ -0,0 +1,162 @@ +indexing + description : "System's root class" + date: "$Date$" + revision: "$Revision$" + +class + APPLICATION + +create + make + +feature -- Initialization + + make is + -- Run application. + do + print ("JSON OBJECT%N") + test_json_object + + print ("%NJSON STRING%N") + test_json_string + + print ("%NJSON NUMBER%N") + test_json_number + + print ("%NJSON NULL%N") + test_json_null + + print ("%NJSON BOOLEAN%N") + test_json_boolean + + print ("%NJSON ARRAY%N") + test_json_array + + print ("%NJSON READER%N") + test_json_reader + + print ("%NJSON PARSER%N") + test_json_parser + + end + + test_json_object is + -- + local + jo:JSON_OBJECT + do + create jo.make + jo.put (create {JSON_STRING}.make_json("myKey"), create {JSON_STRING}.make_json ("MyValue")) + print (jo.to_json) + end + + test_json_string is + -- + local + js:JSON_STRING + do + create js.make_json ("Json String example") + print (js.to_json) + end + + test_json_number is + -- + local + jnr,jni:JSON_NUMBER + do + create jnr.make_real (12.3) + print (jnr.to_json) + print ("%N") + create jni.make_integer (123) + print (jni.to_json) + + + end + + + test_json_null is + -- + local + jnull:JSON_NULL + do + + create jnull + print (jnull.to_json) + + end + + test_json_boolean is + -- + local + jbt,jbf:JSON_BOOLEAN + do + create jbt.make_boolean (true) + print (jbt.to_json) + + print ("%N") + create jbf.make_boolean (false) + print (jbf.to_json) + + end + + + test_json_array is + -- + local + ja:JSON_ARRAY + + jo: JSON_OBJECT + do + create ja.make_array + ja.add (create{JSON_STRING}.make_json ("valor1")) + ja.add (create{JSON_NUMBER}.make_integer (10)) + ja.add (create{JSON_NULL} ) + ja.add (create{JSON_BOOLEAN}.make_boolean (true)) + + create jo.make + jo.put (create {JSON_STRING}.make_json("myKey"), create {JSON_STRING}.make_json ("MyValue")) + + ja.add (jo) + print (ja.to_json) + + end + + test_json_reader is + -- + local + jr:EXAMPLE_JSON_READER + do + create jr.make + jr.test_create_reader + end + + test_json_parser is + -- + local + jp:EXAMPLE_JSON_PARSER + do + create jp + print("%N ARRAY PARSING %N") + jp.test_json_array + + print("%N GLOSSATY PARSING %N") + jp.test_json_glossary_from_file + + print("%N NUMBER PARSING %N") + jp.test_json_number + + print("%N OBJECTS PARSING %N") + jp.test_json_objects_with_string + + print("%N STRING PARSING %N") + jp.test_json_string + + + + + end + + + + +end -- class APPLICATION diff --git a/json_test/json_glossary_example.txt b/json_test/json_glossary_example.txt new file mode 100644 index 00000000..d6e6ca15 --- /dev/null +++ b/json_test/json_glossary_example.txt @@ -0,0 +1,22 @@ +{ + "glossary": { + "title": "example glossary", + "GlossDiv": { + "title": "S", + "GlossList": { + "GlossEntry": { + "ID": "SGML", + "SortAs": "SGML", + "GlossTerm": "Standard Generalized Markup Language", + "Acronym": "SGML", + "Abbrev": "ISO 8879:1986", + "GlossDef": { + "para": "A meta-markup language, used to create markup languages such as DocBook.", + "GlossSeeAlso": ["GML", "XML"] + }, + "GlossSee": "markup" + } + } + } + } +} \ No newline at end of file diff --git a/json_test/json_menu2_example.txt b/json_test/json_menu2_example.txt new file mode 100644 index 00000000..539c3af2 --- /dev/null +++ b/json_test/json_menu2_example.txt @@ -0,0 +1,27 @@ +{"menu": { + "header": "SVG Viewer", + "items": [ + {"id": "Open"}, + {"id": "OpenNew", "label": "Open New"}, + null, + {"id": "ZoomIn", "label": "Zoom In"}, + {"id": "ZoomOut", "label": "Zoom Out"}, + {"id": "OriginalView", "label": "Original View"}, + null, + {"id": "Quality"}, + {"id": "Pause"}, + {"id": "Mute"}, + null, + {"id": "Find", "label": "Find..."}, + {"id": "FindAgain", "label": "Find Again"}, + {"id": "Copy"}, + {"id": "CopyAgain", "label": "Copy Again"}, + {"id": "CopySVG", "label": "Copy SVG"}, + {"id": "ViewSVG", "label": "View SVG"}, + {"id": "ViewSource", "label": "View Source"}, + {"id": "SaveAs", "label": "Save As"}, + null, + {"id": "Help"}, + {"id": "About", "label": "About Adobe CVG Viewer..."} + ] +}} \ No newline at end of file diff --git a/json_test/json_menu_example.txt b/json_test/json_menu_example.txt new file mode 100644 index 00000000..bce42e86 --- /dev/null +++ b/json_test/json_menu_example.txt @@ -0,0 +1,11 @@ +{"menu": { + "id": "file", + "value": "File", + "popup": { + "menuitem": [ + {"value": "New", "onclick": "CreateNewDoc()"}, + {"value": "Open", "onclick": "OpenDoc()"}, + {"value": "Close", "onclick": "CloseDoc()"} + ] + } +}} \ No newline at end of file diff --git a/json_test/json_test.ecf b/json_test/json_test.ecf new file mode 100644 index 00000000..acc7b2b2 --- /dev/null +++ b/json_test/json_test.ecf @@ -0,0 +1,24 @@ + + + + + + + + + + + + /EIFGENs$ + /.svn$ + /CVS$ + /cdd_tests$ + + + + + + + diff --git a/json_test/json_webxml_example.txt b/json_test/json_webxml_example.txt new file mode 100644 index 00000000..ee7b0f8b --- /dev/null +++ b/json_test/json_webxml_example.txt @@ -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"}}} \ No newline at end of file diff --git a/json_test/json_widget_example.txt b/json_test/json_widget_example.txt new file mode 100644 index 00000000..f9a37125 --- /dev/null +++ b/json_test/json_widget_example.txt @@ -0,0 +1,26 @@ +{"widget": { + "debug": "on", + "window": { + "title": "Sample Konfabulator Widget", + "name": "main_window", + "width": 500, + "height": 500 + }, + "image": { + "src": "Images/Sun.png", + "name": "sun1", + "hOffset": 250, + "vOffset": 250, + "alignment": "center" + }, + "text": { + "data": "Click Here", + "size": 36, + "style": "bold", + "name": "text1", + "hOffset": 250, + "vOffset": 100, + "alignment": "center", + "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" + } +}} \ No newline at end of file diff --git a/json_test/test_json_parser.e b/json_test/test_json_parser.e new file mode 100644 index 00000000..9284f4e3 --- /dev/null +++ b/json_test/test_json_parser.e @@ -0,0 +1,160 @@ +indexing + description: "Objects that ..." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + EXAMPLE_JSON_PARSER + +feature -- Access + + test_json_string is + -- + local + parse_json:JSON_PARSER + json_value:JSON_VALUE + do + create parse_json.make_parser("%"key %N This is a test %"") + json_value:=parse_json.parse + print (json_value.to_json) + end + + test_json_objects_with_string is + -- + local + parse_json:JSON_PARSER + json_value:JSON_VALUE + do + create parse_json.make_parser("{}") + json_value:=parse_json.parse + print (json_value.to_json) + + create parse_json.make_parser("{%"key%":%"value%"}") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser("{%"key%" :%"value%"}") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser("{%"key%" : %"value%"}") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser("{%"key%" : %"value%" }") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser("{ %N%"key%" : %"value%" }") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser("{ %N%"key%" ; %"value%" }") + json_value:=parse_json.parse + print (json_value.to_json) + + end + + test_json_array is + -- + local + parse_json:JSON_PARSER + json_value:JSON_VALUE + do + create parse_json.make_parser ("[]") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser ("[%"value%"]") + json_value:=parse_json.parse + print (json_value.to_json) + + create parse_json.make_parser ("[%"value%",%"value2%"]") + json_value:=parse_json.parse + print (json_value.to_json) + + --create parse_json.make_parser ("[%"value%";%"value2%"]") + --json_value:=parse_json.parse + --print (json_value.to_json) + + + create parse_json.make_parser ("[null]") + json_value:=parse_json.parse + print (json_value.to_json) + + create parse_json.make_parser ("[false]") + json_value:=parse_json.parse + print (json_value.to_json) + + create parse_json.make_parser ("[true]") + json_value:=parse_json.parse + print (json_value.to_json) + + end + + test_json_number is + -- + local + parse_json:JSON_PARSER + json_value:JSON_VALUE + do + create parse_json.make_parser ("1234.5") + json_value:=parse_json.parse + print (json_value.to_json) + + + create parse_json.make_parser ("1234.e5") + json_value:=parse_json.parse + print (json_value.to_json) + end + + test_json_glossary_from_file is + -- + local + file_reader:JSON_FILE_READER + parse_json:JSON_PARSER + json_value:JSON_VALUE + + do + + create file_reader + create parse_json.make_parser (file_reader.read_json_from ("./json_glossary_example.txt")) + json_value:=parse_json.parse + print (json_value.to_json) + + + print ("%N JSON MENU %N") + create parse_json.make_parser (file_reader.read_json_from ("./json_menu_example.txt")) + json_value:=parse_json.parse + print (json_value.to_json) + + print ("%N JSON WIDGET %N") + create parse_json.make_parser (file_reader.read_json_from ("./json_widget_example.txt")) + json_value:=parse_json.parse + print (json_value.to_json) + + + print ("%N JSON WEBXML %N") + create parse_json.make_parser (file_reader.read_json_from ("./json_webxml_example.txt")) + json_value:=parse_json.parse + print (json_value.to_json) + + print ("%N JSON MENU2 %N") + create parse_json.make_parser (file_reader.read_json_from ("./json_menu2_example.txt")) + json_value:=parse_json.parse + print (json_value.to_json) + + + + + end + + +end diff --git a/json_test/test_json_reader.e b/json_test/test_json_reader.e new file mode 100644 index 00000000..2eac2741 --- /dev/null +++ b/json_test/test_json_reader.e @@ -0,0 +1,41 @@ +indexing + description: "Objects that ..." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + EXAMPLE_JSON_READER + +create + make +feature -- Access + make is + -- + do + test_create_reader + end + + test_create_reader is + -- + local + reader:JSON_READER + condition:BOOLEAN + do + create reader.make("{%"key%":%"value%"}") + + from + condition:=false + until condition + + loop + if reader.has_next then + print (reader.read) + reader.next + else + condition:=true + end + end + end + +end