divine 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -14
- data/README.md +25 -0
- data/Rakefile +34 -19
- data/divine.gemspec +1 -0
- data/lib/divine.rb +3 -1
- data/lib/divine/code_generators/code_generator.rb +51 -1
- data/lib/divine/code_generators/csharp.rb +898 -0
- data/lib/divine/code_generators/java.rb +125 -13
- data/lib/divine/code_generators/javascript.rb +111 -4
- data/lib/divine/code_generators/ruby.rb +103 -9
- data/lib/divine/dsl.rb +95 -6
- data/lib/divine/graph_generator/graph_generator.rb +81 -0
- data/lib/divine/version.rb +2 -1
- data/test/basic_complex_test/basic_complex_test.rb +5 -0
- data/test/basic_complex_test/graph.jpg +0 -0
- data/test/basic_complex_test/java_test/JavaTest.java +1 -1
- data/test/basic_complex_test/ruby_test/ruby_test.rb +17 -4
- data/test/binaryTree_test/binaryTree_test.rb +5 -0
- data/test/binaryTree_test/csharp_test/csharp_test.cs +99 -0
- data/test/binaryTree_test/graph.png +0 -0
- data/test/binaryTree_test/java_test/JavaTest.java +1 -1
- data/test/binaryTree_test/ruby_test/ruby_test.rb +26 -3
- data/test/complex_test/complex_test.rb +5 -0
- data/test/complex_test/csharp_test/csharp_test.cs +109 -0
- data/test/complex_test/graph.png +0 -0
- data/test/complex_test/java_test/JavaTest.java +1 -1
- data/test/complex_test/ruby_test/ruby_test.rb +24 -1
- data/test/dynamic_int_test/csharp_test/csharp_test.cs +76 -0
- data/test/dynamic_int_test/dynamic_int_test.rb +20 -0
- data/test/dynamic_int_test/graph.jpg +0 -0
- data/test/dynamic_int_test/java_test/JavaTest.java +72 -0
- data/test/dynamic_int_test/js_test/js_test.js +54 -0
- data/test/dynamic_int_test/ruby_test/ruby_test.rb +55 -0
- data/test/ipv6_test/csharp_test/csharp_test.cs +73 -0
- data/test/ipv6_test/graph.jpg +0 -0
- data/test/ipv6_test/ipv6_test.rb +5 -0
- data/test/ipv6_test/java_test/JavaTest.java +1 -1
- data/test/ipv6_test/ruby_test/ruby_test.rb +24 -4
- data/test/lib/csharp/nunit.framework.dll +0 -0
- data/test/{java_lib → lib/java}/junit.jar +0 -0
- data/test/signed_int_test/csharp_test/csharp_test.cs +86 -0
- data/test/signed_int_test/graph.jpg +0 -0
- data/test/signed_int_test/java_test/JavaTest.java +1 -1
- data/test/signed_int_test/ruby_test/ruby_test.rb +21 -1
- data/test/signed_int_test/signed_int_test.rb +6 -0
- data/test/unify_test/unify_test.rb +17 -4
- metadata +54 -8
- data/test/signed_float_test/ruby_test/ruby_test.rb +0 -36
- data/test/signed_float_test/signed_float_test.rb +0 -14
Binary file
|
@@ -90,7 +90,7 @@ public class JavaTest {
|
|
90
90
|
bt2.root_node.get(0).next_node.get(0).next_node.get(0).i32);
|
91
91
|
}
|
92
92
|
|
93
|
-
public void serialize(
|
93
|
+
public void serialize(Divine obj) throws IOException {
|
94
94
|
byte[] data = obj.serialize();
|
95
95
|
File file = new File("test/binaryTree_test/java_test/bin.babel");
|
96
96
|
try {
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require_relative 'test_binaryTree.rb'
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
|
-
|
4
|
+
#
|
5
|
+
# Responsible for testing Binary Tree structure
|
6
|
+
#
|
7
|
+
class TestBinaryTree < MiniTest::Unit::TestCase
|
5
8
|
|
9
|
+
#
|
10
|
+
# Compare objects after serialize and deserialize operations
|
11
|
+
#
|
6
12
|
def test_BinaryTree
|
7
13
|
puts "Test Binary Tree"
|
8
14
|
binaryTree_ser = buildTree
|
@@ -13,10 +19,13 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
|
|
13
19
|
|
14
20
|
binaryTree_deser = BabelTest::BinaryTree.new
|
15
21
|
binaryTree_deser.deserialize res
|
16
|
-
|
22
|
+
compare(binaryTree_ser, binaryTree_deser)
|
17
23
|
|
18
24
|
end
|
19
25
|
|
26
|
+
#
|
27
|
+
# Initialize the original object
|
28
|
+
#
|
20
29
|
def buildTree()
|
21
30
|
root = BabelTest::Node.new
|
22
31
|
root.i32 = 0
|
@@ -48,19 +57,33 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
|
|
48
57
|
bt
|
49
58
|
end
|
50
59
|
|
51
|
-
|
60
|
+
#
|
61
|
+
# Make sure that the comming two objects are the same
|
62
|
+
# * *Args* :
|
63
|
+
# -obj_ser- --> original object
|
64
|
+
# -obj_deser- --> obtained object after serialize and deserialize operations
|
65
|
+
#
|
66
|
+
def compare(bt1, bt2)
|
52
67
|
assert_equal bt1.root_node.length, bt2.root_node.length
|
53
68
|
assert_equal bt1.root_node[0].i32, bt2.root_node[0].i32
|
54
69
|
assert_equal bt1.root_node[0].next_node.length, bt2.root_node[0].next_node.length
|
55
70
|
assert_equal bt1.root_node[0].next_node[0].next_node[0].i32, bt2.root_node[0].next_node[0].next_node[0].i32
|
56
71
|
end
|
57
72
|
|
73
|
+
#
|
74
|
+
# Write binary data to file
|
75
|
+
# * *Args* :
|
76
|
+
# -data- --> bytes to be written
|
77
|
+
#
|
58
78
|
def serialize(data)
|
59
79
|
File.open("test/binaryTree_test/ruby_test/bin.babel.rb", "w+b") do |f|
|
60
80
|
f.write(data)
|
61
81
|
end
|
62
82
|
end
|
63
83
|
|
84
|
+
#
|
85
|
+
# Read file in binary mode and return its bytes content
|
86
|
+
#
|
64
87
|
def deserialize()
|
65
88
|
mem_buf = File.new('test/binaryTree_test/ruby_test/bin.babel.rb').binmode
|
66
89
|
end
|
@@ -14,10 +14,15 @@ struct 'Complex' do
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
|
+
# Draw ERD for prev. structs
|
18
|
+
Divine::GraphGenerator.new.draw("test/complex_test/", "graph", "png")
|
19
|
+
|
17
20
|
if ARGV[0] == "ruby"
|
18
21
|
Divine::CodeGenerator.new.generate(:ruby, file: 'test_complex.rb', module: 'BabelTest', parent_class: "Object", target_dir: 'test/complex_test/ruby_test')
|
19
22
|
elsif ARGV[0] == "js"
|
20
23
|
Divine::CodeGenerator.new.generate(:javascript, file: 'test_complex.js', target_dir: 'test/complex_test/js_test')
|
21
24
|
elsif ARGV[0] == "java"
|
22
25
|
Divine::CodeGenerator.new.generate(:java, file: 'test_complex.java', target_dir: 'test/complex_test/java_test')
|
26
|
+
elsif ARGV[0] == "csharp"
|
27
|
+
Divine::CodeGenerator.new.generate(:csharp, file: 'test_complex.cs', target_dir: "test/complex_test/csharp_test")
|
23
28
|
end
|
@@ -0,0 +1,109 @@
|
|
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 Complex Data Structure \n");
|
17
|
+
Complex ser = buildObj();
|
18
|
+
serialize(ser);
|
19
|
+
byte[] res = deserialize();
|
20
|
+
|
21
|
+
Complex deser = new Complex();
|
22
|
+
deser.deserialize(new MemoryStream(res));
|
23
|
+
|
24
|
+
compare(ser, deser);
|
25
|
+
}
|
26
|
+
|
27
|
+
public static Complex buildObj() {
|
28
|
+
IPList ipList_1 = new IPList();
|
29
|
+
ipList_1.list1.Add("10.2.2.1");
|
30
|
+
ipList_1.list1.Add("127.0.0.1");
|
31
|
+
ipList_1.list1.Add("129.36.58.15");
|
32
|
+
|
33
|
+
ipList_1.list2.Add("2001:db8::ff00:1:8329");
|
34
|
+
ipList_1.list2.Add("ff:ac:12::5f");
|
35
|
+
ipList_1.list2.Add("1::");
|
36
|
+
|
37
|
+
IPList ipList_2 = new IPList();
|
38
|
+
ipList_2.list1.Add("100.20.20.10");
|
39
|
+
ipList_2.list1.Add("17.10.10.1");
|
40
|
+
ipList_2.list1.Add("12.36.68.105");
|
41
|
+
|
42
|
+
ipList_2.list2.Add("ff:fabf:faf:f15f:f1ff:f2f:1f:f2");
|
43
|
+
ipList_2.list2.Add("2001:db8::ff00:1:8329");
|
44
|
+
ipList_2.list2.Add("::1");
|
45
|
+
|
46
|
+
|
47
|
+
List<IPList> tmp1 = new List<IPList>();
|
48
|
+
tmp1.Add(ipList_1);
|
49
|
+
tmp1.Add(ipList_2);
|
50
|
+
|
51
|
+
List<IPList> tmp2 = new List<IPList>();
|
52
|
+
tmp2.Add(ipList_2);
|
53
|
+
tmp2.Add(ipList_1);
|
54
|
+
|
55
|
+
Dictionary<string, List<IPList>> dict1 = new Dictionary<string, List<IPList>>();
|
56
|
+
dict1.Add("AA", tmp1);
|
57
|
+
|
58
|
+
Dictionary<string, List<IPList>> dict2 = new Dictionary<string, List<IPList>>();
|
59
|
+
dict2.Add("BB", tmp2);
|
60
|
+
|
61
|
+
Complex com = new Complex();
|
62
|
+
com.list1.Add(dict1);
|
63
|
+
com.list1.Add(dict2);
|
64
|
+
|
65
|
+
return com;
|
66
|
+
}
|
67
|
+
|
68
|
+
public static void compare(Complex obj1, Complex obj2)
|
69
|
+
{
|
70
|
+
Assert.AreEqual(obj1.list1.Count, obj2.list1.Count);
|
71
|
+
Assert.AreEqual(obj1.list1[0]["AA"].Count,
|
72
|
+
obj2.list1[0]["AA"].Count);
|
73
|
+
Assert.AreEqual(obj1.list1[0]["AA"][0].list1
|
74
|
+
.Count, obj2.list1[0]["AA"][0].list1.Count);
|
75
|
+
Assert.AreEqual(obj1.list1[0]["AA"][0].list1
|
76
|
+
[2].ToLower(), obj2.list1[0]["AA"][0].list1[2].ToLower());
|
77
|
+
Assert.AreEqual(obj1.list1[0]["AA"][0].list2
|
78
|
+
[1].ToLower(), obj2.list1[0]["AA"][0].list2[1].ToLower());
|
79
|
+
Assert.AreEqual(obj1.list1[1]["BB"][0].list2
|
80
|
+
[0].ToLower(), obj2.list1[1]["BB"][0].list2[0].ToLower());
|
81
|
+
}
|
82
|
+
|
83
|
+
public static void serialize(Divine obj)
|
84
|
+
{
|
85
|
+
try
|
86
|
+
{
|
87
|
+
byte[] data = obj.serialize();
|
88
|
+
File.WriteAllBytes("test/complex_test/csharp_test/bin.babel.csharp", data);
|
89
|
+
}
|
90
|
+
catch (System.IO.IOException ex)
|
91
|
+
{
|
92
|
+
throw ex;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
public static byte[] deserialize(){
|
97
|
+
try
|
98
|
+
{
|
99
|
+
byte[] data = File.ReadAllBytes("test/complex_test/csharp_test/bin.babel.csharp");
|
100
|
+
return data;
|
101
|
+
}
|
102
|
+
catch (System.IO.IOException ex)
|
103
|
+
{
|
104
|
+
throw ex;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
}
|
109
|
+
}
|
Binary file
|
@@ -102,7 +102,7 @@ public class JavaTest {
|
|
102
102
|
.get(0), obj2.list1.get(1).get("BB").get(0).list2.get(0));
|
103
103
|
}
|
104
104
|
|
105
|
-
public void serialize(
|
105
|
+
public void serialize(Divine obj) throws IOException {
|
106
106
|
byte[] data = obj.serialize();
|
107
107
|
File file = new File("test/complex_test/java_test/bin.babel");
|
108
108
|
try {
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require_relative 'test_complex.rb'
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
|
-
|
4
|
+
#
|
5
|
+
# Responsible for testing complex structure
|
6
|
+
#
|
7
|
+
class TestComplexStructure < MiniTest::Unit::TestCase
|
5
8
|
|
9
|
+
#
|
10
|
+
# Compare objects after serialize and deserialize operations
|
11
|
+
#
|
6
12
|
def test_complex
|
7
13
|
puts "Test Complex Data Structure"
|
8
14
|
com_ser = buildObject
|
@@ -17,6 +23,9 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
|
|
17
23
|
|
18
24
|
end
|
19
25
|
|
26
|
+
#
|
27
|
+
# Initialize the original object
|
28
|
+
#
|
20
29
|
def buildObject()
|
21
30
|
ipList_1 = BabelTest::IPList.new
|
22
31
|
ipList_1.list1 = ["10.2.2.1","127.0.0.1","129.36.58.15"]
|
@@ -33,6 +42,12 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
|
|
33
42
|
com
|
34
43
|
end
|
35
44
|
|
45
|
+
#
|
46
|
+
# Make sure that the comming two objects are the same
|
47
|
+
# * *Args* :
|
48
|
+
# -obj_ser- --> original object
|
49
|
+
# -obj_deser- --> obtained object after serialize and deserialize operations
|
50
|
+
#
|
36
51
|
def compare(obj1, obj2)
|
37
52
|
assert obj1.list1.length == obj2.list1.length
|
38
53
|
assert obj1.list1[0]["AA"].length == obj2.list1[0]["AA"].length
|
@@ -42,12 +57,20 @@ class TestBabelTestBasic < MiniTest::Unit::TestCase
|
|
42
57
|
assert obj1.list1[1]["BB"][0].list2[2] == obj2.list1[1]["BB"][0].list2[2]
|
43
58
|
end
|
44
59
|
|
60
|
+
#
|
61
|
+
# Write binary data to file
|
62
|
+
# * *Args* :
|
63
|
+
# -data- --> bytes to be written
|
64
|
+
#
|
45
65
|
def serialize(data)
|
46
66
|
File.open("test/complex_test/ruby_test/bin.babel.rb", "w+b") do |f|
|
47
67
|
f.write(data)
|
48
68
|
end
|
49
69
|
end
|
50
70
|
|
71
|
+
#
|
72
|
+
# Read file in binary mode and return its bytes content
|
73
|
+
#
|
51
74
|
def deserialize()
|
52
75
|
mem_buf = File.new('test/complex_test/ruby_test/bin.babel.rb').binmode
|
53
76
|
end
|
@@ -0,0 +1,76 @@
|
|
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_dynamic_int
|
9
|
+
{
|
10
|
+
[TestFixture]
|
11
|
+
class divine
|
12
|
+
{
|
13
|
+
[Test]
|
14
|
+
public static void Main(String[] args)
|
15
|
+
{
|
16
|
+
System.Console.Write("Test Dynamic Int \n");
|
17
|
+
DynamicInt ser = buildObj();
|
18
|
+
serialize(ser);
|
19
|
+
byte[] res = deserialize();
|
20
|
+
|
21
|
+
DynamicInt deser = new DynamicInt();
|
22
|
+
deser.deserialize(new MemoryStream(res));
|
23
|
+
|
24
|
+
compare(ser, deser);
|
25
|
+
}
|
26
|
+
|
27
|
+
public static DynamicInt buildObj() {
|
28
|
+
DynamicInt obj = new DynamicInt();
|
29
|
+
obj.list1.Add(127);
|
30
|
+
obj.list1.Add(16383);
|
31
|
+
obj.list1.Add(2097151);
|
32
|
+
obj.list1.Add(268435455);
|
33
|
+
obj.list1.Add(34359738367);
|
34
|
+
obj.list1.Add(4398046511103);
|
35
|
+
obj.list1.Add(562949953421311);
|
36
|
+
//obj.list1.Add(72057594037927935);
|
37
|
+
//obj.list1.Add(9223372036854775807);
|
38
|
+
return obj;
|
39
|
+
}
|
40
|
+
|
41
|
+
public static void compare(DynamicInt obj1, DynamicInt obj2)
|
42
|
+
{
|
43
|
+
for (int i = 0; i < obj1.list1.Count; i++)
|
44
|
+
{
|
45
|
+
//System.Console.Write("Ser = " + obj1.list1[i] + ", Deser = " + obj2.list1[i] + "\n");
|
46
|
+
Assert.AreEqual(obj1.list1[i], obj2.list1[i]);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
public static void serialize(Divine obj)
|
51
|
+
{
|
52
|
+
try
|
53
|
+
{
|
54
|
+
byte[] data = obj.serialize();
|
55
|
+
File.WriteAllBytes("test/dynamic_int_test/csharp_test/bin.babel.csharp", data);
|
56
|
+
}
|
57
|
+
catch (System.IO.IOException ex)
|
58
|
+
{
|
59
|
+
throw ex;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
public static byte[] deserialize(){
|
64
|
+
try
|
65
|
+
{
|
66
|
+
byte[] data = File.ReadAllBytes("test/dynamic_int_test/csharp_test/bin.babel.csharp");
|
67
|
+
return data;
|
68
|
+
}
|
69
|
+
catch (System.IO.IOException ex)
|
70
|
+
{
|
71
|
+
throw ex;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'divine'
|
3
|
+
|
4
|
+
struct 'DynamicInt' do
|
5
|
+
list :list1, :dint63
|
6
|
+
end
|
7
|
+
|
8
|
+
# Draw ERD for prev. struct
|
9
|
+
Divine::GraphGenerator.new.draw("test/dynamic_int_test/")
|
10
|
+
|
11
|
+
if ARGV[0] == "ruby"
|
12
|
+
Divine::CodeGenerator.new.generate(:ruby, file: 'test_dynamic_int.rb', module: 'BabelTest', parent_class: "Object", target_dir: "test/dynamic_int_test/ruby_test")
|
13
|
+
elsif ARGV[0] == "js"
|
14
|
+
Divine::CodeGenerator.new.generate(:javascript, file: 'test_dynamic_int.js', target_dir: "test/dynamic_int_test/js_test")
|
15
|
+
elsif ARGV[0] == "java"
|
16
|
+
Divine::CodeGenerator.new.generate(:java, file: 'test_dynamic_int.java', target_dir: "test/dynamic_int_test/java_test")
|
17
|
+
elsif ARGV[0] == "csharp"
|
18
|
+
Divine::CodeGenerator.new.generate(:csharp, file: 'test_dynamic_int.cs', target_dir: "test/dynamic_int_test/csharp_test")
|
19
|
+
|
20
|
+
end
|
Binary file
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
import java.io.ByteArrayInputStream;
|
3
|
+
import java.io.File;
|
4
|
+
import java.io.FileInputStream;
|
5
|
+
import java.io.FileOutputStream;
|
6
|
+
import java.io.IOException;
|
7
|
+
import java.util.ArrayList;
|
8
|
+
import java.util.Collections;
|
9
|
+
import java.util.HashMap;
|
10
|
+
import org.junit.*;
|
11
|
+
|
12
|
+
public class JavaTest {
|
13
|
+
|
14
|
+
@Test
|
15
|
+
public void testDynamicInt() throws IOException {
|
16
|
+
System.out.println("Test Dynamic Int63");
|
17
|
+
DynamicInt ser = buildObj();
|
18
|
+
|
19
|
+
serialize(ser);
|
20
|
+
byte[] res = deserialize();
|
21
|
+
|
22
|
+
DynamicInt deser = new DynamicInt();
|
23
|
+
deser.deserialize(new ByteArrayInputStream(res));
|
24
|
+
|
25
|
+
compare(ser, deser);
|
26
|
+
}
|
27
|
+
|
28
|
+
public DynamicInt buildObj() {
|
29
|
+
DynamicInt obj = new DynamicInt();
|
30
|
+
obj.list1 = new ArrayList<Long>(){{
|
31
|
+
add(127L);
|
32
|
+
add(16383L);
|
33
|
+
add(2097151L);
|
34
|
+
add(268435455L);
|
35
|
+
add(34359738367L);
|
36
|
+
add(4398046511103L);
|
37
|
+
add(562949953421311L);
|
38
|
+
//add(72057594037927935L);
|
39
|
+
//add(9223372036854775807L);
|
40
|
+
}};
|
41
|
+
return obj;
|
42
|
+
}
|
43
|
+
|
44
|
+
public void compare(DynamicInt obj1, DynamicInt obj2) {
|
45
|
+
for (int i = 0; i < obj1.list1.size(); i++){
|
46
|
+
//System.out.println("Ser = " + obj1.list1.get(i) + ", Deser = " + obj2.list1.get(i));
|
47
|
+
org.junit.Assert.assertEquals(obj1.list1.get(i), obj2.list1.get(i));
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
public void serialize(Divine obj) throws IOException {
|
52
|
+
byte[] data = obj.serialize();
|
53
|
+
File file = new File("test/dynamic_int_test/java_test/bin.babel");
|
54
|
+
try {
|
55
|
+
new FileOutputStream(file).write(data);
|
56
|
+
} catch (Exception e) {
|
57
|
+
e.printStackTrace();
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
public byte[] deserialize() throws IOException{
|
62
|
+
File file = new File("test/dynamic_int_test/java_test/bin.babel");
|
63
|
+
byte[] data = new byte[(int) file.length()];
|
64
|
+
try {
|
65
|
+
new FileInputStream(file).read(data);
|
66
|
+
} catch (Exception e) {
|
67
|
+
e.printStackTrace();
|
68
|
+
}
|
69
|
+
return data;
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|