Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / node_modules / protobufjs / examples / protoify / test.js
diff --git a/legacy-libs/grpc/node_modules/protobufjs/examples/protoify/test.js b/legacy-libs/grpc/node_modules/protobufjs/examples/protoify/test.js
new file mode 100644 (file)
index 0000000..c6c9e0d
--- /dev/null
@@ -0,0 +1,56 @@
+var protoify = require("./index.js"),\r
+    ByteBuffer = require("protobufjs").ByteBuffer,\r
+    assert = require("assert");\r
+\r
+// Array of samples to test\r
+var samples = [\r
+    1, -1, 0x80000000|0, 0x7fffffff|0,                    // Integers\r
+    0.1, 0.2, 1.234,                                      // Doubles\r
+    "John",                                               // String\r
+    true, false,                                          // Booleans\r
+    null,                                                 // null\r
+    [],                                                   // Array\r
+    {},                                                   // Object\r
+    undefined,                                            // undefined\r
+    [                                                     // Array holding each data type\r
+        1,\r
+        0.1,\r
+        "John",\r
+        true,\r
+        false,\r
+        null,\r
+        [],\r
+        {},\r
+        undefined\r
+    ],\r
+    {                                                     // Object holding each data type\r
+        1: 1,\r
+        0.1: 0.1,\r
+        "John": "John",\r
+        true: true,\r
+        false: false,\r
+        null: null,\r
+        array: [],\r
+        object: {},\r
+        undefined: undefined\r
+    }\r
+];\r
+\r
+samples.forEach(function(sample) {\r
+    // Encode each sample to a Buffer\r
+    var buf = protoify(sample);\r
+\r
+    // Print some nice debugging information\r
+    console.log(JSON.stringify(sample));\r
+    console.log("-------------------------------------------------------------------");\r
+    console.log(ByteBuffer.wrap(buf).toDebug(true));\r
+\r
+    // Decode the Buffer back to JSON\r
+    var decodedSample = protoify.parse(buf);\r
+\r
+    // And assert that it's actually equal\r
+    assert.deepEqual(decodedSample, sample);\r
+});\r
+\r
+// If no assertion errors are thrown, print\r
+console.log("OK");\r