Skip to content
Browse files

- Added small test script to find borken providers, not yet fully wor…

…king, but already found some brokeness

- made that silly providernname work for ruby
- killed a few bugs in the bindings
- more tests will follow..
- Removing Gly_cachelist from the core is planned.
- Release after this proably.
  • Loading branch information...
1 parent 2f889f8 commit 868a3797cb4b79075326c8c4f5d9ef918a018634 @sahib committed Jun 25, 2011
Showing with 212 additions and 40 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 CHANGELOG
  3. +4 −4 gui/guilyr.rb
  4. +29 −1 lib/glyr.c
  5. +10 −1 lib/glyr.h
  6. +12 −12 lib/types.h
  7. +1 −2 swig/glyr.i
  8. +20 −20 swig/glyros.rb
  9. +129 −0 test/provider_quicktest.rb
View
3 .gitignore
@@ -13,6 +13,9 @@ cmake_install.cmake
install_manifest.txt
Makefile
+# testoutput
+test/out/*
+
# swig
*_wrap.c
View
4 CHANGELOG
@@ -88,3 +88,7 @@ Found some time to work a bit here :-)
----------
+ added support for proxy. (only basic libcurl support, should be suffiecient for 99% of all cases)
+ made API *much* slicker & nicer
+
+2011/06/25
+----------
+- CHANGELOG discontinued, use the git commit history instead
View
8 gui/guilyr.rb
@@ -62,7 +62,7 @@ def initialize(path, data, artist, album, title)
if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
puts "filename = #{dialog.filename}"
- Glyros::writeFile(Glyros::GlyQuery.new,data,dialog.filename)
+ data.write_file(filename)
end
dialog.destroy
end
@@ -182,7 +182,7 @@ def load_image_from_url( url )
q = Glyros::GlyQuery.new
cache = Glyros::download(url,q)
path = "/tmp/guilyr_simphoto_#{@@similiar_photo_count}.img"
- Glyros::writeFile(q,cache,path)
+ cache.write_file(path)
@@similiar_photo_count += 1
pixbuf = nil
@@ -395,8 +395,8 @@ def on_searchButton_clicked
unless results.size == 0
results.each do |c|
- path = "/tmp/guilyr_item_#{i}.img"
- m.write_file(path,c) if c.is_image
+ path = "/tmp/guilyr_item_#{i}.img"
+ c.write_file(path) if c.is_image
self.add_item(path,c, @artistEntry.text, @albumEntry.text, @titleEntry.text)
end
@statusbar.push(@statusbar_info,"Done: found #{results.size} item(s)")
View
30 lib/glyr.c
@@ -665,7 +665,7 @@ int Gly_write(GlyMemCache * data, const char * path)
}
else
{
- FILE * fp = fopen(path,"wb" /* welcome back */);
+ FILE * fp = fopen(path,"w" /* welcome back */);
if(fp)
{
if(data->data != NULL)
@@ -705,6 +705,34 @@ const char ** GlyPlug_get_name_by_id(enum GLYR_GET_TYPE ID)
/*-----------------------------------------------*/
+const char * GlyPlug_get_single_name_by_id(enum GLYR_GET_TYPE ID)
+{
+ const char * result = NULL;
+ GlyPlugin * plug = Gly_get_provider_by_id(ID);
+ if(plug != NULL)
+ {
+ size_t i = 0;
+ while(plug[i].name != NULL)
+ {
+ const char * old = result;
+ result = strdup_printf("%s%s%s",(old == NULL) ? "" : old
+ ,(old == NULL) ? "" : "|"
+ ,plug[i].name);
+
+
+ if(old != NULL) {
+ free((char*)old);
+ }
+
+ i++;
+ }
+ free(plug);
+ }
+ return result;
+}
+
+/*-----------------------------------------------*/
+
const char * GlyPlug_get_key_by_id(enum GLYR_GET_TYPE ID)
{
char * result = NULL;
View
11 lib/glyr.h
@@ -489,6 +489,16 @@ extern "C"
* @return a nullterminated list of available providers
*/
const char ** GlyPlug_get_name_by_id(enum GLYR_GET_TYPE ID);
+
+/**
+* @brief Same as GlyPlug_get_name_by_id, but returns single string
+*
+* @param ID What type to get, or GET_UNSURE for a list of getters
+*
+* @return a nullterminated string of providers, seperated with '|'
+*/
+ const char * GlyPlug_get_single_name_by_id(enum GLYR_GET_TYPE ID);
+
/**
* @brief Get a nullterminated list of available providers, with their name as key
*
@@ -549,7 +559,6 @@ extern "C"
*/
const char * Gly_groupname_by_id(enum GLYR_GROUPS ID);
-
/**
* @brief Returns versioning information, including compiletime
*
View
24 lib/types.h
@@ -92,17 +92,17 @@ enum GLYR_ERROR {
* Requirements are given in braces, [] means optional.
*/
enum GLYR_GET_TYPE {
- GET_COVERART, /*!< Get coverart for (artist|album) */
- GET_LYRICS, /*!< Get lyrics for (artist|[album]|artist) */
- GET_ARTIST_PHOTOS, /*!< Get pics for (artist) */
- GET_ARTISTBIO, /*!< Get bio of (artist) */
- GET_SIMILIAR_ARTISTS, /*!< Get similiar artists to (artist) */
- GET_ALBUM_REVIEW, /*!< Get album review to (artist|album) */
- GET_TRACKLIST, /*!< Get list of tracks for album (artist|album) */
- GET_TAGS, /*!< Get tags (i.e. words like 'Metal') for (artist|[album]|[title]) */
- GET_RELATIONS, /*!< Get relations (e.g. links to last.fm/wikipedia) for (artist|[album]|[title]) */
- GET_ALBUMLIST, /*!< Get a list of albums by (artist) */
- GET_UNSURE /*!< Do nothing but relax */
+ GET_COVERART = 1, /*!< Get coverart for (artist|album) */
+ GET_LYRICS = 2, /*!< Get lyrics for (artist|[album]|artist) */
+ GET_ARTIST_PHOTOS = 3, /*!< Get pics for (artist) */
+ GET_ARTISTBIO = 4, /*!< Get bio of (artist) */
+ GET_SIMILIAR_ARTISTS = 5, /*!< Get similiar artists to (artist) */
+ GET_ALBUM_REVIEW = 6, /*!< Get album review to (artist|album) */
+ GET_TRACKLIST = 7, /*!< Get list of tracks for album (artist|album) */
+ GET_TAGS = 8, /*!< Get tags (i.e. words like 'Metal') for (artist|[album]|[title]) */
+ GET_RELATIONS = 9, /*!< Get relations (e.g. links to last.fm/wikipedia) for (artist|[album]|[title]) */
+ GET_ALBUMLIST= 10, /*!< Get a list of albums by (artist) */
+ GET_UNSURE = 11 /*!< Do nothing but relax */
};
/**
@@ -234,7 +234,7 @@ typedef enum GLYR_ERROR (*DL_callback)(GlyMemCache * dl, struct GlyQuery * s);
{
GlyQuery()
{
- GlyQuery my_query;
+ GlyQuery my_query;
Gly_init_query(&my_query);
GlyQuery * copy = malloc(sizeof(GlyQuery));
memcpy(copy,&my_query,sizeof(GlyQuery));
View
3 swig/glyr.i
@@ -8,7 +8,7 @@
* + By using SWIG you just can use the compile.sh by replacing 'ruby' with <your_lang>
* + Ruby bindings e.g. are so incredible easy to use after writing a wrapper class
*/
-
+
/* module name */
%module glyros
@@ -22,7 +22,6 @@
%include "../lib/glyr.h"
%include "../lib/types.h"
-
/* make sure libglyr wakes up */
%init
%{
View
40 swig/glyros.rb
@@ -5,10 +5,11 @@
begin
# Load C library
- require "glyros"
+ require_relative "../bin/ruby/glyros"
rescue LoadError => e
puts "-- Error while loading Glyr's ruby module"
- puts "-- It is supposed to be in the same path as this script"
+ puts "-- It is supposed to be in the bin/ruby directory"
+ puts "-- ..did you build it? (cmake . -DSWIG_RUBY)"
exit(-1)
end
@@ -34,6 +35,10 @@ def self.instance_by_copy(copy_me)
return copy.register_free
end
+ def write_file(path)
+ return Glyros::Gly_write(self,path)
+ end
+
# disable ctor
private_class_method :new
@@ -66,7 +71,7 @@ def finalize
end
-class GlyrosQuery
+class GlyrosSpit
# members
@query = nil
@providers = nil
@@ -96,20 +101,19 @@ def version
return Glyros::Gly_version()
end
- def key_by_id(get_id)
+ def self.key_by_id(get_id)
return Glyros::GlyPlug_get_key_by_id(get_id)
end
- def gid_by_id(get_id)
+ def self.gid_by_id(get_id)
return Glyros::GlyPlug_get_gid_by_id(get_id)
end
- # not working yet
- def name_by_id(get_id)
- return Glyros::GlyPlug_get_key_by_id(get_id)
+ def self.name_by_id(get_id)
+ return Glyros::GlyPlug_get_single_name_by_id(get_id)
end
- def groupname_by_id(get_id)
+ def self.groupname_by_id(get_id)
return Glyros::Gly_groupname_by_id(get_id)
end
=begin
@@ -150,10 +154,6 @@ def title=(title)
def type
return @query.type
end
-
- def write_file( path, cache )
- return Glyros::Gly_write(cache,path)
- end
def number=(num)
Glyros::GlyOpt_number(@query,num)
@@ -320,7 +320,7 @@ def call_get
def test_me
# Note the dots at the end.
- q = GlyrosQuery.new
+ q = GlyrosSpit.new
q.artist = "Die Apokalyptischen Reiter"
q.album = "Moral & Wahnsinn"
q.title = "Die Boten"
@@ -330,11 +330,11 @@ def test_me
end
def use_strange_functions
- puts GlyrosQuery.new.key_by_id(Glyros::GET_LYRICS)
- puts GlyrosQuery.new.name_by_id(Glyros::GET_LYRICS)
- GlyrosQuery.new.gid_by_id(Glyros::GET_LYRICS).each_byte { |int| print "#{int} " }
- puts "\n",GlyrosQuery.new.groupname_by_id(Glyros::GRP_FAST)
+ puts GlyrosSpit.new.key_by_id(Glyros::GET_LYRICS)
+ puts GlyrosSpit.new.name_by_id(Glyros::GET_LYRICS)
+ GlyrosSpit.new.gid_by_id(Glyros::GET_LYRICS).each_byte { |int| print "#{int} " }
+ puts "\n",GlyrosSpit.new.groupname_by_id(Glyros::GRP_FAST)
end
-test_me()
-use_strange_functions()
+#test_me()
+#use_strange_functions()
View
129 test/provider_quicktest.rb
@@ -0,0 +1,129 @@
+#!/usr/bin/ruby
+# This is a very simple script to test if providers are working as expected
+# It may need some work still, as tags relations are a little harder to test,
+# Three queries are created, and filled with popular acts (or known to be found)
+# Those are tested for every provider and marked with DONE if found at least 2/3
+# If 0 were found you should have a look there..
+#
+# P.S: Sorry, the providernames are not working yet
+
+require 'rubygems'
+
+begin
+ require_relative '../swig/glyros.rb'
+rescue LoadError => e
+ puts "-- Cannot test, you monster"
+ puts "-- Reason: #{e}"
+end
+
+begin
+ require 'rainbow'
+rescue LoadError => e
+ puts "-- disabling colors"
+ class String
+ def color(sym)
+ #no color here
+ self
+ end
+ end
+end
+
+$FAILSTRING = "[" + "FAIL".color(:red) + "]"
+$DONESTRING = "[" + "DONE".color(:green) + "]"
+
+ # Actual testing here
+begin
+ trap("INT") do
+ puts
+ puts "## Interrupted Test, you monster!! ".color(:red)
+ puts "## Exiting therefore. Good testing.".color(:red)
+ exit(-1)
+ end
+
+
+ adele = GlyrosSpit.new
+ rider = GlyrosSpit.new
+ equilibrium = GlyrosSpit.new
+
+
+puts GlyrosSpit.name_by_id(Glyros::GET_UNSURE)
+
+
+ # Lyrics
+ adele.artist = "Adele"
+ adele.album = "21"
+ adele.title = "Rolling In The Deep"
+ adele.fuzzyness = 6
+
+
+ rider.artist = "Die Apokalyptischen Reiter"
+ rider.album = "Moral & Wahnsinn"
+ rider.title = "Wir reiten"
+ rider.fuzzyness = 6
+
+
+ equilibrium.artist = "Equilibrium"
+ equilibrium.album = "Sagas"
+ equilibrium.title = "Blut im Auge"
+ equilibrium.fuzzyness = 6
+
+
+ gKeys = GlyrosSpit.key_by_id(Glyros::GET_UNSURE)
+ gNums = 0
+
+ dTest = 0
+ dPass = 0
+
+ GlyrosSpit.gid_by_id(Glyros::GET_UNSURE).each_byte do |type|
+ passed = 0
+ tested = 0
+
+ puts " -- Testing getter '#{gKeys[gNums]}'"
+ GlyrosSpit.key_by_id(type).each_char do |key|
+ print " -- Testing provider '#{key}' "
+
+ # Set origin
+ adele.from = key
+ rider.from = key
+ equilibrium.from = key
+
+ threads = [], ad = [], ri = [], eq = []
+ threads.push Thread.new { ad = adele.get(type) }
+ threads.push Thread.new { ri = rider.get(type) }
+ threads.push Thread.new { eq = equilibrium.get(type) }
+ threads.each { |t| t.join }
+
+ list = ad + ri + eq
+ if list.size < 2
+ print $FAILSTRING
+ else
+ print $DONESTRING
+ passed += 1
+ end
+
+ print " [" +
+ (ad.empty? ? "x".color(:red) : "v".color(:green)) + "|" +
+ (ri.empty? ? "x".color(:red) : "v".color(:green)) + "|" +
+ (eq.empty? ? "x".color(:red) : "v".color(:green)) +
+ "]\n"
+
+ list.each do |item|
+ item.write_file(File.dirname(__FILE__) + "/out/" + gKeys[gNums] + "_" + key + (item.is_image ? ".img" : ".txt"))
+ end
+
+
+ tested += 1
+ end
+ puts " -- Passed #{passed.to_s.color(:red)} of #{tested.to_s.color(:green)} tests. (#{((passed.to_f / tested.to_f)*100).to_i}%)"
+ gNums += 1
+
+
+ dPass += passed
+ dTest += tested
+ end
+
+ puts "-- In total: #{dPass}/#{dTest} (#{((dPass.to_f / dTest.to_f)*100).to_i})%"
+ puts "-- => Battle station fully operational?"
+ puts "-- Thanks for testing, you monster."
+end
+

0 comments on commit 868a379

Please sign in to comment.
Something went wrong with that request. Please try again.