Example #1
0
/**
 * call-seq:
 *  read(device=nil)
 * 
 * Read the disc ID from the given device.
 * 
 * If no device is given the default device of the platform will be used.
 * Throws an _Exception_ if the CD's TOC can not be read.
 *
 * Raises:: ArgumentError, TypeError, Exception
 */
static VALUE mb_discid_read(int argc, VALUE *argv, VALUE self)
{
	DiscId *disc;        /* Pointer to the disc struct */
	VALUE device = Qnil; /* The device string as a Ruby string */
	char* cdevice;       /* The device string as a C string */
	
	Data_Get_Struct(self, DiscId, disc);
	
	/* Check the number and types of arguments */
	rb_scan_args(argc, argv, "01", &device);

	/* Use the default device if none was given. */
	if (device == Qnil)
		cdevice = discid_get_default_device();
	else if (rb_respond_to(device, rb_intern("to_s")))
	{
		device = rb_funcall(device, rb_intern("to_s"), 0, 0);
		cdevice = StringValuePtr(device);
	}
	else
		rb_raise(rb_eTypeError, "wrong argument type (expected String)");
	
	/* Mark the disc id as unread in case something goes wrong. */
	rb_iv_set(self, "@read", Qfalse);
	
	/* Read the discid */
	if (discid_read(disc, cdevice) == 0)
		rb_raise(rb_eException, discid_get_error_msg(disc));
	else /* Remember that we already read the ID. */
		rb_iv_set(self, "@read", Qtrue);
	
	return Qnil;
	
}
Example #2
0
int discid_read_sparse(DiscId *d, const char *device, unsigned int features) {
	mb_disc_private *disc = (mb_disc_private *) d;

	assert( disc != NULL );

	if ( device == NULL )
		device = discid_get_default_device();

	assert( device != NULL );

	/* Necessary, because the disc handle could have been used before. */
	memset(disc, 0, sizeof(mb_disc_private));

	return disc->success = mb_disc_read_unportable(disc, device, features);
}
Example #3
0
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();
}