// Copyright 2014 Tamás Gulácsi. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.
package picago
import (
"encoding/xml"
"os"
"testing"
)
const albumsXML = `
https://picasaweb.google.com/data/feed/api/user/liz
2009-03-12T01:19:14.876Z
liz
https://iconPath/liz.jpg
Liz
http://picasaweb.google.com/liz
Picasaweb
1
1
1000
liz
Liz
https://thumbnailPath/liz.jpg
1073741824
32716
500
https://picasaweb.google.com/data/entry/api/user/liz/albumid/albumID
2005-06-17T07:09:42.000Z
2009-03-12T01:19:14.000Z
2009-03-12T01:19:14.000Z
lolcats
Hilarious Felines
public
Liz
http://picasaweb.google.com/liz
albumID
Mountain View, CA
public
1118992182000
1
499
23044
liz
Liz
lolcats
Hilarious
Felines
Liz
`
const photosXML = `
https://picasaweb.google.com/data/feed/user/liz/albumid/albumID
2008-12-08T01:24:16.000Z
lolcats
Hilarious Felines
public
https://iconPath/Lolcats.jpg
Liz
http://picasaweb.google.com/liz
Picasaweb
1
1
1000
albumID
Mountain View, CA, USA
public
1150527600000
1
499
23044
liz
Liz
37.38911780598221 -122.08638668060303
37.38482151758655 -122.0958924293518
37.39341409437787 -122.07688093185425
true
true
http://picasaweb.google.com/data/entry/user/liz/albumid/albumID/photoid/photoID
2008-08-15T18:58:44.000Z
2008-12-08T01:11:03.000Z
2008-12-08T01:11:03.000Z
invisible_bike.jpg
Bike
photoID
1.66002086E9
albumID
public
410
295
23044
1218826724000
0
0657130896bace739a44ce90a7d5b451
Liz
invisible, bike
invisible_bike.jpg
37.427399548633325 -122.1703290939331
37.42054944692195 -122.1825385093689
37.4342496503447 -122.15811967849731
`
func TestAtom(t *testing.T) {
for _, text := range []string{albumsXML, photosXML} {
var result Atom
if err := xml.Unmarshal([]byte(text), &result); err != nil {
t.Errorf("Unmarshal error: %v", err)
}
t.Logf("result: %#v", result)
}
}
func mustParseAtom(t *testing.T, file string) *Atom {
f, err := os.Open(file)
if err != nil {
t.Fatal(err)
}
defer f.Close()
a := new(Atom)
if err := xml.NewDecoder(f).Decode(a); err != nil {
t.Fatal(err)
}
return a
}
func TestVideoInGallery(t *testing.T) {
atom := mustParseAtom(t, "testdata/gallery-with-a-video.xml")
if len(atom.Entries) != 3 {
t.Fatalf("num entries = %d; want 3", len(atom.Entries))
}
p, err := atom.Entries[2].photo()
if err != nil {
t.Fatal(err)
}
if p.Type != "video/mpeg4" {
t.Errorf("type = %q; want video/mpeg4", p.Type)
}
if got, want := p.URL, "https://foo.googlevideo.com/bar.mp4"; got != want {
t.Errorf("URL = %q; want %q", got, want)
}
for i, ent := range atom.Entries {
t.Logf("%d. Media = %#v", i, ent.Media)
p, _ := ent.photo()
t.Logf("%d. %#v", i, p)
}
}