divine 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +4 -14
  2. data/README.md +25 -0
  3. data/Rakefile +34 -19
  4. data/divine.gemspec +1 -0
  5. data/lib/divine.rb +3 -1
  6. data/lib/divine/code_generators/code_generator.rb +51 -1
  7. data/lib/divine/code_generators/csharp.rb +898 -0
  8. data/lib/divine/code_generators/java.rb +125 -13
  9. data/lib/divine/code_generators/javascript.rb +111 -4
  10. data/lib/divine/code_generators/ruby.rb +103 -9
  11. data/lib/divine/dsl.rb +95 -6
  12. data/lib/divine/graph_generator/graph_generator.rb +81 -0
  13. data/lib/divine/version.rb +2 -1
  14. data/test/basic_complex_test/basic_complex_test.rb +5 -0
  15. data/test/basic_complex_test/graph.jpg +0 -0
  16. data/test/basic_complex_test/java_test/JavaTest.java +1 -1
  17. data/test/basic_complex_test/ruby_test/ruby_test.rb +17 -4
  18. data/test/binaryTree_test/binaryTree_test.rb +5 -0
  19. data/test/binaryTree_test/csharp_test/csharp_test.cs +99 -0
  20. data/test/binaryTree_test/graph.png +0 -0
  21. data/test/binaryTree_test/java_test/JavaTest.java +1 -1
  22. data/test/binaryTree_test/ruby_test/ruby_test.rb +26 -3
  23. data/test/complex_test/complex_test.rb +5 -0
  24. data/test/complex_test/csharp_test/csharp_test.cs +109 -0
  25. data/test/complex_test/graph.png +0 -0
  26. data/test/complex_test/java_test/JavaTest.java +1 -1
  27. data/test/complex_test/ruby_test/ruby_test.rb +24 -1
  28. data/test/dynamic_int_test/csharp_test/csharp_test.cs +76 -0
  29. data/test/dynamic_int_test/dynamic_int_test.rb +20 -0
  30. data/test/dynamic_int_test/graph.jpg +0 -0
  31. data/test/dynamic_int_test/java_test/JavaTest.java +72 -0
  32. data/test/dynamic_int_test/js_test/js_test.js +54 -0
  33. data/test/dynamic_int_test/ruby_test/ruby_test.rb +55 -0
  34. data/test/ipv6_test/csharp_test/csharp_test.cs +73 -0
  35. data/test/ipv6_test/graph.jpg +0 -0
  36. data/test/ipv6_test/ipv6_test.rb +5 -0
  37. data/test/ipv6_test/java_test/JavaTest.java +1 -1
  38. data/test/ipv6_test/ruby_test/ruby_test.rb +24 -4
  39. data/test/lib/csharp/nunit.framework.dll +0 -0
  40. data/test/{java_lib → lib/java}/junit.jar +0 -0
  41. data/test/signed_int_test/csharp_test/csharp_test.cs +86 -0
  42. data/test/signed_int_test/graph.jpg +0 -0
  43. data/test/signed_int_test/java_test/JavaTest.java +1 -1
  44. data/test/signed_int_test/ruby_test/ruby_test.rb +21 -1
  45. data/test/signed_int_test/signed_int_test.rb +6 -0
  46. data/test/unify_test/unify_test.rb +17 -4
  47. metadata +54 -8
  48. data/test/signed_float_test/ruby_test/ruby_test.rb +0 -36
  49. data/test/signed_float_test/signed_float_test.rb +0 -14
@@ -0,0 +1,54 @@
1
+ eval(require('fs').readFileSync('test/dynamic_int_test/js_test/test_dynamic_int.js', 'utf8'));
2
+ var fs = require('fs');
3
+ var assert = require('assert');
4
+
5
+ console.log("Test Dynamic Int");
6
+
7
+ var obj_ser = buildObject();
8
+
9
+ var ca = obj_ser.serialize();
10
+ serialize(ca);
11
+ var read = deserialize();
12
+
13
+ var obj_deser = new DynamicInt();
14
+ obj_deser.deserialize(new DivineDataReader(read));
15
+ compare_list(obj_ser.list1, obj_deser.list1);
16
+
17
+
18
+ function buildObject(){
19
+ var obj = new DynamicInt();
20
+ obj.list1 = [127, 16383, 2097151, 268435455, 34359738367, 4398046511103, 562949953421311]//, 9007199254740991];
21
+ return obj;
22
+ }
23
+
24
+ function compare_list(lst_1, lst_2){
25
+ assert.equal(lst_1.length, lst_2.length)
26
+ for (var i = 0; i < lst_1.length; i++){
27
+ //console.log("Ser = " + lst_1[i] + ", Deser = " + lst_2[i]);
28
+ assert.equal(lst_1[i], lst_2[i]);
29
+ }
30
+ }
31
+
32
+ function serialize(obj){
33
+ var bBuffer = new Buffer(obj);
34
+ fs.writeFileSync(__dirname + '/bin.babel.js', bBuffer, function (err) {
35
+ if (err) {
36
+ return console.log(err);
37
+ }
38
+ });
39
+ }
40
+
41
+ function deserialize(){
42
+ var data = fs.readFileSync(__dirname + '/bin.babel.js');
43
+ data = toArray(data);
44
+ return data;
45
+
46
+ }
47
+
48
+ function toArray(buffer) {
49
+ var view = new Uint8Array(buffer.length);
50
+ for (var i = 0; i < buffer.length; ++i) {
51
+ view[i] = buffer[i];
52
+ }
53
+ return view;
54
+ }
@@ -0,0 +1,55 @@
1
+ require_relative 'test_dynamic_int.rb'
2
+ require 'minitest/autorun'
3
+
4
+ #
5
+ # Responsible for testing dynamic integer data types
6
+ #
7
+ class TestDynamicInteger < MiniTest::Unit::TestCase
8
+
9
+ #
10
+ # Compare objects after serialize and deserialize operations
11
+ #
12
+ def test_signedInt
13
+ puts "Test Dynamic Int"
14
+ obj_ser = BabelTest::DynamicInt.new
15
+ obj_ser.list1 = [127, 16383, 2097151, 268435455, 34359738367, 4398046511103, 562949953421311]#, 72057594037927935, 9223372036854775807]
16
+
17
+ ser = obj_ser.serialize
18
+ serialize(ser)
19
+ res = deserialize()
20
+
21
+ obj_deser = BabelTest::DynamicInt.new
22
+ obj_deser.deserialize res
23
+ compare(obj_ser, obj_deser)
24
+ end
25
+
26
+ #
27
+ # Make sure that the comming two objects are the same
28
+ # * *Args* :
29
+ # -obj_ser- --> original object
30
+ # -obj_deser- --> obtained object after serialize and deserialize operations
31
+ #
32
+ def compare(obj_ser, obj_deser)
33
+ #puts "Ser = #{obj_ser.list1}, Deser = #{obj_deser.list1}"
34
+ assert_equal obj_ser.list1, obj_deser.list1
35
+ end
36
+
37
+ #
38
+ # Write binary data to file
39
+ # * *Args* :
40
+ # -data- --> bytes to be written
41
+ #
42
+ def serialize(data)
43
+ File.open("test/dynamic_int_test/ruby_test/bin.babel.rb", "w+b") do |f|
44
+ f.write(data)
45
+ end
46
+ end
47
+
48
+ #
49
+ # Read file in binary mode and return its bytes content
50
+ #
51
+ def deserialize()
52
+ mem_buf = File.new('test/dynamic_int_test/ruby_test/bin.babel.rb').binmode
53
+ end
54
+
55
+ end
@@ -0,0 +1,73 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Text;
4
+ using System.IO;
5
+ using divine;
6
+ using NUnit.Framework;
7
+
8
+ namespace test_signed_int
9
+ {
10
+ [TestFixture]
11
+ class divine
12
+ {
13
+ [Test]
14
+ public static void Main(String[] args)
15
+ {
16
+ System.Console.Write("Test IPv6 \n");
17
+ IPV6 ser = buildObj();
18
+ serialize(ser);
19
+ byte[] res = deserialize();
20
+
21
+ IPV6 deser = new IPV6();
22
+ deser.deserialize(new MemoryStream(res));
23
+
24
+ compare(ser, deser);
25
+ }
26
+
27
+ public static IPV6 buildObj() {
28
+ IPV6 obj = new IPV6();
29
+ obj.list1.Add("255.102.0.25");
30
+ obj.list1.Add("ff:fabf:faf:f15f:f1ff:f2f:1f:f2");
31
+ obj.list1.Add("2001:db8::ff00:1:8329");
32
+ obj.list1.Add("f::");
33
+ obj.list1.Add("::1");
34
+ obj.list1.Add("");
35
+ return obj;
36
+ }
37
+
38
+ public static void compare(IPV6 obj1, IPV6 obj2)
39
+ {
40
+ for (int i = 0; i < obj1.list1.Count; i++)
41
+ {
42
+ //System.Console.Write("Ser = " + obj1.list1[i] + ", Deser = " + obj2.list1[i] + "\n");
43
+ Assert.AreEqual(obj1.list1[i].ToLower(), obj2.list1[i].ToLower());
44
+ }
45
+ }
46
+
47
+ public static void serialize(Divine obj)
48
+ {
49
+ try
50
+ {
51
+ byte[] data = obj.serialize();
52
+ File.WriteAllBytes("test/ipv6_test/csharp_test/bin.babel.csharp", data);
53
+ }
54
+ catch (System.IO.IOException ex)
55
+ {
56
+ throw ex;
57
+ }
58
+ }
59
+
60
+ public static byte[] deserialize(){
61
+ try
62
+ {
63
+ byte[] data = File.ReadAllBytes("test/ipv6_test/csharp_test/bin.babel.csharp");
64
+ return data;
65
+ }
66
+ catch (System.IO.IOException ex)
67
+ {
68
+ throw ex;
69
+ }
70
+ }
71
+
72
+ }
73
+ }
Binary file
@@ -5,10 +5,15 @@ struct 'IPV6' do
5
5
  list :list1, :ip_number
6
6
  end
7
7
 
8
+ # Draw ERD for prev. structs
9
+ Divine::GraphGenerator.new.draw("test/ipv6_test/")
10
+
8
11
  if ARGV[0] == "ruby"
9
12
  Divine::CodeGenerator.new.generate(:ruby, file: 'test_ipv6.rb', module: 'BabelTest', parent_class: "Object", target_dir: "test/ipv6_test/ruby_test")
10
13
  elsif ARGV[0] == "js"
11
14
  Divine::CodeGenerator.new.generate(:javascript, file: 'test_ipv6.js', target_dir: "test/ipv6_test/js_test")
12
15
  elsif ARGV[0] == "java"
13
16
  Divine::CodeGenerator.new.generate(:java, file: 'test_ipv6.java', target_dir: "test/ipv6_test/java_test")
17
+ elsif ARGV[0] == "csharp"
18
+ Divine::CodeGenerator.new.generate(:csharp, file: 'test_ipv6.cs', target_dir: "test/ipv6_test/csharp_test")
14
19
  end
@@ -51,7 +51,7 @@ public class JavaTest {
51
51
  org.junit.Assert.assertEquals(obj1.list1.get(1), obj2.list1.get(1));
52
52
  }
53
53
 
54
- public void serialize(BabelBase obj) throws IOException {
54
+ public void serialize(Divine obj) throws IOException {
55
55
  byte[] data = obj.serialize();
56
56
  File file = new File("test/ipv6_test/java_test/bin.babel");
57
57
  try {
@@ -1,10 +1,16 @@
1
1
  require_relative 'test_ipv6.rb'
2
2
  require 'minitest/autorun'
3
3
 
4
- class TestBabelTestBasic < MiniTest::Unit::TestCase
5
-
6
- def test_ipv6
7
- puts "Test IPv6"
4
+ #
5
+ # Responsible for testing IP data types
6
+ #
7
+ class TestIP < MiniTest::Unit::TestCase
8
+
9
+ #
10
+ # Compare objects after serialize and deserialize operations
11
+ #
12
+ def test_ip
13
+ puts "Test IP"
8
14
  obj_ser = BabelTest::IPV6.new
9
15
  obj_ser.list1 = ["255.102.0.25","ff:fabf:faf:f15f:f1ff:f2f:1f:f2","2001:db8::ff00:1:8329","f::","::1",""]
10
16
 
@@ -25,16 +31,30 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
25
31
 
26
32
  end
27
33
 
34
+ #
35
+ # Make sure that the comming two objects are the same
36
+ # * *Args* :
37
+ # -obj_ser- --> original object
38
+ # -obj_deser- --> obtained object after serialize and deserialize operations
39
+ #
28
40
  def compare(obj_ser, obj_deser)
29
41
  assert_equal obj_ser.list1, obj_deser.list1
30
42
  end
31
43
 
44
+ #
45
+ # Write binary data to file
46
+ # * *Args* :
47
+ # -data- --> bytes to be written
48
+ #
32
49
  def serialize(data)
33
50
  File.open("test/ipv6_test/ruby_test/bin.babel.rb", "w+b") do |f|
34
51
  f.write(data)
35
52
  end
36
53
  end
37
54
 
55
+ #
56
+ # Read file in binary mode and return its bytes content
57
+ #
38
58
  def deserialize()
39
59
  mem_buf = File.new('test/ipv6_test/ruby_test/bin.babel.rb').binmode
40
60
  end
File without changes
@@ -0,0 +1,86 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Text;
4
+ using System.IO;
5
+ using divine;
6
+ using NUnit.Framework;
7
+
8
+ namespace test_signed_int
9
+ {
10
+ [TestFixture]
11
+ class divine
12
+ {
13
+ [Test]
14
+ public static void Main(String[] args)
15
+ {
16
+ System.Console.Write("Test Signed Int \n");
17
+ SignedInt ser = buildObj();
18
+ serialize(ser);
19
+ byte[] res = deserialize();
20
+
21
+ SignedInt deser = new SignedInt();
22
+ deser.deserialize(new MemoryStream(res));
23
+
24
+ compare(ser, deser);
25
+
26
+ //System.Console.Read();
27
+
28
+ }
29
+
30
+ public static SignedInt buildObj() {
31
+ SignedInt obj = new SignedInt();
32
+ obj.list1.Add(-1);
33
+ obj.list1.Add(-2);
34
+ obj.list1.Add(-3);
35
+ obj.list1.Add(int.MaxValue);
36
+ obj.list1.Add(int.MinValue);
37
+
38
+ obj.list2.Add(-1);
39
+ obj.list2.Add(-2);
40
+ obj.list2.Add(-3);
41
+ obj.list2.Add( (long) Math.Pow(2, 53) -1 );
42
+ obj.list2.Add( (long) (Math.Pow(2, 53) - Math.Pow(2, 54)) );
43
+ return obj;
44
+ }
45
+
46
+ public static void compare(SignedInt obj1, SignedInt obj2)
47
+ {
48
+ for (int i = 0; i < obj1.list1.Count; i++)
49
+ {
50
+ //System.Console.Write("Ser = " + obj1.list1[i] + ", Deser = " + obj2.list1[i] + "\n");
51
+ Assert.AreEqual(obj1.list1[i], obj2.list1[i]);
52
+ }
53
+ for (int i = 0; i < obj1.list2.Count; i++)
54
+ {
55
+ //System.Console.Write("Ser = " + obj1.list2[i] + ", Deser = " + obj2.list2[i] + "\n");
56
+ Assert.AreEqual(obj1.list2[i], obj2.list2[i]);
57
+ }
58
+ }
59
+
60
+ public static void serialize(Divine obj)
61
+ {
62
+ try
63
+ {
64
+ byte[] data = obj.serialize();
65
+ File.WriteAllBytes("test/signed_int_test/csharp_test/bin.babel.csharp", data);
66
+ }
67
+ catch (System.IO.IOException ex)
68
+ {
69
+ throw ex;
70
+ }
71
+ }
72
+
73
+ public static byte[] deserialize(){
74
+ try
75
+ {
76
+ byte[] data = File.ReadAllBytes("test/signed_int_test/csharp_test/bin.babel.csharp");
77
+ return data;
78
+ }
79
+ catch (System.IO.IOException ex)
80
+ {
81
+ throw ex;
82
+ }
83
+ }
84
+
85
+ }
86
+ }
@@ -59,7 +59,7 @@ public class JavaTest {
59
59
  }
60
60
  }
61
61
 
62
- public void serialize(BabelBase obj) throws IOException {
62
+ public void serialize(Divine obj) throws IOException {
63
63
  byte[] data = obj.serialize();
64
64
  File file = new File("test/signed_int_test/java_test/bin.babel");
65
65
  try {
@@ -1,8 +1,14 @@
1
1
  require_relative 'test_signed_int.rb'
2
2
  require 'minitest/autorun'
3
3
 
4
+ #
5
+ # Responsible for testing signed integer data types
6
+ #
4
7
  class TestBabelTestBasic < MiniTest::Unit::TestCase
5
8
 
9
+ #
10
+ # Compare objects after serialize and deserialize operations
11
+ #
6
12
  def test_signedInt
7
13
  puts "Test Signed Int"
8
14
  obj_ser = BabelTest::SignedInt.new
@@ -19,17 +25,31 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
19
25
 
20
26
  end
21
27
 
28
+ #
29
+ # Make sure that the comming two objects are the same
30
+ # * *Args* :
31
+ # -obj_ser- --> original object
32
+ # -obj_deser- --> obtained object after serialize and deserialize operations
33
+ #
22
34
  def compare(obj_ser, obj_deser)
23
35
  #puts "Ser = #{obj_ser.list1}, Deser = #{obj_deser.list1}"
24
36
  assert_equal obj_ser.list1, obj_deser.list1
25
37
  end
26
38
 
39
+ #
40
+ # Write binary data to file
41
+ # * *Args* :
42
+ # -data- --> bytes to be written
43
+ #
27
44
  def serialize(data)
28
45
  File.open("test/signed_int_test/ruby_test/bin.babel.rb", "w+b") do |f|
29
46
  f.write(data)
30
47
  end
31
48
  end
32
-
49
+
50
+ #
51
+ # Read file in binary mode and return its bytes content
52
+ #
33
53
  def deserialize()
34
54
  mem_buf = File.new('test/signed_int_test/ruby_test/bin.babel.rb').binmode
35
55
  end
@@ -6,10 +6,16 @@ struct 'SignedInt' do
6
6
  list :list2, :sint64
7
7
  end
8
8
 
9
+ # Draw ERD for prev. struct
10
+ Divine::GraphGenerator.new.draw("test/signed_int_test/")
11
+
9
12
  if ARGV[0] == "ruby"
10
13
  Divine::CodeGenerator.new.generate(:ruby, file: 'test_signed_int.rb', module: 'BabelTest', parent_class: "Object", target_dir: "test/signed_int_test/ruby_test")
11
14
  elsif ARGV[0] == "js"
12
15
  Divine::CodeGenerator.new.generate(:javascript, file: 'test_signed_int.js', target_dir: "test/signed_int_test/js_test")
13
16
  elsif ARGV[0] == "java"
14
17
  Divine::CodeGenerator.new.generate(:java, file: 'test_signed_int.java', target_dir: "test/signed_int_test/java_test")
18
+ elsif ARGV[0] == "csharp"
19
+ Divine::CodeGenerator.new.generate(:csharp, file: 'test_signed_int.cs', target_dir: "test/signed_int_test/csharp_test")
20
+
15
21
  end
@@ -1,25 +1,38 @@
1
1
  require 'minitest/autorun'
2
2
 
3
+ #
4
+ # Responsible for equality testing to the produced byte files for all languages
5
+ #
3
6
  class TestUnify < MiniTest::Unit::TestCase
4
7
 
8
+ #
9
+ # Make sure that the produced byte files from all languages in every test are the same.
10
+ #
5
11
  def test_unify
6
12
  puts "Unify Test: Compare the produced binary files"
7
13
  paths = [
8
14
  "test/binaryTree_test/",
9
15
  "test/complex_test/",
10
16
  "test/ipv6_test/",
11
- "test/signed_int_test/"
17
+ "test/signed_int_test/",
18
+ "test/dynamic_int_test/"
12
19
  ]
13
20
  paths.each do |path|
14
- ruby = readFile("#{path}ruby_test/bin.babel.rb")
15
- js = readFile("#{path}js_test/bin.babel.js")
16
- java = readFile("#{path}java_test/bin.babel")
21
+ ruby = readFile("#{path}ruby_test/bin.babel.rb")
22
+ js = readFile("#{path}js_test/bin.babel.js")
23
+ java = readFile("#{path}java_test/bin.babel")
24
+ csharp = readFile("#{path}csharp_test/bin.babel.csharp")
17
25
 
18
26
  assert_equal ruby, js
19
27
  assert_equal ruby, java
28
+ assert_equal ruby, csharp
20
29
  end
21
30
  end
22
31
 
32
+ #
33
+ # Read certain file in binary mode and return its content bytes
34
+ # * *Args* :
35
+ # - +file+ -> path to file name
23
36
  def readFile(file)
24
37
  data = File.new(file).binmode
25
38
  data.read(data.size).each_byte.to_a