From f9a7afaa83d83fce9a1a4e8b818fed1717199e0d Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Thu, 26 Apr 2018 02:06:51 +0200
Subject: [PATCH] improve tests

---
 .gitignore               |   1 -
 lib/index.js             |  11 ++++----
 test.bin                 | Bin 0 -> 67 bytes
 tests/tests_safe_wots.js |  54 +++++++++++++++++++++++++++++++++++----
 4 files changed, 55 insertions(+), 11 deletions(-)
 create mode 100644 test.bin

diff --git a/.gitignore b/.gitignore
index 8470dbc..e0ea992 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-test.bin
 test2.bin
 native/target
 native/index.node
diff --git a/lib/index.js b/lib/index.js
index 8a5c969..5fbc3e0 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -55,15 +55,16 @@ module.exports = {
         return instance
     },
 
-    newSafeMemoryInstance: (sigStock) => {
+    newEmptySafeMemoryInstance: (sigStock) => {
         var instance = Object.create(SafeWoTB)
         instance.setFilePath("")
         instance.setMaxCert(sigStock)
-        instance.nodes = new Array()
-        instance.issued_count = new Array()
-        instance.sources = new Array()
+        let instance_content = binding.new_safe_empty_instance();
+        instance.nodes = instance_content.nodes;
+        instance.issued_count = instance_content.issued_count;
+        instance.sources = instance_content.sources;
         return instance
-    },
+    }
 };
 
 const UnsafeWoTB = {
diff --git a/test.bin b/test.bin
new file mode 100644
index 0000000000000000000000000000000000000000..5c9b061e07e6907b3bdae3bad66857db4eac1547
GIT binary patch
literal 67
zcmZR80G|IJ7#JBC7?>Csm>C!tnHU&27#NrsA((}cfq|8gfq{*Yfq|2efq@$$4Wc+1
G7`Om@WCCOW

literal 0
HcmV?d00001

diff --git a/tests/tests_safe_wots.js b/tests/tests_safe_wots.js
index 15555f9..5c0e275 100644
--- a/tests/tests_safe_wots.js
+++ b/tests/tests_safe_wots.js
@@ -28,7 +28,7 @@ testsSafe()
 function testsSafe() {
     function newInstance(launchSafeTests) {
         return () => {
-            let wot = addon.newSafeMemoryInstance(3);
+            let wot = addon.newEmptySafeMemoryInstance(3);
             launchSafeTests(wot);
         }
     }
@@ -250,14 +250,47 @@ function testsSafe() {
         
 
 
-        describe('tests open written wot file', newInstance((wot) => {
+        describe('Building a larger WoT', newInstance((wot) => {
             before(() => {
                 wot = addon.newSafeFileInstance("test.bin", 3);
             });
 
-            it('should have a wot size of 12', function() {
+            /*it('should build a larget WoT', function() {
+                /* We build WoT:
+                 *
+                 * 0 --> 1 --> 2 --> 4 --> 5 <==> 6 --> 7
+                 *             ^
+                 *            ||
+                 *            ##==> 3 <-- 8 <-- 9 <========##
+                 *                       |                 ||
+                 *                       `> 10 <==> 11 <===##
+                 *//*
+                // Add nodes
+                for (let i = 0; i < 12; i++) {
+                  should.equal(wot.addNode(), i);
+                }
+                // First line
+                should.equal(wot.addLink(0, 1), 1);
+                should.equal(wot.addLink(1, 2), 1);
+                should.equal(wot.addLink(2, 4), 1);
+                should.equal(wot.addLink(4, 5), 1);
+                should.equal(wot.addLink(5, 6), 1);
+                should.equal(wot.addLink(6, 7), 1);
+                // 2n level
+                should.equal(wot.addLink(2, 3), 1);
+                should.equal(wot.addLink(3, 2), 2);
+                should.equal(wot.addLink(8, 3), 2);
+                should.equal(wot.addLink(9, 8), 1);
+                // 3rd level
+                should.equal(wot.addLink(8, 10), 1);
+                should.equal(wot.addLink(10, 11), 1);
+                should.equal(wot.addLink(11, 10), 2);
+                should.equal(wot.addLink(11, 9), 1);
+                should.equal(wot.addLink(9, 11), 2);
+        
                 should.equal(wot.getWoTSize(), 12);
-            });
+                return Promise.resolve();
+              });*/
 
             describe('testing around 2 with d = 1', () => {
       
@@ -428,12 +461,23 @@ function testsSafe() {
                     should.equal(wot.isOutdistanced(2, FROM_3_LINKS_SENTRIES, MAX_DISTANCE_5, 0.01), __OK__);
                   });
               });
+        }));
+
+        describe('tests open written wot file', newInstance((wot) => {
+            before(() => {
+                wot = addon.newFileInstance("test.bin", 3);
+            });
+
+            it('should have a wot size of 12', function() {
+                should.equal(wot.getWoTSize(), 12);
+            });
 
             it('should add node, write and read new wot with 13 nodes', function() {
                 wot.addNode();
                 wot.setFilePath("test2.bin");
                 assert.equal(wot.write(), true)
-                wot = addon.newSafeFileInstance("test2.bin", 3);
+                wot.clear();
+                wot = addon.newFileInstance("test2.bin", 3);
                 should.equal(wot.getWoTSize(), 13);
             });
         }));
-- 
GitLab