mirror of
				https://github.com/winfsp/winfsp.git
				synced 2025-10-30 19:48:38 -05:00 
			
		
		
		
	winfsp-tests: memfs-test, create-test
This commit is contained in:
		
							
								
								
									
										29
									
								
								tst/winfsp-tests/create-test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tst/winfsp-tests/create-test.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| #include <winfsp/winfsp.h> | ||||
| #include <tlib/testsuite.h> | ||||
| #include "memfs.h" | ||||
|  | ||||
| void *memfs_start(ULONG Flags); | ||||
| void memfs_stop(void *data); | ||||
|  | ||||
| extern int WinFspDiskTests; | ||||
| extern int WinFspNetTests; | ||||
|  | ||||
| void create_dotest(ULONG Flags) | ||||
| { | ||||
|     void *memfs = memfs_start(Flags); | ||||
|  | ||||
|     memfs_stop(memfs); | ||||
| } | ||||
|  | ||||
| void create_test(void) | ||||
| { | ||||
|     if (WinFspDiskTests) | ||||
|         create_dotest(MemfsDisk); | ||||
|     if (WinFspNetTests) | ||||
|         create_dotest(MemfsNet); | ||||
| } | ||||
|  | ||||
| void create_tests(void) | ||||
| { | ||||
|     TEST(create_test); | ||||
| } | ||||
							
								
								
									
										79
									
								
								tst/winfsp-tests/memfs-test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								tst/winfsp-tests/memfs-test.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| #include <winfsp/winfsp.h> | ||||
| #include <tlib/testsuite.h> | ||||
| #include <process.h> | ||||
| #include "memfs.h" | ||||
|  | ||||
| extern int WinFspDiskTests; | ||||
| extern int WinFspNetTests; | ||||
|  | ||||
| struct memfs_data | ||||
| { | ||||
|     MEMFS *Memfs; | ||||
|     HANDLE Thread; | ||||
| }; | ||||
|  | ||||
| static unsigned __stdcall memfs_thread(void *Memfs0) | ||||
| { | ||||
|     MEMFS *Memfs = Memfs0; | ||||
|     return FspFileSystemLoop(MemfsFileSystem(Memfs)); | ||||
| } | ||||
|  | ||||
| void *memfs_start(ULONG Flags) | ||||
| { | ||||
|     struct memfs_data *data; | ||||
|     MEMFS *Memfs; | ||||
|     HANDLE Thread; | ||||
|     NTSTATUS Result; | ||||
|  | ||||
|     data = malloc(sizeof *data); | ||||
|     ASSERT(0 != data); | ||||
|  | ||||
|     Result = MemfsCreate(Flags, 1000, 65500, &Memfs); | ||||
|     ASSERT(NT_SUCCESS(Result)); | ||||
|     ASSERT(0 != Memfs); | ||||
|  | ||||
|     Thread = (HANDLE)_beginthreadex(0, 0, memfs_thread, Memfs, 0, 0); | ||||
|     ASSERT(0 != Thread); | ||||
|  | ||||
|     data->Memfs = Memfs; | ||||
|     data->Thread = Thread; | ||||
|  | ||||
|     return data; | ||||
| } | ||||
|  | ||||
| void memfs_stop(void *data) | ||||
| { | ||||
|     MEMFS *Memfs = ((struct memfs_data *)data)->Memfs; | ||||
|     HANDLE Thread = ((struct memfs_data *)data)->Thread; | ||||
|     DWORD ExitCode; | ||||
|  | ||||
|     FspFileSystemSetDispatcherResult(MemfsFileSystem(Memfs), STATUS_CANCELLED); | ||||
|  | ||||
|     WaitForSingleObject(Thread, INFINITE); | ||||
|     GetExitCodeThread(Thread, &ExitCode); | ||||
|     CloseHandle(Thread); | ||||
|  | ||||
|     ASSERT(STATUS_CANCELLED == ExitCode); | ||||
|  | ||||
|     MemfsDelete(Memfs); | ||||
| } | ||||
|  | ||||
| void memfs_dotest(ULONG Flags) | ||||
| { | ||||
|     void *memfs = memfs_start(Flags); | ||||
|  | ||||
|     memfs_stop(memfs); | ||||
| } | ||||
|  | ||||
| void memfs_test(void) | ||||
| { | ||||
|     if (WinFspDiskTests) | ||||
|         memfs_dotest(MemfsDisk); | ||||
|     if (WinFspNetTests) | ||||
|         memfs_dotest(MemfsNet); | ||||
| } | ||||
|  | ||||
| void memfs_tests(void) | ||||
| { | ||||
|     TEST(memfs_test); | ||||
| } | ||||
| @@ -419,3 +419,8 @@ VOID MemfsDelete(MEMFS *Memfs) | ||||
|  | ||||
|     free(Memfs); | ||||
| } | ||||
|  | ||||
| FSP_FILE_SYSTEM *MemfsFileSystem(MEMFS *Memfs) | ||||
| { | ||||
|     return Memfs->FileSystem; | ||||
| } | ||||
|   | ||||
| @@ -26,6 +26,7 @@ enum | ||||
| NTSTATUS MemfsCreate(ULONG Flags, ULONG MaxFileNodes, ULONG MaxFileSize, | ||||
|     MEMFS **PMemfs); | ||||
| VOID MemfsDelete(MEMFS *Memfs); | ||||
| FSP_FILE_SYSTEM *MemfsFileSystem(MEMFS *Memfs); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|   | ||||
| @@ -8,6 +8,8 @@ int main(int argc, char *argv[]) | ||||
|     TESTSUITE(path_tests); | ||||
|     TESTSUITE(mount_tests); | ||||
|     TESTSUITE(timeout_tests); | ||||
|     TESTSUITE(memfs_tests); | ||||
|     TESTSUITE(create_tests); | ||||
|  | ||||
|     tlib_run_tests(argc, argv); | ||||
|     return 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user