static gboolean get_disc_ids (const gchar *device, gchar **disc_id, gchar **cddb_id, track_t *tracks) { DiscId *disc = discid_new (); g_return_val_if_fail (disc, FALSE); if (discid_read_sparse (disc, device, 0) == 0) { xmms_log_error ("Could not read disc: %s", discid_get_error_msg (disc)); discid_free (disc); return FALSE; } *disc_id = g_strdup (discid_get_id (disc)); if (tracks) { *tracks = discid_get_last_track_num (disc); } if (cddb_id) { *cddb_id = g_strdup (discid_get_freedb_id (disc)); } discid_free (disc); return TRUE; }
int main(int argc, char *argv[]) { int i, first_track, last_track; char *device = NULL; char time_str[14]; int sectors; DiscId *disc; disc = discid_new(); /* If we have an argument, use it as the device name */ if (argc > 1) { device = argv[1]; } else { /* this will use discid_get_default_device() internally */ device = NULL; } if (discid_read_sparse(disc, device, 0) == 0) { fprintf(stderr, "Error: %s\n", discid_get_error_msg(disc)); discid_free(disc); return 1; } printf("DiscID : %s\n", discid_get_id(disc)); printf("FreeDB DiscID : %s\n", discid_get_freedb_id(disc)); first_track = discid_get_first_track_num(disc); last_track = discid_get_last_track_num(disc); printf("First track : %d\n", first_track); printf("Last track : %d\n", last_track); sectors = discid_get_sectors(disc); sectors_to_time(sectors, ROUND_SECONDS, time_str, sizeof time_str); printf("Length : %d sectors (%s)\n", sectors, time_str); for ( i = first_track; i <= last_track; i++ ) { sectors = discid_get_track_length(disc, i); sectors_to_time(sectors, ROUND_SECONDS, time_str, sizeof time_str); printf("Track %-2d : %8d %8d (%s)\n", i, discid_get_track_offset(disc, i), sectors, time_str); } printf("Submit via : %s\n", discid_get_submission_url(disc)); discid_free(disc); return 0; }
static void sj_metadata_musicbrainz4_finalize (GObject *object) { SjMetadataMusicbrainz4Private *priv; priv = GET_PRIVATE (object); if (priv->mb != NULL) { mb4_query_delete (priv->mb); priv->mb = NULL; } if (priv->disc != NULL) { discid_free (priv->disc); priv->disc = NULL; } g_free (priv->cdrom); G_OBJECT_CLASS (sj_metadata_musicbrainz4_parent_class)->finalize (object); }
int main(int argc, char *argv[]) { DiscId *d; char *tmp, *expected; int ret; int ntests = 0, nok = 0; int offsets[] = { 303602, 150, 9700, 25887, 39297, 53795, 63735, 77517, 94877, 107270, 123552, 135522, 148422, 161197, 174790, 192022, 205545, 218010, 228700, 239590, 255470, 266932, 288750, }; d = discid_new(); /* Setting TOC */ printf("Testing discid_put ... "); ret = discid_put(d, 1, 22, offsets); if ( ret ) { printf("OK\n"); nok++; } else printf("Failed\n"); ntests++; /* MusicBrainz DiscID */ printf("Testing discid_get_id ... "); tmp = discid_get_id(d); expected = "xUp1F2NkfP8s8jaeFn_Av3jNEI4-"; if ( strcmp(tmp, expected) == 0 ) { printf("OK\n"); nok++; } else { printf("Failed\n"); printf(" Expected : %s\n", expected); printf(" Actual : %s\n", tmp); } ntests++; /* FreeDB DiscID */ printf("Testing discid_get_freedb_id ... "); tmp = discid_get_freedb_id(d); expected = "370fce16"; if ( strcmp(tmp, expected) == 0 ) { printf("OK\n"); nok++; } else { printf("Failed\n"); printf(" Expected : %s\n", expected); printf(" Actual : %s\n", tmp); } ntests++; /* MusicBrainz web submit URL */ printf("Testing discid_get_submission_url ... "); tmp = discid_get_submission_url(d); expected = "http://mm.musicbrainz.org/bare/cdlookup.html?id=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&tracks=22&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750"; if ( strcmp(tmp, expected) == 0 ) { printf("OK\n"); nok++; } else { printf("Failed\n"); printf(" Expected : %s\n", expected); printf(" Actual : %s\n", tmp); } ntests++; printf("\n%d tests, %d passed, %d failed\n", ntests, nok, ntests - nok); discid_free(d); return ntests != nok; }
int main(int argc, char *argv[]) { DiscId *d; char *features[DISCID_FEATURE_LENGTH]; char *feature; int i, found_features, invalid; int result; announce("discid_get_version_string"); evaluate(strlen(discid_get_version_string()) > 0); announce("discid_get_feature_list"); discid_get_feature_list(features); found_features = 0; invalid = 0; for (i = 0; i < DISCID_FEATURE_LENGTH; i++) { feature = features[i]; if (feature) { found_features++; if (!feature_consistent(feature)) { invalid++; } } } evaluate(!invalid && found_features == discid_has_feature(DISCID_FEATURE_READ) + discid_has_feature(DISCID_FEATURE_MCN) + discid_has_feature(DISCID_FEATURE_ISRC)); announce("discid_get_default_device"); /* this doesn't test much, but shouldn't fail completely * TODO: make sure there is always something > 0 returned */ evaluate(strlen(discid_get_default_device()) >= 0); /* TODO * test access with/without initialization doesn't fail */ announce("discid_new"); d = discid_new(); evaluate(d != NULL); announce("giving invalid device"); result = discid_read(d, "invalid_device_name"); evaluate(!result); announce("discid_get_error_msg"); /* depending on result from invalid read * If that fails, it still is only one failure.*/ if (result) { evaluate(strlen(discid_get_error_msg(d)) == 0); } else { evaluate(strlen(discid_get_error_msg(d)) > 0); } /* announce("empty values"); evaluate(discid_get_id(d) == NULL); */ /* TODO * This needs implementation. * Right now we get segmentation faults in debug builds (assert) * and have to test for NULL in release builds. announce("empty values"); evaluate(strlen(discid_get_id(d)) == 0 && strlen(discid_get_freedb_id(d)) == 0 && strlen(discid_get_submission_url(d)) == 0 && strlen(discid_get_mcn(d)) == 0 && discid_get_first_track_num(d) == 0 && discid_get_last_track_num(d) == 0 && discid_get_sectors(d) == 0); */ announce("discid_free"); discid_free(d); evaluate(1); /* only segfaults etc. would "show" */ return !test_result(); }