Exemple #1
0
void test_ms_scan(void){
	#ifdef WIN32
	const char dir[MAX_PATH_STR_LEN] = "data\\video\\dlna";
	#else
	const char dir[MAX_PATH_STR_LEN] = "data/video/dlna";
	#endif

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->npaths == 0);
	ms_add_path(s, dir);
	CU_ASSERT(s->npaths == 1);
	CU_ASSERT_STRING_EQUAL(s->paths[0], dir);


	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	ms_scan(s);

	ms_destroy(s);
}
Exemple #2
0
void test_ms_file_asf_audio(void)	{
#ifdef WIN32
	char asf_file[MAX_PATH_STR_LEN] = "data\\audio\\wmv92-with-audio.wmv";
#else
	char asf_file[MAX_PATH_STR_LEN] = "data/audio/wmv92-with-audio.wmv";
#endif
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback_1);
	CU_ASSERT(s->on_result == my_result_callback_1);

	// Set up an error callback
	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	// Now scan a valid video file, with an error handler
	ms_errno = 0;
	error_called = FALSE;
	ms_scan_file(s, asf_file, TYPE_VIDEO);
	// Need more info to run this test

	ms_destroy(s);
} /* test_ms_file_asf_audio */
Exemple #3
0
void test_ms_scan_4(void)	{
	char dir[MAX_PATH_STR_LEN] = "notadirectory";
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);


	CU_ASSERT(s->npaths == 0);
	ms_add_path(s, dir);
	CU_ASSERT(s->npaths == 1);
	CU_ASSERT_STRING_EQUAL(s->paths[0], dir);

	// Won't run without the call backs in place
	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	// Okay this is the test, try to scan a non-exsistent directory structure
	ms_scan(s);
	CU_ASSERT(ms_errno == MSENO_DIRECTORYFAIL); // If we got this errno, then we got the failure we wanted

	ms_destroy(s);
} /* test_ms_scan_4 */
Exemple #4
0
void test_ms_scan_3(void)	{

	char dir[MAX_PATH_STR_LEN];
	char dir2[MAX_PATH_STR_LEN];
	int i = 0;

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->npaths == 0);

	// Add 128 Paths to the list, which should work fine
	for(i = 0; i < MAX_PATHS; i++)
	{
		sprintf(dir, "testdir%04d", i);
		CU_ASSERT(s->npaths == (i) );
		ms_add_path(s, dir);
		CU_ASSERT(s->npaths == (i+1) );
		CU_ASSERT_STRING_EQUAL(s->paths[i], dir);
	}

	CU_ASSERT(s->npaths == MAX_PATHS );
	CU_ASSERT_STRING_EQUAL(s->paths[MAX_PATHS - 1], dir);

	strcpy(dir2, dir);
	sprintf(dir, "toomany");
	ms_add_path(s, dir); // This will fail

	// Make sure number of paths hasn't gone up and the last entry is the same
	CU_ASSERT(s->npaths == MAX_PATHS );
	CU_ASSERT_STRING_EQUAL(s->paths[MAX_PATHS - 1], dir2);

	ms_destroy(s);
}
void generate_thumbnails()
{
	FILE *tfp;
	char file[MAX_PATH_STR_LEN];
	int i, n;
	MediaScanImage *thumb;
	Buffer *dbuf;

	MediaScan *s = ms_create();
		ms_set_result_callback(s, my_result_callback);
			ms_set_error_callback(s, my_error_callback); 
			
	ms_add_thumbnail_spec(s, THUMB_PNG, 32,32, TRUE, 0, 90);

	for(i = 0; expected_results[i].filename; i++) 
	{
		ms_scan_file(s, expected_results[i].filename, TYPE_IMAGE);

		if (!strcmp("JPEG", result._thumbs[0]->codec))
			sprintf(file, "%s.jpg", expected_results[i].thumb_filename);
		else
			sprintf(file, "%s.png",expected_results[i].thumb_filename);

		write_png_file(file);
	}


		ms_destroy(s);

}
Exemple #6
0
void test_ms_misc_functions(void)	{
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);


	ms_destroy(s);
} /* test_ms_misc_functions() */
Exemple #7
0
void test_ms_file_scan_1(void)	{
#ifdef WIN32
	char valid_file[MAX_PATH_STR_LEN] = "data\\video\\bars-mpeg4-aac.m4v";
	char invalid_file[MAX_PATH_STR_LEN] = "data\\video\\notafile.m4v";
#else
	char valid_file[MAX_PATH_STR_LEN] = "data/video/bars-mpeg4-aac.m4v";
	char invalid_file[MAX_PATH_STR_LEN] = "data/video/notafile.m4v";
#endif
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	// Check null mediascan oject
	ms_errno = 0;
	ms_scan_file(NULL, invalid_file, TYPE_VIDEO);
	CU_ASSERT(ms_errno == MSENO_NULLSCANOBJ);

	// Check for no callback set
	ms_errno = 0;
	ms_scan_file(s, invalid_file, TYPE_VIDEO);
	CU_ASSERT(ms_errno == MSENO_NORESULTCALLBACK);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback_1);
	CU_ASSERT(s->on_result == my_result_callback_1);

	// Now scan an invalid file, without an error handler
	ms_errno = 0;
	ms_scan_file(s, invalid_file, TYPE_VIDEO);
	CU_ASSERT(ms_errno == MSENO_NOERRORCALLBACK);

	// Set up an error callback
	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	// Now scan an invalid file, with an error handler
	ms_errno = 0;
	error_called = FALSE;
	ms_scan_file(s, invalid_file, TYPE_VIDEO);
	CU_ASSERT(ms_errno != MSENO_NOERRORCALLBACK);
	CU_ASSERT(error_called == TRUE);

	// Now scan a valid video file, with an error handler
	ms_errno = 0;
	error_called = FALSE;
	ms_scan_file(s, valid_file, TYPE_VIDEO);
	// Need more info to run this test

	ms_destroy(s);
} /* test_ms_file_scan_1 */
Exemple #8
0
void test_ms_db(void)	{

#ifdef WIN32
	char valid_file[MAX_PATH_STR_LEN] = "data\\video\\bars-mpeg4-aac.m4v";
#else
	char valid_file[MAX_PATH_STR_LEN] = "data/video/bars-mpeg4-aac.m4v";
#endif

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->npaths == 0);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	ms_errno = 0;
	error_called = FALSE;

	// Okay scan a file
	result_called = FALSE;
	ms_scan_file(s, valid_file, TYPE_VIDEO);
	CU_ASSERT(result_called == TRUE);

	// now scan the same file again and make sure it is skipped
	result_called = FALSE;
	ms_scan_file(s, valid_file, TYPE_VIDEO);
	CU_ASSERT(result_called == FALSE);

	// now scan the same file again, this time with a different modification time and make sure it is scanned
	TouchFile(valid_file);
	result_called = FALSE;
	ms_scan_file(s, valid_file, TYPE_VIDEO);
	CU_ASSERT(result_called == TRUE);

	ms_destroy(s);
} /* test_ms_db() */
Exemple #9
0
void test_ms_scan_2(void)
{
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	// Do not add a path and then attempt to scan
	CU_ASSERT(s->npaths == 0);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	ms_scan(s);

	ms_destroy(s);
}
Exemple #10
0
void audio_process( short *blocks, int len ) {
	msData *ms;
	const char *tmpStr;

	ms = ms_create( blocks, len );

	ms_peaks_find( ms );
	ms_peaks_filter_group( ms );
	peak_save( ms );

	ms_decode_peaks( ms );
	tmpStr = ms_get_bitStream( ms );
	printf("Decoded to bits:\n%s\n", tmpStr );

	if( ms_decode_bits( ms ) ) {
		fprintf( stderr, "Warning: Appears to be unsuccessful swipe!\n" );
		// but will display the data we got anyway...
	}
	tmpStr = ms_get_charStream( ms );
	printf( "Decoded to chars:\n%s\n", tmpStr );

	ms = ms_free( ms );
}
void test_thumbnailing(void)	{
	int i = 0;

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback); 
	CU_ASSERT(s->on_error == my_error_callback);

	ms_add_thumbnail_spec(s, THUMB_PNG, 32,32, TRUE, 0, 90);

	ms_scan_file(s, expected_results[0].filename, TYPE_IMAGE);

	// TODO: Read and compare presaved and approved thumbnails

	ms_destroy(s);
} /* test_thumbnailing() */
Exemple #12
0
void test_ms_large_directory(void)	{
	char dir[MAX_PATH_STR_LEN] = "data";
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->npaths == 0);
	ms_add_path(s, dir);
	CU_ASSERT(s->npaths == 1);
	CU_ASSERT_STRING_EQUAL(s->paths[0], dir);


	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	ms_scan(s);

	ms_destroy(s);
} /* test_ms_misc_functions() */
Exemple #13
0
void test_ms_scan_5(void)	{
		#define NUM_STRINGS 3

	int i = 0;
	char in_dir[NUM_STRINGS][MAX_PATH_STR_LEN] =
		{ "data", "data/", "data\\" };
	char out_dir[NUM_STRINGS][MAX_PATH_STR_LEN] =
		{ "data", "data/", "data\\" };

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	for(i = 0; i < NUM_STRINGS; i++)
	{
	ms_add_path(s, in_dir[i]);
	CU_ASSERT(s->npaths == i + 1);
	CU_ASSERT_STRING_EQUAL(s->paths[i], in_dir[i]);
	}

	// Won't run without the call backs in place
	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	// Run the scan
	ms_errno = 0;
	ms_scan(s);
	CU_ASSERT(ms_errno != MSENO_DIRECTORYFAIL); // Should get no error if the stripping worked correctly

	ms_destroy(s);
} /* test_ms_scan_5 */
Exemple #14
0
void test_ms_scan_6(void)	{
#ifdef WIN32
	char dir[MAX_PATH_STR_LEN] = "data\\audio\\mp3";
#else
	char dir[MAX_PATH_STR_LEN] = "data/audio/mp3";
#endif
	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);


	CU_ASSERT(s->npaths == 0);
	ms_add_path(s, dir);
	CU_ASSERT(s->npaths == 1);
	CU_ASSERT_STRING_EQUAL(s->paths[0], dir);


	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback);
	CU_ASSERT(s->on_error == my_error_callback);

	CU_ASSERT(s->on_progress == NULL);
	ms_set_progress_callback(s, my_progress_callback_6);
	CU_ASSERT(s->on_progress == my_progress_callback_6);


	CU_ASSERT(s->progress->interval == 1); // Verify that the progress interval is set to 1

	ms_set_progress_interval(s, 60);
	CU_ASSERT(s->progress->interval == 60);

	// Reset the callback time
	progress_called = FALSE;
	s->progress->_last_update_ts = 0;
	ms_scan(s);
	CU_ASSERT(progress_called == FALSE);
	#ifdef WIN32
	Sleep(40); // wait 40ms
	#else
	sleep(1);
	#endif
	ms_scan(s);
	CU_ASSERT(progress_called == FALSE);

	// Reset the callback time
	s->progress->_last_update_ts = 0;
	ms_scan(s);
	CU_ASSERT(progress_called == FALSE);

	#ifdef WIN32
	Sleep(61); // wait 61ms
	#else
	sleep(1);
	#endif;

	ms_scan(s);
	CU_ASSERT(progress_called == TRUE);

	ms_destroy(s);

} /* test_ms_scan_6 */
void test_image_reading(void)	{
	int i = 0;

	MediaScan *s = ms_create();

	CU_ASSERT_FATAL(s != NULL);

	CU_ASSERT(s->on_result == NULL);
	ms_set_result_callback(s, my_result_callback);
	CU_ASSERT(s->on_result == my_result_callback);

	CU_ASSERT(s->on_error == NULL);
	ms_set_error_callback(s, my_error_callback); 
	CU_ASSERT(s->on_error == my_error_callback);

	for(i = 0; expected_results[i].filename; i++) 
	{
		error_called = FALSE;
		result_called = FALSE;

		ms_scan_file(s, expected_results[i].filename, TYPE_IMAGE);
	
		if(expected_results[i].failure) {
			CU_ASSERT(error_called);
			continue;
		}
		else {
			CU_ASSERT(result_called);
		}

		CU_ASSERT_PTR_NOT_NULL(result.mime_type);
		if(result.mime_type) {
			CU_ASSERT_STRING_EQUAL(result.mime_type, expected_results[i].mime_type); }

		CU_ASSERT_PTR_NOT_NULL(result.image);
		if(result.image) {
			CU_ASSERT_STRING_EQUAL(result.image->codec, expected_results[i].codec);
			CU_ASSERT(result.image->width == expected_results[i].width);
			CU_ASSERT(result.image->height == expected_results[i].height);
			CU_ASSERT(result.image->channels == expected_results[i].channels);

			if(!strcmp(expected_results[i].codec, "GIF") )
			{
				CU_ASSERT(result.image->_jpeg == NULL);
				CU_ASSERT(result.image->_png == NULL);
				CU_ASSERT(result.image->_bmp == NULL);
		//		CU_ASSERT(result.image->_gif != NULL);
			}
			else if(!strcmp(expected_results[i].codec, "JPEG") )
			{
				CU_ASSERT(result.image->_jpeg != NULL);
				CU_ASSERT(result.image->_png == NULL);
				CU_ASSERT(result.image->_bmp == NULL);
		//		CU_ASSERT(result.image->_gif == NULL);
			}
			else if(!strcmp(expected_results[i].codec, "PNG") )
			{
				CU_ASSERT(result.image->_jpeg == NULL);
				CU_ASSERT(result.image->_png != NULL);
				CU_ASSERT(result.image->_bmp == NULL);
		//		CU_ASSERT(result.image->_gif == NULL);
			}
			else if(!strcmp(expected_results[i].codec, "BMP") )
			{
				CU_ASSERT(result.image->_jpeg == NULL);
				CU_ASSERT(result.image->_png == NULL);
				CU_ASSERT(result.image->_bmp != NULL);
		//		CU_ASSERT(result.image->_gif == NULL);
			}
		}

	}

	ms_destroy(s);
} /* test_image_reading() */