test/metamodel_roundtrip_test.rb in rgen-0.5.1 vs test/metamodel_roundtrip_test.rb in rgen-0.5.2
- old
+ new
@@ -5,11 +5,11 @@
require 'rgen/model_comparator'
require 'mmgen/metamodel_generator'
require 'rgen/instantiator/ecore_xml_instantiator'
require 'rgen/serializer/xmi20_serializer'
-class MetamodelGeneratorTest < Test::Unit::TestCase
+class MetamodelRoundtripTest < Test::Unit::TestCase
TEST_DIR = File.dirname(__FILE__)+"/metamodel_roundtrip_test"
include MMGen::MetamodelGenerator
include RGen::ModelComparator
@@ -55,7 +55,41 @@
File.open(TEST_DIR+"/houseMetamodel_Regenerated.ecore","w") do |f|
ser = RGen::Serializer::XMI20Serializer.new(f)
ser.serialize(HouseMetamodel.ecore)
end
end
-
-end
\ No newline at end of file
+
+ BuiltinTypesTestEcore = TEST_DIR+"/using_builtin_types.ecore"
+
+ def test_ecore_serializer_builtin_types
+ mm = RGen::ECore::EPackage.new(:name => "P1", :eClassifiers => [
+ RGen::ECore::EClass.new(:name => "C1", :eStructuralFeatures => [
+ RGen::ECore::EAttribute.new(:name => "a1", :eType => RGen::ECore::EString),
+ RGen::ECore::EAttribute.new(:name => "a2", :eType => RGen::ECore::EInt),
+ RGen::ECore::EAttribute.new(:name => "a3", :eType => RGen::ECore::EFloat),
+ RGen::ECore::EAttribute.new(:name => "a4", :eType => RGen::ECore::EBoolean)
+ ])
+ ])
+ outfile = TEST_DIR+"/using_builtin_types_serialized.ecore"
+ File.open(outfile, "w") do |f|
+ ser = RGen::Serializer::XMI20Serializer.new(f)
+ ser.serialize(mm)
+ end
+ assert_equal(File.read(BuiltinTypesTestEcore), File.read(outfile))
+ end
+
+ def test_ecore_instantiator_builtin_types
+ env = RGen::Environment.new
+ File.open(BuiltinTypesTestEcore) { |f|
+ ECoreXMLInstantiator.new(env).instantiate(f.read)
+ }
+ a1 = env.find(:class => RGen::ECore::EAttribute, :name => "a1").first
+ assert_equal(RGen::ECore::EString, a1.eType)
+ a2 = env.find(:class => RGen::ECore::EAttribute, :name => "a2").first
+ assert_equal(RGen::ECore::EInt, a2.eType)
+ a3 = env.find(:class => RGen::ECore::EAttribute, :name => "a3").first
+ assert_equal(RGen::ECore::EFloat, a3.eType)
+ a4 = env.find(:class => RGen::ECore::EAttribute, :name => "a4").first
+ assert_equal(RGen::ECore::EBoolean, a4.eType)
+ end
+
+end