-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <assert.h> | ||
#include "test-server.inc" | ||
|
||
int main(void) { | ||
|
||
char track_buffer[512]; | ||
struct sock_data_tag *track = (struct sock_data_tag *)track_buffer; | ||
|
||
track->duration = 35; | ||
track->alboff = 20; | ||
track->titoff = 40; | ||
track->locoff = 60; | ||
strcpy(((char *)(track + 1)), "The Beatles"); | ||
strcpy(((char *)(track + 1)) + 20, ""); | ||
strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); | ||
strcpy(((char *)(track + 1)) + 60, ""); | ||
|
||
/* data communication facility */ | ||
int fd[2]; | ||
assert(pipe(fd) != -1); | ||
|
||
config.nowplaying_localfile = 1; | ||
config.nowplaying_shoutcast = 1; | ||
|
||
track->status = CMSTATUS_PLAYING; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_update_now_playing_count == 1); | ||
|
||
config.nowplaying_localfile = 0; | ||
|
||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_update_now_playing_count == 1); | ||
assert(strcmp(scrobbler_update_now_playing_sbt.artist, "The Beatles") == 0); | ||
assert(strcmp(scrobbler_update_now_playing_sbt.track, "Yellow Submarine") == 0); | ||
|
||
#if ENABLE_LIBNOTIFY | ||
config.notification = 1; | ||
#endif | ||
|
||
track->status |= CMSTATUS_SHOUTCASTMASK; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_update_now_playing_count == 2); | ||
#if ENABLE_LIBNOTIFY | ||
assert(cmusfm_notify_show_count == 1); | ||
#endif | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <assert.h> | ||
|
||
#define DEBUG_SKIP_HICCUP | ||
#include "test-server.inc" | ||
|
||
int main(void) { | ||
|
||
char track_buffer[512]; | ||
struct sock_data_tag *track = (struct sock_data_tag *)track_buffer; | ||
|
||
track->alboff = 20; | ||
track->titoff = 40; | ||
track->locoff = 60; | ||
strcpy(((char *)(track + 1)), "The Beatles"); | ||
strcpy(((char *)(track + 1)) + 20, ""); | ||
strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); | ||
strcpy(((char *)(track + 1)) + 60, ""); | ||
|
||
/* data communication facility */ | ||
int fd[2]; | ||
assert(pipe(fd) != -1); | ||
|
||
config.submit_localfile = 1; | ||
config.submit_shoutcast = 1; | ||
|
||
track->status = CMSTATUS_PLAYING; | ||
track->duration = 35; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
|
||
/* track was played for more than half its duration */ | ||
sleep(track->duration / 2 + 1); | ||
|
||
track->status = CMSTATUS_PLAYING; | ||
track->duration = 35; | ||
strcpy(((char *)(track + 1)) + 40, "For No One"); | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_scrobble_count == 1); | ||
|
||
/* track was played for less than half its duration */ | ||
sleep(track->duration / 2 - 1); | ||
|
||
track->duration = 30; | ||
strcpy(((char *)(track + 1)) + 40, "Doctor Robert"); | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_scrobble_count == 1); | ||
|
||
/* whole track was played but its duration isn't longer than 30 seconds */ | ||
sleep(track->duration); | ||
|
||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_scrobble_count == 1); | ||
|
||
/* short track was overplayed (due to seeking) */ | ||
sleep(track->duration + 10); | ||
|
||
track->status = CMSTATUS_STOPPED; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_scrobble_count == 1); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <assert.h> | ||
|
||
#define DEBUG_SKIP_HICCUP | ||
#include "test-server.inc" | ||
|
||
int main(void) { | ||
|
||
char track_buffer[512]; | ||
struct sock_data_tag *track = (struct sock_data_tag *)track_buffer; | ||
|
||
track->alboff = 20; | ||
track->titoff = 40; | ||
track->locoff = 60; | ||
strcpy(((char *)(track + 1)), "The Beatles"); | ||
strcpy(((char *)(track + 1)) + 20, ""); | ||
strcpy(((char *)(track + 1)) + 40, "Yellow Submarine"); | ||
strcpy(((char *)(track + 1)) + 60, ""); | ||
|
||
/* data communication facility */ | ||
int fd[2]; | ||
assert(pipe(fd) != -1); | ||
|
||
config.submit_localfile = 1; | ||
config.submit_shoutcast = 1; | ||
|
||
track->status = CMSTATUS_PLAYING; | ||
track->duration = 4 * 60 * 5; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
|
||
/* track was played for more than 4 minutes but less than half its duration */ | ||
sleep(4 * 60 + 1); | ||
|
||
track->status = CMSTATUS_STOPPED; | ||
write(fd[1], track_buffer, sizeof(track_buffer)); | ||
cmusfm_server_process_data(fd[0], NULL); | ||
assert(scrobbler_scrobble_count == 1); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "../src/cmusfm.h" | ||
#include "../src/server.c" | ||
#include "../src/utils.c" | ||
|
||
/* global variables used in the server code */ | ||
unsigned char SC_api_key[16] = { 0 }; | ||
unsigned char SC_secret[16] = { 0 }; | ||
struct cmusfm_config config = { 0 }; | ||
const char *cmusfm_config_file = NULL; | ||
const char *cmusfm_socket_file = NULL; | ||
|
||
/* mock subscription subsystem - with the invocation counter */ | ||
scrobbler_trackinfo_t scrobbler_scrobble_sbt = { 0 }; | ||
int scrobbler_scrobble_count = 0; | ||
int scrobbler_scrobble(scrobbler_session_t *sbs, scrobbler_trackinfo_t *sbt) { | ||
memcpy(&scrobbler_scrobble_sbt, sbt, sizeof(scrobbler_scrobble_sbt)); | ||
scrobbler_scrobble_count++; | ||
return 0; | ||
} | ||
|
||
/* mock now-playing subsystem - with the invocation counter */ | ||
scrobbler_trackinfo_t scrobbler_update_now_playing_sbt = { 0 }; | ||
int scrobbler_update_now_playing_count = 0; | ||
int scrobbler_update_now_playing(scrobbler_session_t *sbs, scrobbler_trackinfo_t *sbt) { | ||
memcpy(&scrobbler_update_now_playing_sbt, sbt, sizeof(scrobbler_update_now_playing_sbt)); | ||
scrobbler_update_now_playing_count++; | ||
return 0; | ||
} | ||
|
||
/* mock notification subsystem - with the invocation counter */ | ||
scrobbler_trackinfo_t cmusfm_notify_show_sbt = { 0 }; | ||
int cmusfm_notify_show_count = 0; | ||
void cmusfm_notify_show(const scrobbler_trackinfo_t *sbt, const char *icon) { | ||
memcpy(&cmusfm_notify_show_sbt, sbt, sizeof(cmusfm_notify_show_sbt)); | ||
cmusfm_notify_show_count++; | ||
} | ||
|
||
/* other (irrelevant) functions used by the server code */ | ||
void cmusfm_cache_update(const scrobbler_trackinfo_t *sbt) {} | ||
void cmusfm_cache_submit(scrobbler_session_t *sbs) {} | ||
int cmusfm_config_read(const char *fname, struct cmusfm_config *conf) { return 0; } | ||
int cmusfm_config_add_watch(int fd) { return 0; } | ||
void cmusfm_notify_initialize() {} | ||
void cmusfm_notify_free() {} | ||
scrobbler_session_t *scrobbler_initialize(uint8_t api_key[16], uint8_t secret[16]) { return NULL; } | ||
void scrobbler_free(scrobbler_session_t *sbs) {} | ||
void scrobbler_set_session_key_str(scrobbler_session_t *sbs, const char *str) {} | ||
int scrobbler_test_session_key(scrobbler_session_t *sbs) { return 0; } |