[grilo-plugins/tmdb-test] tests: Add tests for tmdb plug-in



commit 5866efcf116c08417040c8c3b37b658dc2cfe468
Author: Jens Georg <jensg openismus com>
Date:   Tue Nov 13 10:32:05 2012 +0100

    tests: Add tests for tmdb plug-in
    
    With some changes by Murray Cumming to update this patch to
    the latest grilo API.

 Makefile.am                           |    2 +-
 configure.ac                          |    1 +
 test/Makefile.am                      |   11 +-
 test/test_data/tmdb/casts.txt         |    1 +
 test/test_data/tmdb/configuration.txt |    1 +
 test/test_data/tmdb/details.txt       |    1 +
 test/test_data/tmdb/empty-data.ini    |    2 +
 test/test_data/tmdb/images.txt        |    1 +
 test/test_data/tmdb/keywords.txt      |    1 +
 test/test_data/tmdb/no-details.ini    |   10 +
 test/test_data/tmdb/releases.txt      |    1 +
 test/test_data/tmdb/search.txt        |    1 +
 test/test_data/tmdb/sherlock.ini      |   23 +++
 test/test_tmdb.c                      |  299 +++++++++++++++++++++++++++++++++
 14 files changed, 353 insertions(+), 2 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4b9e922..88b3866 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = src
+SUBDIRS = src test
 
 MAINTAINERCLEANFILES = \
         aclocal.m4 \
diff --git a/configure.ac b/configure.ac
index 521723f..05f457d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -922,6 +922,7 @@ AC_CONFIG_FILES([
   src/upnp/Makefile
   src/vimeo/Makefile
   src/youtube/Makefile
+  test/Makefile
 ])
 
 AC_OUTPUT
diff --git a/test/Makefile.am b/test/Makefile.am
index 1217ebb..a68fe61 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,7 +7,7 @@
 
 INCLUDES = @DEPS_CFLAGS@
 
-noinst_PROGRAMS = test_local_metadata
+noinst_PROGRAMS = test_local_metadata test_tmdb
 #noinst_PROGRAMS += test
 
 #test_SOURCES =	\
@@ -32,6 +32,15 @@ test_local_metadata_CFLAGS = \
 	@GTHREAD_CFLAGS@ \
 	@GIO_CFLAGS@
 
+test_tmdb_SOURCES = \
+	test_tmdb.c
+
+test_tmdb_LDADD = \
+	@DEPS_LIBS@
+
+test_tmdb_CFLAGS = \
+	-DPREFIX=$(prefix)
+
 MAINTAINERCLEANFILES =	\
 	*.in		\
 	*~
diff --git a/test/test_data/tmdb/casts.txt b/test/test_data/tmdb/casts.txt
new file mode 100644
index 0000000..84bd4fa
--- /dev/null
+++ b/test/test_data/tmdb/casts.txt
@@ -0,0 +1 @@
+{"id":10528,"cast":[{"id":53714,"name":"Rachel McAdams","character":"Irene Adler","order":1,"profile_path":"/vvbr4wKIRbfiH4u7aXorobKLai5.jpg"},{"id":9642,"name":"Jude Law","character":"Dr. John Watson","order":2,"profile_path":"/n6mragkZ8jHNLi9nwSETPxxf8z0.jpg"},{"id":2983,"name":"Mark Strong","character":"Lord Blackwood","order":3,"profile_path":"/vC1a35KBxx8f2rkMKyaik7bTOud.jpg"},{"id":17521,"name":"Kelly Reilly","character":"Mary","order":4,"profile_path":"/tGOT6XkJSVD6LzF8tAPjWf4ZMzm.jpg"},{"id":10207,"name":"William Hope","character":"John Standish","order":5,"profile_path":"/46N4dSYShHnRTcbqD7Fzfjnmvvq.jpg"},{"id":1665,"name":"Eddie Marsan","character":"Inspector Lestrade","order":6,"profile_path":"/oxLYpxVIbYeQvQ5os32wCOZLtDO.jpg"},{"id":112692,"name":"Robert Maillet","character":"Dredger","order":7,"profile_path":null},{"id":11855,"name":"Geraldine James","character":"Mrs. Hudson","order":8,"profile_path":"/uRapxZIWwfcmOl2rzlz77oCC1e4.jpg"},{"id":84865,"name":"Willia
 m Houston","character":"Constable Clark","order":9,"profile_path":null},{"id":3223,"name":"Robert Downey Jr.","character":"Sherlock Holmes","order":0,"profile_path":"/o6ffyv7CYsEVpdd4jkmYT7y41Xn.jpg"}],"crew":[{"id":956,"name":"Guy Ritchie","department":"Directing","job":"Director","profile_path":"/eatQVmnFuHboJseFrYft1BIIc.jpg"},{"id":71244,"name":"Anthony Peckham","department":"Writing","job":"Screenplay","profile_path":null},{"id":11092,"name":"Simon Kinberg","department":"Writing","job":"Screenplay","profile_path":null},{"id":41289,"name":"Lionel Wigram","department":"Writing","job":"Screenstory","profile_path":null},{"id":112689,"name":"Michael Robert Johnson","department":"Writing","job":"Screenstory","profile_path":null},{"id":25167,"name":"Arthur Conan Doyle","department":"Writing","job":"Characters","profile_path":"/wkfHlJ56PpSqui0Cjhnahs3sfZg.jpg"},{"id":947,"name":"Hans Zimmer","department":"Sound","job":"Music","profile_path":"/7IjJpvGtCfY0DsritmfCh2iX9I4.jpg"},{
 "id":1296,"name":"Bruce Berman","department":"Production","job":"Executive Producer","profile_path":null},{"id":17630,"name":"Michael Tadross","department":"Production","job":"Executive Producer","profile_path":null},{"id":29018,"name":"Dana Goldberg","department":"Production","job":"Executive Producer","profile_path":null},{"id":37162,"name":"Susan Downey","department":"Production","job":"Producer","profile_path":null},{"id":112690,"name":"Dan Lin","department":"Production","job":"Producer","profile_path":null},{"id":1091,"name":"Joel Silver","department":"Production","job":"Producer","profile_path":null},{"id":41289,"name":"Lionel Wigram","department":"Production","job":"Producer","profile_path":null},{"id":112691,"name":"Peter Eskelsen","department":"Production","job":"Producer","profile_path":null},{"id":63127,"name":"Steve Clark-Hall","department":"Production","job":"Producer","profile_path":null},{"id":1301,"name":"Philippe Rousselot","department":"Crew","job":"Cinemat
 ography","profile_path":null},{"id":112689,"name":"Michael Robert Johnson","department":"Writing","job":"Screenplay","profile_path":null}]}
\ No newline at end of file
diff --git a/test/test_data/tmdb/configuration.txt b/test/test_data/tmdb/configuration.txt
new file mode 100644
index 0000000..1d04646
--- /dev/null
+++ b/test/test_data/tmdb/configuration.txt
@@ -0,0 +1 @@
+{"images":{"base_url":"http://cf2.imgobject.com/t/p/","poster_sizes":["w92","w154","w185","w342","w500","original"],"backdrop_sizes":["w300","w780","w1280","original"],"profile_sizes":["w45","w185","h632","original"],"logo_sizes":["w45","w92","w154","w185","w300","w500","original"]}}
\ No newline at end of file
diff --git a/test/test_data/tmdb/details.txt b/test/test_data/tmdb/details.txt
new file mode 100644
index 0000000..ddd902c
--- /dev/null
+++ b/test/test_data/tmdb/details.txt
@@ -0,0 +1 @@
+{"adult":false,"backdrop_path":"/uM414ugc1B910bTvGEIzsucfMMC.jpg","belongs_to_collection":{"id":102322,"name":"Sherlock Holmes Collection","poster_path":"/bsUN9Ph1nUituteKWOhPQGguNXt.jpg","backdrop_path":"/bZLK5gylAWabHlPrK1wC0bqVAju.jpg"},"budget":90000000,"genres":[{"id":28,"name":"Action"},{"id":12,"name":"Adventure"},{"id":80,"name":"Crime"},{"id":18,"name":"Drama"},{"id":9648,"name":"Mystery"},{"id":53,"name":"Thriller"}],"homepage":"http://sherlock-holmes-movie.warnerbros.com/","id":10528,"imdb_id":"tt0988045","original_title":"Sherlock Holmes","overview":"In a dynamic new portrayal of Arthur Conan Doyleâs most famous characters, âSherlock Holmesâ sends Holmes and his stalwart partner Watson on their latest challenge. Revealing fighting skills as lethal as his legendary intellect, Holmes will battle as never before to bring down a new nemesis and unravel a deadly plot that could destroy England.","popularity":212616.843,"poster_path":"/22ngurXbLqab7Sko6aTSdwOCe5W
 .jpg","production_companies":[{"name":"Warner Bros Pictures","id":4209},{"name":"Village Roadshow Pictures","id":79},{"name":"Silver Pictures","id":1885}],"production_countries":[{"iso_3166_1":"GB","name":"United Kingdom"},{"iso_3166_1":"US","name":"United States of America"},{"iso_3166_1":"DE","name":"Germany"}],"release_date":"2009-12-25","revenue":524028679,"runtime":128,"spoken_languages":[{"iso_639_1":"en","name":"English"},{"iso_639_1":"fr","name":"FranÃais"}],"tagline":"Nothing escapes him.","title":"Sherlock Holmes","vote_average":7.6,"vote_count":87}
\ No newline at end of file
diff --git a/test/test_data/tmdb/empty-data.ini b/test/test_data/tmdb/empty-data.ini
new file mode 100644
index 0000000..786b218
--- /dev/null
+++ b/test/test_data/tmdb/empty-data.ini
@@ -0,0 +1,2 @@
+[default]
+version=1
diff --git a/test/test_data/tmdb/images.txt b/test/test_data/tmdb/images.txt
new file mode 100644
index 0000000..9fd3fce
--- /dev/null
+++ b/test/test_data/tmdb/images.txt
@@ -0,0 +1 @@
+{"id":10528,"backdrops":[{"file_path":"/uM414ugc1B910bTvGEIzsucfMMC.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":7.357142857142857,"vote_count":7},{"file_path":"/r8V954pQMDFzYFdBh2WC1Y3pnN3.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":7.2,"vote_count":5},{"file_path":"/8oOjtbJMPLVAIsQdxcgQ46Pkmhz.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":7.136363636363637,"vote_count":11},{"file_path":"/wqQXp7y3JcYU0dvmlsl4RWcZrWO.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":7.0,"vote_count":6},{"file_path":"/glY2hrSN0WqEPQDC8iqfCCvUyfA.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.611111111111111,"vote_count":9},{"file_path":"/kbkgAiJPUWmLzCJwPh41gNQeG3F.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.5,"vote_count":5},{"file_path":"/k8nSKp54r0j1uy9QwM9RaD3g
 oah.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":6.166666666666667,"vote_count":6},{"file_path":"/5nmIwOfGdPcrNuWmJZemnzuZdKD.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":5.333333333333333,"vote_count":3},{"file_path":"/cMXTD0Iwwll0NKZqtSb3lYWGQ0S.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":5.0,"vote_count":3},{"file_path":"/fRT49QJkQxv5rBtyCAeaokjyzRL.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":4.666666666666667,"vote_count":3},{"file_path":"/53FIlh34An70sDCzvlaFPTk114C.jpg","width":1280,"height":720,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":4.25,"vote_count":2},{"file_path":"/yQvYo8dGpyOAAiG2B39jQercbSZ.jpg","width":1920,"height":1080,"iso_639_1":null,"aspect_ratio":1.78,"vote_average":4.125,"vote_count":4}],"posters":[{"file_path":"/22ngurXbLqab7Sko6aTSdwOCe5W.jpg","width":1000,"height":1500,"iso_639_1":"en
 ","aspect_ratio":0.67,"vote_average":7.136363636363637,"vote_count":11},{"file_path":"/lEV8cMuHtMWYqw1HnRCmcM8VeAq.jpg","width":675,"height":1000,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":6.5,"vote_count":17},{"file_path":"/c2ylpAZYgjhNPLm6gJaWXiXIFaY.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":6.03125,"vote_count":16},{"file_path":"/704ImfEel0BPPIPcowZbahji2Vb.jpg","width":3220,"height":4425,"iso_639_1":"es","aspect_ratio":0.73,"vote_average":5.25,"vote_count":2},{"file_path":"/c0yS2oinfG6AqKW9V4PWF998VhI.jpg","width":950,"height":1419,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":4.928571428571429,"vote_count":14},{"file_path":"/Vttr3YRuZ5Eu5TYdHp8ipf2dEl.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":4.5625,"vote_count":8},{"file_path":"/iX9YYPWAN9UVru4JMdxk2lGEmfZ.jpg","width":800,"height":1171,"iso_639_1":"ru","aspect_ratio":0.68,"vote_average":4.3,"vote_count":5},{"file_path":"
 /s2mzTB2dbExPnTswiSPOczTEIKp.jpg","width":853,"height":1200,"iso_639_1":"cs","aspect_ratio":0.71,"vote_average":4.25,"vote_count":2},{"file_path":"/tla7PAr8HRciUtQ0zBggmOU52eK.jpg","width":1750,"height":2500,"iso_639_1":"en","aspect_ratio":0.7,"vote_average":4.2,"vote_count":5},{"file_path":"/tJRwUXWRGXxOuJ0ssdS8XfYmSJK.jpg","width":1297,"height":2000,"iso_639_1":"en","aspect_ratio":0.65,"vote_average":3.8333333333333335,"vote_count":3},{"file_path":"/xlWqQvCaxzMLNwY9lCWYAfBCtJl.jpg","width":794,"height":1134,"iso_639_1":"en","aspect_ratio":0.7,"vote_average":3.6666666666666665,"vote_count":3},{"file_path":"/kpxMPOfIN72gi96mPV5i8ZXIc36.jpg","width":675,"height":1000,"iso_639_1":"pl","aspect_ratio":0.68,"vote_average":2.75,"vote_count":2},{"file_path":"/yU1qarHPNyA72l4Fy0XJFuVU0l9.jpg","width":1356,"height":2081,"iso_639_1":"pl","aspect_ratio":0.65,"vote_average":2.25,"vote_count":2},{"file_path":"/aCyI7PiYufbMJn2KTOH7gWvtq2f.jpg","width":1356,"height":2081,"iso_639_1":"en","
 aspect_ratio":0.65,"vote_average":0.75,"vote_count":2},{"file_path":"/ezAkXkuTYiWPjYhy3y7DtBE0j5s.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":0.5,"vote_count":2},{"file_path":"/ezAkXkuTYiWPjYhy3y7DtBE0j5s.jpg","width":1000,"height":1500,"iso_639_1":"en","aspect_ratio":0.67,"vote_average":0.5,"vote_count":2},{"file_path":"/i3sC5ZOepzCikV9LZrNa8ukRLlc.jpg","width":533,"height":789,"iso_639_1":"es","aspect_ratio":0.68,"vote_average":0.5,"vote_count":1},{"file_path":"/ioEOm3dvcA0xK4DsJtyS7FM5OJl.jpg","width":1471,"height":2122,"iso_639_1":"bg","aspect_ratio":0.69,"vote_average":0.5,"vote_count":1},{"file_path":"/bJdolsMl9eGgtHH89ZirLvFarHn.jpg","width":1067,"height":1577,"iso_639_1":"es","aspect_ratio":0.68,"vote_average":0.5,"vote_count":1},{"file_path":"/clVy7zGIAhrOqwojV6TYuwEzJvP.jpg","width":1500,"height":2216,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":0.5,"vote_count":3},{"file_path":"/pk380DUzkYqe0eFonuCVmiMquhm.jpg","width
 ":1500,"height":2211,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":0.5,"vote_count":3},{"file_path":"/7bkIR16b6vtfF6gHwuIbizqURq6.jpg","width":1600,"height":2366,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":0.5,"vote_count":3},{"file_path":"/sGYx7voBSzgo3Y3SbyrMvCFzdY7.jpg","width":1600,"height":2366,"iso_639_1":"en","aspect_ratio":0.68,"vote_average":0.5,"vote_count":3}]}
\ No newline at end of file
diff --git a/test/test_data/tmdb/keywords.txt b/test/test_data/tmdb/keywords.txt
new file mode 100644
index 0000000..0b33aaa
--- /dev/null
+++ b/test/test_data/tmdb/keywords.txt
@@ -0,0 +1 @@
+{"id":10528,"keywords":[{"id":703,"name":"detective"},{"id":770,"name":"scotland yard"},{"id":1909,"name":"coffin"},{"id":18220,"name":"grave"},{"id":4252,"name":"black magic"},{"id":5638,"name":"arrest"},{"id":9104,"name":"partner"},{"id":9401,"name":"sherlock holmes"},{"id":15595,"name":"death"},{"id":9826,"name":"murder"},{"id":15638,"name":"escape"},{"id":11855,"name":"pentagram"},{"id":33514,"name":"clue"},{"id":10028,"name":"steampunk"},{"id":155846,"name":"1890s"}]}
\ No newline at end of file
diff --git a/test/test_data/tmdb/no-details.ini b/test/test_data/tmdb/no-details.ini
new file mode 100644
index 0000000..e66cd28
--- /dev/null
+++ b/test/test_data/tmdb/no-details.ini
@@ -0,0 +1,10 @@
+# This file only contains the configuration and the initial search result
+
+[default]
+version=1
+
+[http://api.themoviedb.org/3/configuration?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = configuration.txt
+
+[http://api.themoviedb.org/3/search/movie?query=TMDBTestTitle&api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = search.txt
diff --git a/test/test_data/tmdb/releases.txt b/test/test_data/tmdb/releases.txt
new file mode 100644
index 0000000..5746bc3
--- /dev/null
+++ b/test/test_data/tmdb/releases.txt
@@ -0,0 +1 @@
+{"id":10528,"countries":[{"iso_3166_1":"US","certification":"PG-13","release_date":"2009-12-25"},{"iso_3166_1":"DK","certification":"15","release_date":"2009-12-25"},{"iso_3166_1":"FR","certification":"","release_date":"2010-02-03"},{"iso_3166_1":"DE","certification":"12","release_date":"2010-01-28"},{"iso_3166_1":"HU","certification":"16","release_date":"2010-01-07"},{"iso_3166_1":"BG","certification":"C","release_date":"2010-01-01"},{"iso_3166_1":"NL","certification":"12","release_date":"2009-01-07"},{"iso_3166_1":"GB","certification":"12A","release_date":"2009-12-26"}]}
\ No newline at end of file
diff --git a/test/test_data/tmdb/search.txt b/test/test_data/tmdb/search.txt
new file mode 100644
index 0000000..70cb3df
--- /dev/null
+++ b/test/test_data/tmdb/search.txt
@@ -0,0 +1 @@
+{"page":1,"results":[{"adult":false,"backdrop_path":"/uM414ugc1B910bTvGEIzsucfMMC.jpg","id":10528,"original_title":"Sherlock Holmes","release_date":"2009-12-25","poster_path":"/22ngurXbLqab7Sko6aTSdwOCe5W.jpg","popularity":212616.843,"title":"Sherlock Holmes","vote_average":7.6,"vote_count":87},{"adult":false,"backdrop_path":"/nydyVLoIReyT3ZP223dvIyeLDg2.jpg","id":33555,"original_title":"Sherlock Holmes","release_date":"2010-01-26","poster_path":"/yVeRjNrFPNHkjV200Ncmldd6p6p.jpg","popularity":1.178,"title":"Sherlock Holmes","vote_average":0.5,"vote_count":2},{"adult":false,"backdrop_path":null,"id":53800,"original_title":"Sherlock Holmes","release_date":"1922-03-07","poster_path":"/o0WU1gULoK6TefZnsFVuornD2ni.jpg","popularity":0.006,"title":"Sherlock Holmes","vote_average":0.0,"vote_count":0},{"adult":false,"backdrop_path":"/3jmMRaO8WMjKsf1LWzo6Q6E5zMP.jpg","id":58574,"original_title":"Sherlock Holmes: A Game of Shadows","release_date":"2011-12-16","poster_path":"/fB4iTMEQew
 g7NNkLzdCth6ZGNA0.jpg","popularity":351682.403,"title":"Sherlock Holmes: A Game of Shadows","vote_average":7.3,"vote_count":61},{"adult":false,"backdrop_path":"/nqKfMeHyTRU9G7r4i95TwGjzHH2.jpg","id":126846,"original_title":"ÐÐÑÐÐÐ ÐÐÐÐÑ Ð ÐÐÐÑÐÑ ÐÐÑÑÐÐ: ÐÐÑÐÐÑ ÑÐÐÑÐÐÐ","release_date":"1980-01-01","poster_path":"/xTcChf1urNYbRsyjfnX3PEsllax.jpg","popularity":0.267,"title":"The Adventures of Sherlock Holmes and Doctor Watson: King of Blackmailers","vote_average":8.5,"vote_count":1},{"adult":false,"backdrop_path":"/rvrarHyHuHJ9NydRRDFTOxMRPJ7.jpg","id":126865,"original_title":"ÐÐÑÐÐÐ ÐÐÐÐÑ Ð ÐÐÐÑÐÑ ÐÐÑÑÐÐ: ÐÐÐÐÐÐ ÐÐÑÐÐÑÐÐÐÐÐ Ñ2","release_date":"1981-06-02","poster_path":"/8MvJWKoFwAG5MS1vHPc0EPGL1pU.jpg","popularity":0.263,"title":"The Adventures of Sherlock Holmes and Dr. Watson: The Hound of the Baskervilles","vote_average":8.5,"vote_count":1},{"adult":false,"backdrop_path":"/79h7kAfHQPTR5GJzBAdiXF
 ChW54.jpg","id":126850,"original_title":"ÐÐÑÐÐÐ ÐÐÐÐÑ Ð ÐÐÐÑÐÑ ÐÐÑÑÐÐ: ÐÐÐÑÑÐÐÑÐÐÑ ÑÑÐÐÑÐÐ","release_date":"1980-02-01","poster_path":"/eupoKJuXIYszoeOWeCS2LbGaDn0.jpg","popularity":0.198,"title":"Mortal Fight","vote_average":8.5,"vote_count":1},{"adult":false,"backdrop_path":"/6x5C3iizN2o5CmgEiC9DuTuLK51.jpg","id":72093,"original_title":"ÐÐÑÐÐÐ ÐÐÐÐÑ Ð ÐÐÐÑÐÑ ÐÐÑÑÐÐ: ÐÑÐÐÐÐÐÑ ÐÐÐÐÐÑÑ","release_date":"1979-02-01","poster_path":"/etNRaqINVvm9t0SZj8ZxExMjWmv.jpg","popularity":0.227,"title":"The Adventures of Sherlock Holmes and Dr. Watson: Bloody Signature","vote_average":8.5,"vote_count":1},{"adult":false,"backdrop_path":"/tNEU7iA1SHzn5mNKS0N4Yk6usnW.jpg","id":84254,"original_title":"ÐÐÑÐÐÐ ÐÐÐÐÑ Ð ÐÐÐÑÐÑ ÐÐÑÑÐÐ: ÐÐÐÐÐÐ ÐÐÑÐÐÑÐÐÐÐÐ Ñ1","release_date":"1981-01-02","poster_path":"/4dHEGZNcMjFFedHg3faYzpx7xkU.jpg","popularity":0.135,"title":"The Adventures o
 f Sherlock Holmes and Dr. Watson: The Hound of the Baskervilles","vote_average":8.5,"vote_count":1},{"adult":false,"backdrop_path":"/154KYwXavbbwUVUDJGQ31ZDfE4j.jpg","id":29859,"original_title":"The Adventure of Sherlock Holmes' Smarter Brother","release_date":"1975-01-01","poster_path":"/qE0vUDbiDfLlDok0HPRie980Mbs.jpg","popularity":0.051,"title":"The Adventure of Sherlock Holmes' Smarter Brother","vote_average":6.0,"vote_count":1},{"adult":false,"backdrop_path":"/eqSDyzMYjgLQZgZUa4LFjdTGUBz.jpg","id":11904,"original_title":"Young Sherlock Holmes","release_date":"1985-12-04","poster_path":"/qE7P2aXvbbyQRg18RxoHLyUwJPQ.jpg","popularity":0.244,"title":"Young Sherlock Holmes","vote_average":7.8,"vote_count":2},{"adult":false,"backdrop_path":"/wWDH3r48mmJ3CPmmeApmvhD51Y9.jpg","id":15722,"original_title":"Sherlock Holmes and the Case of the Silk Stocking","release_date":"2004-12-26","poster_path":"/igVMjbLT1z1gFT5jqFnsRGn7J0E.jpg","popularity":0.039,"title":"Sherlock Holmes and 
 the Case of the Silk Stocking","vote_average":9.0,"vote_count":1},{"adult":false,"backdrop_path":"/bKWDk6eqSJvua0kGbkNjz7R2GQN.jpg","id":18706,"original_title":"Sherlock Holmes and the Secret Weapon","release_date":"1943-02-12","poster_path":"/haequT7XAc5H4NnSWAZv1G2btzx.jpg","popularity":0.012,"title":"Sherlock Holmes and the Secret Weapon","vote_average":0.0,"vote_count":0},{"adult":false,"backdrop_path":"/7yIqzcc9m5Tg5d6m3Zr0cE4Fkih.jpg","id":17481,"original_title":"The Adventures of Sherlock Holmes","release_date":"1939-09-01","poster_path":"/9OXL9HDk7Bt2A4fbqlzBB5AP6jz.jpg","popularity":0.017,"title":"The Adventures of Sherlock Holmes","vote_average":8.0,"vote_count":1},{"adult":false,"backdrop_path":"/9WDOLbkhb7uCVDz1wVDDgNrptmj.jpg","id":34327,"original_title":"The Woman in Green","release_date":"1945-07-27","poster_path":"/wg4Vx9oRVNPn6TUrmvyrBgjJYje.jpg","popularity":0.02,"title":"The Woman in Green","vote_average":6.0,"vote_count":1},{"adult":false,"backdrop_path":
 "/aVMhnH3pkuxTitnTyRH9VZCZKNa.jpg","id":27118,"original_title":"The Hound of the Baskervilles","release_date":"1939-03-31","poster_path":"/v1hSYSF3FHOrqXqihorptQmgUct.jpg","popularity":0.017,"title":"The Hound of the Baskervilles","vote_average":6.5,"vote_count":1},{"adult":false,"backdrop_path":"/srjwMuGtnBPUTKEEFib3zC3Tvuk.jpg","id":2443,"original_title":"The Spider Woman","release_date":"1944-01-21","poster_path":"/1nAQZjoUNLrfMCCNL9i5PjZoIfV.jpg","popularity":0.028,"title":"The Spider Woman","vote_average":6.0,"vote_count":0},{"adult":false,"backdrop_path":"/2rkwFOAjJY4BFRDa0Ri89L4pScD.jpg","id":50553,"original_title":"Sherlock Holmes Faces Death","release_date":"1943-09-17","poster_path":"/8ZGyC2xuDDFp1AQ1wtCvK5FGU3w.jpg","popularity":0.013,"title":"Sherlock Holmes Faces Death","vote_average":0.0,"vote_count":0},{"adult":false,"backdrop_path":"/pWCJzawxr4meH73RS6tHs38dcq2.jpg","id":43956,"original_title":"Tom and Jerry Meet Sherlock Holmes","release_date":"2010-08-24","
 poster_path":"/6JFRJhby5y3qP56szDrYHUIovKi.jpg","popularity":0.392,"title":"Tom and Jerry Meet Sherlock Holmes","vote_average":0.0,"vote_count":0}],"total_pages":3,"total_results":55}
diff --git a/test/test_data/tmdb/sherlock.ini b/test/test_data/tmdb/sherlock.ini
new file mode 100644
index 0000000..c65650c
--- /dev/null
+++ b/test/test_data/tmdb/sherlock.ini
@@ -0,0 +1,23 @@
+[default]
+version=1
+
+[http://api.themoviedb.org/3/configuration?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = configuration.txt
+
+[http://api.themoviedb.org/3/movie/10528/casts?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = casts.txt
+
+[http://api.themoviedb.org/3/movie/10528/images?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = images.txt
+
+[http://api.themoviedb.org/3/movie/10528/keywords?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = keywords.txt
+
+[http://api.themoviedb.org/3/movie/10528/releases?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = releases.txt
+
+[http://api.themoviedb.org/3/movie/10528?api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = details.txt
+
+[http://api.themoviedb.org/3/search/movie?query=Sherlock+Holmes&api%5Fkey=TMDB%5FTEST%5FAPI%5FKEY]
+data = search.txt
diff --git a/test/test_tmdb.c b/test/test_tmdb.c
new file mode 100644
index 0000000..690884c
--- /dev/null
+++ b/test/test_tmdb.c
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <grilo.h>
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+#define TEST_PATH "test_data/tmdb/"
+
+GrlSource *source;
+GrlMedia *media;
+GrlOperationOptions *options;
+
+static void
+setup_tmdb (const char *ini)
+{
+  GrlConfig *config;
+  GrlRegistry *registry;
+  GError *error = NULL;
+
+  config = grl_config_new (TMDB_PLUGIN_ID, NULL);
+  /* Does not matter what we set it to, just needs to be non-empty as we're
+   * going to fake the network responses. */
+  grl_config_set_api_key (config, "TMDB_TEST_API_KEY");
+
+  registry = grl_registry_get_default ();
+  grl_registry_add_config (registry, config, &error);
+  g_assert (error == NULL);
+
+  g_setenv ("GRL_NET_MOCKED", ini, TRUE);
+
+  grl_registry_load_plugin_by_id (registry, TMDB_PLUGIN_ID, &error);
+  g_assert (error == NULL);
+
+  source = GRL_SOURCE (grl_registry_lookup_source (registry, TMDB_PLUGIN_ID));
+  g_assert (source != NULL);
+
+  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
+
+  media = grl_media_video_new ();
+  g_assert (media != NULL);
+
+  options = grl_operation_options_new (NULL);
+  g_assert (options != NULL);
+}
+
+static void
+shutdown_tmdb (void)
+{
+  GrlRegistry *registry;
+  GError *error = NULL;
+
+  registry = grl_registry_get_default ();
+  grl_registry_unload_plugin (registry, TMDB_PLUGIN_ID, &error);
+  g_assert (error == NULL);
+
+  g_object_unref (media);
+  media = NULL;
+
+  g_object_unref (options);
+  options = NULL;
+}
+
+static void
+test_preconditions (void)
+{
+  GrlMedia *local_media;
+  GError *error = NULL;
+
+  setup_tmdb ("test_data/tmdb/empty-data.ini");
+
+  local_media = grl_media_audio_new ();
+
+  grl_source_resolve_sync (source,
+                           local_media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the mock
+   * file would have resulted in an error */
+  g_assert (error == NULL);
+
+  g_object_unref (local_media);
+
+  local_media = grl_media_image_new ();
+
+  grl_source_resolve_sync (source,
+                           local_media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the
+   * empty mock file would have resulted in an error */
+  g_assert (error == NULL);
+  g_object_unref (local_media);
+
+  /* Check the same for title-less video */
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+  g_assert (error == NULL);
+
+  shutdown_tmdb ();
+}
+
+static void
+test_missing_configuration (void)
+{
+  GError *error = NULL;
+
+  setup_tmdb (TEST_PATH "empty-data.ini");
+
+  /* Doesn't matter, we just need to get it to resolve */
+  grl_media_set_title (media, "Non-Empty");
+
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the mock
+   * file would have resulted in an error */
+  g_assert (error != NULL);
+
+  shutdown_tmdb ();
+}
+
+/** Compare the floats.
+ * A simple == will fail on values that are effectively the same,
+ * due to rounding issues.
+ */
+static gboolean compare_floats(gfloat a, gfloat b)
+{
+   return fabs(a - b) < DBL_EPSILON;
+}
+
+static void
+test_fast_resolution (void)
+{
+  GError *error = NULL;
+  GrlKeyID backdrop, original_title, posters;
+  GrlRegistry *registry;
+  GDateTime *date, *orig;
+
+  setup_tmdb (TEST_PATH "no-details.ini");
+
+  registry = grl_registry_get_default ();
+  backdrop = grl_registry_lookup_metadata_key (registry, "tmdb-backdrops");
+  original_title = grl_registry_lookup_metadata_key (registry, "tmdb-original-title");
+  posters = grl_registry_lookup_metadata_key (registry, "tmdb-poster");
+
+  grl_operation_options_set_flags (options, GRL_RESOLVE_FAST_ONLY);
+  grl_media_set_title (media, "TMDBTestTitle");
+
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Fast resolution must not result in an error if the details are missing */
+  g_assert (error == NULL);
+
+  /* Check if we have everything we need */
+  g_assert (compare_floats (grl_media_get_rating (media), 3.8f));
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), original_title), ==,
+                   "Sherlock Holmes");
+  /* There's only one poster/backdrop in the search result */
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), backdrop), ==,
+                   "http://cf2.imgobject.com/t/p/original/uM414ugc1B910bTvGEIzsucfMMC.jpg";);
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), posters), ==,
+                   "http://cf2.imgobject.com/t/p/original/22ngurXbLqab7Sko6aTSdwOCe5W.jpg";);
+  orig = g_date_time_new_utc (2009, 12, 25, 0, 0, 0.0);
+  date = grl_media_get_publication_date (media);
+  g_assert_cmpint (g_date_time_compare (orig, date), ==, 0);
+  g_date_time_unref (orig);
+
+  shutdown_tmdb ();
+}
+
+#define DESCRIPTION \
+"In a dynamic new portrayal of Arthur Conan Doyleâs most famous characters, âSherlock Holmesâ sends Holmes and his stalwart partner Watson on their latest challenge. Revealing fighting skills as lethal as his legendary intellect, Holmes will battle as never before to bring down a new nemesis and unravel a deadly plot that could destroy England."
+
+static void
+test_full_resolution (void)
+{
+  GError *error = NULL;
+  GrlRegistry *registry;
+  GrlKeyID backdrop, posters, imdb_id, keywords, performer, producer;
+  GrlKeyID director, age_certs, original_title;
+  GDateTime *date, *orig;
+
+  setup_tmdb (TEST_PATH "sherlock.ini");
+
+  registry = grl_registry_get_default ();
+  backdrop = grl_registry_lookup_metadata_key (registry, "tmdb-backdrops");
+  g_assert_cmpint (backdrop, !=, GRL_METADATA_KEY_INVALID);
+  posters = grl_registry_lookup_metadata_key (registry, "tmdb-poster");
+  g_assert_cmpint (posters, !=, GRL_METADATA_KEY_INVALID);
+  imdb_id = grl_registry_lookup_metadata_key (registry, "tmdb-imdb-id");
+  g_assert_cmpint (imdb_id, !=, GRL_METADATA_KEY_INVALID);
+  keywords = GRL_METADATA_KEY_KEYWORD;
+  performer = GRL_METADATA_KEY_PERFORMER;
+  producer = GRL_METADATA_KEY_PRODUCER;
+  director = GRL_METADATA_KEY_DIRECTOR;
+  age_certs = grl_registry_lookup_metadata_key (registry, "tmdb-age-certificates");
+  g_assert_cmpint (age_certs, !=, GRL_METADATA_KEY_INVALID);
+  original_title = GRL_METADATA_KEY_ORIGINAL_TITLE;
+
+  grl_media_set_title (media, "Sherlock Holmes");
+
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+  g_assert (error == NULL);
+
+  /* Check if we got everything we need for the fast resolution */
+  g_assert (compare_floats (grl_media_get_rating (media), 3.8f));
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), original_title), ==,
+                   "Sherlock Holmes");
+  /* There's only one poster/backdrop in the search result */
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), backdrop), ==,
+                   "http://cf2.imgobject.com/t/p/original/uM414ugc1B910bTvGEIzsucfMMC.jpg";);
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), posters), ==,
+                   "http://cf2.imgobject.com/t/p/original/22ngurXbLqab7Sko6aTSdwOCe5W.jpg";);
+  orig = g_date_time_new_utc (2009, 12, 25, 0, 0, 0.0);
+  date = grl_media_get_publication_date (media);
+  g_assert_cmpint (g_date_time_compare (orig, date), ==, 0);
+  g_date_time_unref (orig);
+
+  /* And now the slow properties */
+  g_assert_cmpstr (grl_media_get_site (media), ==,
+                   "http://sherlock-holmes-movie.warnerbros.com/";);
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_GENRE), ==, 6);
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_STUDIO), ==, 3);
+
+  g_assert_cmpstr (grl_media_get_description (media), ==, DESCRIPTION);
+  g_assert_cmpstr (grl_media_get_certificate (media), ==, "PG-13");
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), imdb_id), ==, "tt0988045");
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), keywords), ==, 15);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), performer), ==, 10);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), producer), ==, 9);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), director), ==, 1);
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), director), ==, "Guy Ritchie");
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), age_certs), ==,
+                   "GB:12A;NL:12;BG:C;HU:16;DE:12;DK:15;US:PG-13");
+
+  shutdown_tmdb ();
+}
+
+int
+main(int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
+
+  grl_init (&argc, &argv);
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test_preconditions ();
+  test_missing_configuration ();
+  test_fast_resolution ();
+  test_full_resolution ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]