mockspotify 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mockspotify/version.rb +1 -1
- data/lib/mockspotify.rb +1 -0
- data/src/image.c +2 -4
- data/src/link.c +12 -3
- data/src/util.c +45 -3
- data/src/util.h +1 -0
- data/test/mockspotify_spec.rb +18 -0
- metadata +3 -3
data/lib/mockspotify/version.rb
CHANGED
data/lib/mockspotify.rb
CHANGED
data/src/image.c
CHANGED
@@ -19,10 +19,8 @@ mocksp_image_create(const byte image_id[20], sp_imageformat format, size_t data_
|
|
19
19
|
sp_image*
|
20
20
|
sp_image_create_from_link(sp_session *session, sp_link *l)
|
21
21
|
{
|
22
|
-
byte *real_id
|
23
|
-
|
24
|
-
memcpy(image_id, real_id, 20); // TODO: convert "deadbeef" to array of: [0xDE, 0xAD, 0xBE, 0xEF]
|
25
|
-
return mocksp_image_create(image_id, SP_IMAGE_FORMAT_JPEG, 0, NULL, SP_ERROR_OK);
|
22
|
+
byte *real_id = l->data + strlen("spotify:image:");
|
23
|
+
return mocksp_image_create(hextoa(real_id, 40), SP_IMAGE_FORMAT_JPEG, 0, NULL, SP_ERROR_OK);
|
26
24
|
}
|
27
25
|
|
28
26
|
void
|
data/src/link.c
CHANGED
@@ -29,9 +29,18 @@ sp_link_create_from_string(const char *link)
|
|
29
29
|
sp_link *
|
30
30
|
sp_link_create_from_user(sp_user *user)
|
31
31
|
{
|
32
|
-
|
33
|
-
sprintf(link, "spotify:user:%s", user->canonical_name);
|
34
|
-
return
|
32
|
+
sp_link *link = ALLOC(sp_link);
|
33
|
+
sprintf(link->data, "spotify:user:%s", user->canonical_name);
|
34
|
+
return link;
|
35
|
+
}
|
36
|
+
|
37
|
+
sp_link *
|
38
|
+
sp_link_create_from_image(sp_image *image)
|
39
|
+
{
|
40
|
+
sp_link *link = ALLOC(sp_link);
|
41
|
+
sprintf(link->data, "spotify:image:");
|
42
|
+
atohex(link->data + strlen("spotify:image:"), image->image_id, 40);
|
43
|
+
return link;
|
35
44
|
}
|
36
45
|
|
37
46
|
int
|
data/src/util.c
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#include
|
2
|
-
#include <string.h>
|
3
|
-
#include "util.h"
|
1
|
+
#include "libmockspotify.h"
|
4
2
|
|
5
3
|
void*
|
6
4
|
xmalloc(size_t size)
|
@@ -9,3 +7,47 @@ xmalloc(size_t size)
|
|
9
7
|
memset(ptr, 0, size);
|
10
8
|
return ptr;
|
11
9
|
}
|
10
|
+
|
11
|
+
int
|
12
|
+
htoi(char n)
|
13
|
+
{
|
14
|
+
if (n >= '0' && n <= '9') return n - '0';
|
15
|
+
else if (n >= 'a' && n <= 'f') return n - 'a' + 10;
|
16
|
+
else if (n >= 'A' && n <= 'F') return n - 'A' + 10;
|
17
|
+
else return 0;
|
18
|
+
}
|
19
|
+
|
20
|
+
char
|
21
|
+
itoh(int n)
|
22
|
+
{
|
23
|
+
char hex[] = { "0123456789abcdef" };
|
24
|
+
return hex[n];
|
25
|
+
}
|
26
|
+
|
27
|
+
char*
|
28
|
+
hextoa(const char *str, int size)
|
29
|
+
{
|
30
|
+
if (size % 2) return NULL;
|
31
|
+
|
32
|
+
char *result = ALLOC_N(char, size / 2);
|
33
|
+
|
34
|
+
int i;
|
35
|
+
for (i = 0; i < size; i += 2)
|
36
|
+
{
|
37
|
+
result[i/2] = (htoi(str[i]) << 4) + htoi(str[i+1]);
|
38
|
+
}
|
39
|
+
|
40
|
+
return result;
|
41
|
+
}
|
42
|
+
|
43
|
+
void
|
44
|
+
atohex(char *dst, const char *src, int size)
|
45
|
+
{
|
46
|
+
int i;
|
47
|
+
int p;
|
48
|
+
for (i = p = 0; i < size; i += 2, p = i/2)
|
49
|
+
{
|
50
|
+
dst[i] = itoh((src[p] >> 4) & 0x0F);
|
51
|
+
dst[i+1] = itoh(src[p] & 0xF);
|
52
|
+
}
|
53
|
+
}
|
data/src/util.h
CHANGED
data/test/mockspotify_spec.rb
CHANGED
@@ -28,4 +28,22 @@ describe Spotify::Mock do
|
|
28
28
|
Spotify.artist_is_loaded(@artist).must_equal true
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
describe "hextoa" do
|
33
|
+
it "should convert a hexidecimal string properly" do
|
34
|
+
Spotify.attach_function :hextoa, [:string, :int], :string
|
35
|
+
Spotify.hextoa("3A3A", 4).must_equal "::"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "atohex" do
|
40
|
+
it "should convert a byte string to a hexadecimal string" do
|
41
|
+
Spotify.attach_function :atohex, [:buffer_out, :buffer_in, :int], :void
|
42
|
+
|
43
|
+
FFI::Buffer.alloc_out(8) do |b|
|
44
|
+
Spotify.atohex(b, "\x3A\x3A\x0F\xF1", b.size)
|
45
|
+
b.get_string(0, b.size).must_equal "3a3a0ff1"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
31
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mockspotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-07-21 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spotify
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152713800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152713800
|
25
25
|
description:
|
26
26
|
email: kim@burgestrand.se
|
27
27
|
executables: []
|