
// {{{
const string TD1 = """
{
  "created_at" : "Mon May 05 06:48:32 +0000 2014",
  "id" : 463208606784311296,
  "id_str" : "463208606784311296",
  "text" : "RT @BlackForestTeam: DIESELSTÖRMERS Kickstarter is live! - Go and check it out right now!... http://t.co/ZVmefc0w5e",
  "source" : "web",
  "truncated" : false,
  "in_reply_to_status_id" : null,
  "in_reply_to_status_id_str" : null,
  "in_reply_to_user_id" : null,
  "in_reply_to_user_id_str" : null,
  "in_reply_to_screen_name" : null,
  "user" : {
    "id" : 62574927,
    "id_str" : "62574927",
    "name" : "Frozenbyte",
    "screen_name" : "Frozenbyte",
    "location" : "Helsinki, Finland",
    "description" : "We're an independent game developer. Follow us on Twitter to get the latest news on our games! For support issues please get in touch via email.",
    "url" : "http://t.co/NlgW9k9ZXj",
    "entities" : {
      "url" : {
        "urls" : [
          {
            "url" : "http://t.co/NlgW9k9ZXj",
            "expanded_url" : "http://www.frozenbyte.com",
            "display_url" : "frozenbyte.com",
            "indices" : [
              0,
              22
            ]
          }
        ]
      },
      "description" : {
        "urls" : [
        ]
      }
    },
    "protected" : false,
    "followers_count" : 5682,
    "friends_count" : 137,
    "listed_count" : 242,
    "created_at" : "Mon Aug 03 17:52:07 +0000 2009",
    "favourites_count" : 233,
    "utc_offset" : 10800,
    "time_zone" : "Helsinki",
    "geo_enabled" : false,
    "verified" : false,
    "statuses_count" : 1042,
    "lang" : "en",
    "contributors_enabled" : false,
    "is_translator" : false,
    "is_translation_enabled" : false,
    "profile_background_color" : "000000",
    "profile_background_image_url" : "http://pbs.twimg.com/profile_background_images/378800000117103508/abe5a14a1f3b0b78e9038e73bf6b812d.jpeg",
    "profile_background_image_url_https" : "https://pbs.twimg.com/profile_background_images/378800000117103508/abe5a14a1f3b0b78e9038e73bf6b812d.jpeg",
    "profile_background_tile" : false,
    "profile_image_url" : "http://pbs.twimg.com/profile_images/1130292729/fb_newlogo_black480_normal.png",
    "profile_image_url_https" : "https://pbs.twimg.com/profile_images/1130292729/fb_newlogo_black480_normal.png",
    "profile_link_color" : "CBA051",
    "profile_sidebar_border_color" : "000000",
    "profile_sidebar_fill_color" : "D4802D",
    "profile_text_color" : "4A2500",
    "profile_use_background_image" : true,
    "default_profile" : false,
    "default_profile_image" : false,
    "following" : true,
    "follow_request_sent" : false,
    "notifications" : false
  },
  "geo" : null,
  "coordinates" : null,
  "place" : null,
  "contributors" : null,
  "retweeted_status" : {
    "created_at" : "Tue Apr 29 11:00:25 +0000 2014",
    "id" : 461097667775725569,
    "id_str" : "461097667775725569",
    "text" : "DIESELSTÖRMERS Kickstarter is live! - Go and check it out right now!... http://t.co/ZVmefc0w5e",
    "source" : "<a href=\"http://www.tumblr.com/\" rel=\"nofollow\">Tumblr</a>",
    "truncated" : false,
    "in_reply_to_status_id" : null,
    "in_reply_to_status_id_str" : null,
    "in_reply_to_user_id" : null,
    "in_reply_to_user_id_str" : null,
    "in_reply_to_screen_name" : null,
    "user" : {
      "id" : 726763934,
      "id_str" : "726763934",
      "name" : "Black Forest Games",
      "screen_name" : "BlackForestTeam",
      "location" : "Offenburg",
      "description" : "South-german team that brought you Giana Sisters: Twisted Dreams",
      "url" : "http://t.co/BXuCnqlX50",
      "entities" : {
        "url" : {
          "urls" : [
            {
              "url" : "http://t.co/BXuCnqlX50",
              "expanded_url" : "http://gianasisterstwisteddreams.com",
              "display_url" : "gianasisterstwisteddreams.com",
              "indices" : [
                0,
                22
              ]
            }
          ]
        },
        "description" : {
          "urls" : [
          ]
        }
      },
      "protected" : false,
      "followers_count" : 1145,
      "friends_count" : 308,
      "listed_count" : 35,
      "created_at" : "Mon Jul 30 20:11:50 +0000 2012",
      "favourites_count" : 116,
      "utc_offset" : 7200,
      "time_zone" : "Amsterdam",
      "geo_enabled" : false,
      "verified" : false,
      "statuses_count" : 1475,
      "lang" : "en",
      "contributors_enabled" : false,
      "is_translator" : false,
      "is_translation_enabled" : false,
      "profile_background_color" : "C0DEED",
      "profile_background_image_url" : "http://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_image_url_https" : "https://abs.twimg.com/images/themes/theme1/bg.png",
      "profile_background_tile" : false,
      "profile_image_url" : "http://pbs.twimg.com/profile_images/3694489354/ed399e59260bf71b10235dcd7eb56fe5_normal.png",
      "profile_image_url_https" : "https://pbs.twimg.com/profile_images/3694489354/ed399e59260bf71b10235dcd7eb56fe5_normal.png",
      "profile_banner_url" : "https://pbs.twimg.com/profile_banners/726763934/1369154494",
      "profile_link_color" : "0084B4",
      "profile_sidebar_border_color" : "C0DEED",
      "profile_sidebar_fill_color" : "DDEEF6",
      "profile_text_color" : "333333",
      "profile_use_background_image" : true,
      "default_profile" : true,
      "default_profile_image" : false,
      "following" : false,
      "follow_request_sent" : false,
      "notifications" : false
    },
    "geo" : null,
    "coordinates" : null,
    "place" : null,
    "contributors" : null,
    "retweet_count" : 6,
    "favorite_count" : 2,
    "entities" : {
      "hashtags" : [
      ],
      "symbols" : [
      ],
      "urls" : [
        {
          "url" : "http://t.co/ZVmefc0w5e",
          "expanded_url" : "http://tmblr.co/ZTqD4s1ERcDZg",
          "display_url" : "tmblr.co/ZTqD4s1ERcDZg",
          "indices" : [
            72,
            94
          ]
        }
      ],
      "user_mentions" : [
      ]
    },
    "favorited" : false,
    "retweeted" : false,
    "possibly_sensitive" : false,
    "lang" : "en"
  },
  "retweet_count" : 6,
  "favorite_count" : 0,
  "entities" : {
    "hashtags" : [
    ],
    "symbols" : [
    ],
    "urls" : [
      {
        "url" : "http://t.co/ZVmefc0w5e",
        "expanded_url" : "http://tmblr.co/ZTqD4s1ERcDZg",
        "display_url" : "tmblr.co/ZTqD4s1ERcDZg",
        "indices" : [
          93,
          115
        ]
      }
    ],
    "user_mentions" : [
      {
        "screen_name" : "BlackForestTeam",
        "name" : "Black Forest Games",
        "id" : 726763934,
        "id_str" : "726763934",
        "indices" : [
          3,
          19
        ]
      }
    ]
  },
  "favorited" : false,
  "retweeted" : false,
  "possibly_sensitive" : false,
  "lang" : "en"
}""";


const string TD2 =
"""
{
  "created_at": "Tue Apr 29 00:50:10 +0000 2014",
  "id": 460944092554227713,
  "id_str": "460944092554227713",
  "text": "Combined. http:\/\/t.co\/fFJqqT1A4j",
  "source": "\u003ca href=\"http:\/\/twitter.com\/geekculturejam\" rel=\"nofollow\"\u003eCultureJam\u003c\/a\u003e",
  "truncated": false,
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "in_reply_to_screen_name": null,
  "user": {
    "id": 657693,
    "id_str": "657693",
    "screen_name": "FOOBAR",
    "name": "Foo Bar",
    "profile_image_url" : "http://pbs.twimg.com/profile_images/3694489354/ed399e59260bf71b10235dcd7eb56fe5_normal.png",
    "verified" : false
  },
  "geo": null,
  "coordinates": null,
  "place": null,
  "contributors": null,
  "retweet_count": 0,
  "favorite_count": 0,
  "entities": {
    "hashtags": [],
    "symbols": [],
    "urls": [],
    "user_mentions": [],
    "media": []
  },
  "extended_entities": {
    "media": [
      {
        "id": 460938773744717825,
        "id_str": "460938773744717825",
        "indices": [
          10,
          32
        ],
        "media_url": "http:\/\/pbs.twimg.com\/media\/BmWVX2BCEAEx4MK.jpg",
        "media_url_https": "https:\/\/pbs.twimg.com\/media\/BmWVX2BCEAEx4MK.jpg",
        "url": "http:\/\/t.co\/fFJqqT1A4j",
        "display_url": "pic.twitter.com\/fFJqqT1A4j",
        "expanded_url": "http:\/\/twitter.com\/froginthevalley\/status\/460944092554227713\/photo\/1",
        "type": "photo",
        "sizes": {
          "medium": {
            "w": 599,
            "h": 397,
            "resize": "fit"
          },
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "small": {
            "w": 340,
            "h": 225,
            "resize": "fit"
          },
          "large": {
            "w": 1023,
            "h": 678,
            "resize": "fit"
          }
        }
      },
      {
        "id": 460938635315916,
        "indices": [
          10,
          32
        ],
        "media_url": "http:\/\/pbs.twimg.com\/media\/BmWVPyVCMAAeAwI.jpg",
        "media_url_https": "https:\/\/pbs.twimg.com\/media\/BmWVPyVCMAAeAwI.jpg",
        "url": "http:\/\/t.co\/fFJqqT1A4j",
        "display_url": "pic.twitter.com\/fFJqqT1A4j",
        "expanded_url": "http:\/\/twitter.com\/froginthevalley\/status\/460944092554227713\/photo\/1",
        "type": "photo",
        "sizes": {
          "medium": {
            "w": 600,
            "h": 600,
            "resize": "fit"
          },
          "thumb": {
            "w": 150,
            "h": 150,
            "resize": "crop"
          },
          "large": {
            "w": 1024,
            "h": 1024,
            "resize": "fit"
          },
          "small": {
            "w": 340,
            "h": 340,
            "resize": "fit"
          }
        }
      }
    ]
  },
  "favorited": false,
  "retweeted": false,
  "possibly_sensitive": false,
  "lang": "en"
}
""";

const string TD3 =
"""
{
  "created_at" : "Thu Jun 12 19:34:16 +0000 2014",
  "id" : 477172048427765760,
  "id_str" : "477172048427765760",
  "text" : "http://t.co/ZGX7b9YGiU http://t.co/6hfxg0TPyt",
  "source" : "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
  "truncated" : false,
  "in_reply_to_status_id" : null,
  "in_reply_to_status_id_str" : null,
  "in_reply_to_user_id" : null,
  "in_reply_to_user_id_str" : null,
  "in_reply_to_screen_name" : null,
  "user" : {
    "id" : 993713617,
    "id_str" : "993713617",
    "name" : "Core Bird",
    "screen_name" : "corebirdgtk",
    "location" : "",
    "description" : "",
    "url" : null,
    "entities" : {
      "description" : {
        "urls" : [
        ]
      }
    },
    "protected" : true,
    "followers_count" : 1,
    "friends_count" : 6,
    "listed_count" : 0,
    "created_at" : "Thu Dec 06 19:47:16 +0000 2012",
    "favourites_count" : 12,
    "utc_offset" : 7200,
    "time_zone" : "Amsterdam",
    "geo_enabled" : false,
    "verified" : false,
    "statuses_count" : 537,
    "lang" : "en",
    "contributors_enabled" : false,
    "is_translator" : false,
    "is_translation_enabled" : false,
    "profile_background_color" : "C0DEED",
    "profile_background_image_url" : "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https" : "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_tile" : false,
    "profile_image_url" : "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "profile_image_url_https" : "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "profile_link_color" : "0084B4",
    "profile_sidebar_border_color" : "C0DEED",
    "profile_sidebar_fill_color" : "DDEEF6",
    "profile_text_color" : "333333",
    "profile_use_background_image" : true,
    "default_profile" : true,
    "default_profile_image" : true,
    "following" : true,
    "follow_request_sent" : false,
    "notifications" : false
  },
  "geo" : null,
  "coordinates" : null,
  "place" : null,
  "contributors" : null,
  "retweet_count" : 0,
  "favorite_count" : 0,
  "entities" : {
    "hashtags" : [
    ],
    "symbols" : [
    ],
    "urls" : [
      {
        "url" : "http://t.co/ZGX7b9YGiU",
        "expanded_url" : "http://i.imgur.com/kgrtCf0.png",
        "display_url" : "i.imgur.com/kgrtCf0.png",
        "indices" : [
          0,
          22
        ]
      },
      {
        "url" : "http://t.co/6hfxg0TPyt",
        "expanded_url" : "http://i.imgur.com/xqmzPar.gif",
        "display_url" : "i.imgur.com/xqmzPar.gif",
        "indices" : [
          23,
          45
        ]
      }
    ],
    "user_mentions" : [
    ]
  },
  "favorited" : false,
  "retweeted" : false,
  "possibly_sensitive" : false,
  "lang" : "und"
}
""";


const string TD4 =
"""
{
  "created_at" : "Thu Jun 12 19:34:16 +0000 2014",
  "id" : 477172048465760,
  "id_str" : "477172048427765760",
  "text" : "http://t.co/ZGX7b9YGiU http://t.co/6hfxg0TPyt",
  "source" : "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
  "truncated" : false,
  "in_reply_to_status_id" : null,
  "in_reply_to_status_id_str" : null,
  "in_reply_to_user_id" : null,
  "in_reply_to_user_id_str" : null,
  "in_reply_to_screen_name" : null,
  "user" : {
    "id" : 993713617,
    "id_str" : "993713617",
    "name" : "Core Bird",
    "screen_name" : "corebirdgtk",
    "location" : "",
    "description" : "",
    "url" : null,
    "entities" : {
      "description" : {
        "urls" : [
        ]
      }
    },
    "protected" : true,
    "followers_count" : 1,
    "friends_count" : 6,
    "listed_count" : 0,
    "created_at" : "Thu Dec 06 19:47:16 +0000 2012",
    "favourites_count" : 12,
    "utc_offset" : 7200,
    "time_zone" : "Amsterdam",
    "geo_enabled" : false,
    "verified" : false,
    "statuses_count" : 537,
    "lang" : "en",
    "contributors_enabled" : false,
    "is_translator" : false,
    "is_translation_enabled" : false,
    "profile_background_color" : "C0DEED",
    "profile_background_image_url" : "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https" : "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_tile" : false,
    "profile_image_url" : "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "profile_image_url_https" : "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "profile_link_color" : "0084B4",
    "profile_sidebar_border_color" : "C0DEED",
    "profile_sidebar_fill_color" : "DDEEF6",
    "profile_text_color" : "333333",
    "profile_use_background_image" : true,
    "default_profile" : true,
    "default_profile_image" : true,
    "following" : true,
    "follow_request_sent" : false,
    "notifications" : false
  },
  "geo" : null,
  "coordinates" : null,
  "place" : null,
  "contributors" : null,
  "retweet_count" : 0,
  "favorite_count" : 0,
  "entities" : {
    "hashtags" : [
    ],
    "symbols" : [
    ],
    "urls" : [
      {
        "url" : "http://t.co/ZGX7b9YGiU",
        "expanded_url" : "http://i.imgur.com/kgrtCf0.png",
        "display_url" : "i.imgur.com/kgrtCf0.png",
        "indices" : [
          0,
          22
        ]
      },
      {
        "url" : "http://t.co/6hfxg0TPyt",
        "expanded_url" : "http://i.imgur.com/xqmzPar.gif",
        "display_url" : "i.imgur.com/xqmzPar.gif",
        "indices" : [
          23,
          45
        ]
      }
    ],
    "user_mentions" : [
    ]
  },
  "favorited" : false,
  "retweeted" : false,
  "possibly_sensitive" : false,
  "lang" : "und",
  "extended_entities": {
    "media": [
      {
        "id": 460938773744717,
        "media_url": "http:\/\/pbs.twimg.com\/media\/BmWVX2BCEAEx4MK.jpg",
        "media_url_https": "https:\/\/pbs.twimg.com\/media\/BmWVX2BCEAEx4MK.jpg",
        "url": "http:\/\/t.co\/fFJqqT1A4j",
        "display_url": "pic.twitter.com\/fFJqqT1A4j",
        "expanded_url": "http:\/\/twitter.com\/froginthevalley\/status\/460944092554227713\/photo\/1",
        "type": "photo"
      },
      {
        "id": 460938615916800,
        "media_url": "http:\/\/pbs.twimg.com\/media\/BmWVPyVCMAAeAwI.jpg",
        "media_url_https": "https:\/\/pbs.twimg.com\/media\/BmWVPyVCMAAeAwI.jpg",
        "url": "http:\/\/t.co\/fFJqqT1A4j",
        "display_url": "pic.twitter.com\/fFJqqT1A4j",
        "expanded_url": "http:\/\/twitter.com\/froginthevalley\/status\/460944092554227713\/photo\/1",
        "type": "photo"
      }
    ]

  }
}
""";



// """
// }}}

void retweet () {
  var now = new GLib.DateTime.now_local ();
  var t = new Cb.Tweet ();

  var parser = new Json.Parser ();
  try {
    parser.load_from_data (TD1);
  } catch (GLib.Error e) {
    critical (e.message);
  }
  var root = parser.get_root ();

  t.load_from_json (root, now);
  assert (t.id == 463208606784311296);
  assert (t.retweeted_tweet != null);
  assert (t.retweeted_tweet.id == 461097667775725569);
  assert (t.source_tweet.author.user_name == "Frozenbyte");
  assert (t.favorite_count == 0);
  assert (t.retweet_count == 6);
  assert (t.source_tweet.author.id == 62574927);
  assert (t.get_mentions ().length == 0);
  assert (t.retweeted_tweet.author.user_name == "Black Forest Games");
  assert (!t.is_flag_set (Cb.TweetState.FAVORITED));
  assert (!t.is_flag_set (Cb.TweetState.RETWEETED));
  assert (!t.is_flag_set (Cb.TweetState.VERIFIED));
  assert (t.reply_id == 0);
  assert (t.my_retweet == 0);
  //assert (!t.has_inline_media);
}



void media_count () {
  var now = new GLib.DateTime.now_local ();
  var t = new Cb.Tweet ();

  var parser = new Json.Parser ();
  try {
    parser.load_from_data (TD3);
  } catch (GLib.Error e) {
    critical (e.message);
  }
  var root = parser.get_root ();

  t.load_from_json (root, now);
  assert (t.get_screen_name () == "corebirdgtk");
  //message ("Media count: %d", t.medias.length);
  assert (t.get_medias ().length == 2);
}

int main (string[] args) {
  GLib.Test.init (ref args);
  Settings.init ();
  Gtk.init (ref args);
  Twitter.get ().init ();
  Utils.init_soup_session ();
  //XXX These are disabled for now since using Tweet.load_from_json will also start a media download
  //    which might spuriously fail because it's an async operation (which we don't care about here...).
  //GLib.Test.add_func ("/tweet-parsing/retweet", retweet);
  //GLib.Test.add_func ("/tweet-parsing/media-count", media_count);

  return GLib.Test.run ();
}
