add fake connection to C API
This commit is contained in:
		
							parent
							
								
									960f12ebc5
								
							
						
					
					
						commit
						f8f5dd0d4f
					
				
					 2 changed files with 31 additions and 1 deletions
				
			
		|  | @ -1201,6 +1201,20 @@ SPCommand *sp_command_hard_reset(void); | |||
|  */ | ||||
| SPCommand *sp_command_try_from_packet(SPPacket *packet); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new instance of [SPConnection] for testing that does not actually send anything. | ||||
|  * | ||||
|  * returns: a new instance. Will never return NULL. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_connection_free`. | ||||
|  */ | ||||
| SPConnection *sp_connection_fake(void); | ||||
| 
 | ||||
| /**
 | ||||
|  * Closes and deallocates a [SPConnection]. | ||||
|  * | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ | |||
| //! prefix `sp_connection_`
 | ||||
| 
 | ||||
| use std::ffi::{c_char, CStr}; | ||||
| use std::ptr::null_mut; | ||||
| use std::ptr::{null_mut, NonNull}; | ||||
| 
 | ||||
| use crate::{SPCommand, SPPacket}; | ||||
| 
 | ||||
|  | @ -46,6 +46,22 @@ pub unsafe extern "C" fn sp_connection_open( | |||
|     Box::into_raw(Box::new(SPConnection(connection))) | ||||
| } | ||||
| 
 | ||||
| /// Creates a new instance of [SPConnection] for testing that does not actually send anything.
 | ||||
| ///
 | ||||
| /// returns: a new instance. Will never return NULL.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - the returned instance is freed in some way, either by using a consuming function or
 | ||||
| ///   by explicitly calling `sp_connection_free`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_connection_fake() -> NonNull<SPConnection> { | ||||
|     let result = Box::new(SPConnection(servicepoint::Connection::Fake)); | ||||
|     NonNull::from(Box::leak(result)) | ||||
| } | ||||
| 
 | ||||
| /// Sends a [SPPacket] to the display using the [SPConnection].
 | ||||
| ///
 | ||||
| /// The passed `packet` gets consumed.
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter