~ubuntu-branches/ubuntu/oneiric/weave/oneiric

« back to all changes in this revision

Viewing changes to tests/unit/test_utils_json.js

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2010-08-11 00:35:15 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100811003515-o3jbh826bnd1syjv
Tags: 1.4.3-1ubuntu1
* Add -fshort-wchar to CXXFLAGS to fix FTBFS in Ubuntu
  - update debian/rules 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
_("Make sure json saves and loads from disk");
2
 
Cu.import("resource://weave/util.js");
3
 
 
4
 
function run_test() {
5
 
  _("Do a simple write of an array to json and read");
6
 
  let foo;
7
 
  Utils.jsonSave("foo", {}, ["v1", "v2"]);
8
 
  Utils.jsonLoad("foo", {}, function(val) {
9
 
    foo = val;
10
 
  });
11
 
  do_check_eq(typeof foo, "object");
12
 
  do_check_eq(foo.length, 2);
13
 
  do_check_eq(foo[0], "v1");
14
 
  do_check_eq(foo[1], "v2");
15
 
 
16
 
  _("Use the function callback version of jsonSave");
17
 
  let bar;
18
 
  Utils.jsonSave("bar", {}, function() ["v1", "v2"]);
19
 
  Utils.jsonLoad("bar", {}, function(val) {
20
 
    bar = val;
21
 
  });
22
 
  do_check_eq(typeof bar, "object");
23
 
  do_check_eq(bar.length, 2);
24
 
  do_check_eq(bar[0], "v1");
25
 
  do_check_eq(bar[1], "v2");
26
 
 
27
 
  _("Try saving simple strings");
28
 
  let str;
29
 
  Utils.jsonSave("str", {}, "hi");
30
 
  Utils.jsonLoad("str", {}, function(val) {
31
 
    str = val;
32
 
  });
33
 
  do_check_eq(typeof str, "string");
34
 
  do_check_eq(str.length, 2);
35
 
  do_check_eq(str[0], "h");
36
 
  do_check_eq(str[1], "i");
37
 
 
38
 
  _("Try saving a number");
39
 
  let num;
40
 
  Utils.jsonSave("num", {}, function() 42);
41
 
  Utils.jsonLoad("num", {}, function(val) {
42
 
    num = val;
43
 
  });
44
 
  do_check_eq(typeof num, "number");
45
 
  do_check_eq(num, 42);
46
 
}