tests: add `test_neo`
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 21 Jul 2014 14:38:42 +0000 (10:38 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 23 Jul 2014 17:08:14 +0000 (13:08 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/test_neo.nit [new file with mode: 0644]
tests/sav/test_neo.res [new file with mode: 0644]
tests/sav/test_neo_args1.res [new file with mode: 0644]
tests/test_neo.args [new file with mode: 0644]

diff --git a/src/test_neo.nit b/src/test_neo.nit
new file mode 100644 (file)
index 0000000..37adf04
--- /dev/null
@@ -0,0 +1,90 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test for neo model saving and loading.
+module test_neo
+
+import neo
+import model_utils
+import frontend
+
+var test_name = "test_{get_time.to_s}"
+
+# init tool
+var toolcontext = new ToolContext
+toolcontext.tooldescription = "Usage: neo_saver host port files..."
+toolcontext.process_options(args)
+var arguments = toolcontext.option_context.rest
+
+if arguments.length < 3 then
+       toolcontext.usage
+       exit 0
+end
+
+var host = arguments.shift
+var port = arguments.shift
+var url = "http://{host}:{port}"
+
+# parse model
+toolcontext.info("Parse files...", 1)
+var org_model = new Model
+var modelbuilder = new ModelBuilder(org_model, toolcontext)
+modelbuilder.parse(arguments)
+modelbuilder.run_phases
+
+toolcontext.info("Open connection to neo4j on {url} for saving...", 1)
+var save_client = new Neo4jClient(url)
+var save_model = new NeoModel(test_name, toolcontext, save_client)
+save_model.save(org_model)
+
+toolcontext.info("Open connection to neo4j on {url} for reading...", 1)
+var read_client = new Neo4jClient(url)
+var neo_model = new Model
+var read_model = new NeoModel(test_name, toolcontext, read_client)
+read_model.load(neo_model)
+
+# Compare model
+var sorter = new MEntityNameSorter
+
+print "mprojects:"
+var org_mprojects = org_model.mprojects.to_a
+sorter.sort org_mprojects
+print org_mprojects.join(" ")
+var neo_mprojects = neo_model.mprojects.to_a
+sorter.sort neo_mprojects
+print neo_mprojects.join(" ")
+
+print "mmodules:"
+var org_mmodules = org_model.mmodules.to_a
+sorter.sort org_mmodules
+print org_mmodules.join(" ")
+var neo_mmodules = neo_model.mmodules.to_a
+sorter.sort neo_mmodules
+print neo_mmodules.join(" ")
+
+print "mclasses:"
+var org_mclasses = org_model.mclasses.to_a
+sorter.sort org_mclasses
+print org_mclasses.join(" ")
+var neo_mclasses = neo_model.mclasses.to_a
+sorter.sort neo_mclasses
+print neo_mclasses.join(" ")
+
+print "mproperties:"
+var org_mproperties = org_model.mproperties.to_a
+sorter.sort org_mproperties
+print org_mproperties.join(" ")
+var neo_mproperties = neo_model.mproperties.to_a
+sorter.sort neo_mproperties
+print neo_mproperties.join(" ")
diff --git a/tests/sav/test_neo.res b/tests/sav/test_neo.res
new file mode 100644 (file)
index 0000000..501e8ca
--- /dev/null
@@ -0,0 +1,2 @@
+Usage: neo_saver host port files...
+Use --help for help
diff --git a/tests/sav/test_neo_args1.res b/tests/sav/test_neo_args1.res
new file mode 100644 (file)
index 0000000..8b3a417
--- /dev/null
@@ -0,0 +1,12 @@
+mprojects:
+test_prog
+test_prog
+mmodules:
+careers character combat game platform races rpg test_prog
+careers character combat game platform races rpg test_prog
+mclasses:
+Alcoholic Bool Career Character Combatable Dwarf Elf Float Game Human Int List Magician Object Race Starter String Sys Warrior Weapon
+Alcoholic Bool Career Character Combatable Dwarf Elf Float Game Human Int List Magician Object Race Starter String Sys Warrior Weapon
+mproperties:
+!= * * + + - - / / == > > OTHER _age _base_endurance _base_intelligence _base_strength _career _endurance_bonus _health _intelligence_bonus _name _race _sex _strength_bonus age age= attack base_endurance base_endurance= base_intelligence base_intelligence= base_strength base_strength= career career= computer_characters defend direct_attack dps endurance_bonus endurance_bonus= health health= hit_points init init init init init init init init init init intelligence_bonus intelligence_bonus= is_dead main max_health name name= pause_game player_characters quit race race= sex sex= start start_game stop_game strength_bonus strength_bonus= to_f total_endurance total_intelligence total_strengh unary -
+!= * * + + - - / / == > > OTHER _age _base_endurance _base_intelligence _base_strength _career _endurance_bonus _health _intelligence_bonus _name _race _sex _strength_bonus age age= attack base_endurance base_endurance= base_intelligence base_intelligence= base_strength base_strength= career career= computer_characters defend direct_attack dps endurance_bonus endurance_bonus= health health= hit_points init init init init init init init init init init intelligence_bonus intelligence_bonus= is_dead main max_health name name= pause_game player_characters quit race race= sex sex= start start_game stop_game strength_bonus strength_bonus= to_f total_endurance total_intelligence total_strengh unary -
diff --git a/tests/test_neo.args b/tests/test_neo.args
new file mode 100644 (file)
index 0000000..a1ee088
--- /dev/null
@@ -0,0 +1 @@
+localhost 7474 test_prog/test_prog.nit