RegressionTests__ExternalInterfaceTests.st
branchjv
changeset 1500 d406a10b2965
parent 1499 26a16a04219b
parent 1447 2351db93aa5b
child 1567 e17701a073f9
equal deleted inserted replaced
1499:26a16a04219b 1500:d406a10b2965
    14 documentation
    14 documentation
    15 "
    15 "
    16     documentation to be added.
    16     documentation to be added.
    17 
    17 
    18     [author:]
    18     [author:]
    19         cg (cg@FUSI)
    19 	cg (cg@FUSI)
    20 
    20 
    21     [instance variables:]
    21     [instance variables:]
    22 
    22 
    23     [class variables:]
    23     [class variables:]
    24 
    24 
    37     "Create a new process running in a separate address space. n.b., we use CreateProcessA
    37     "Create a new process running in a separate address space. n.b., we use CreateProcessA
    38     (the ANSI version) rather than CreateProcessW (the UNICODE/wide version) as we want the
    38     (the ANSI version) rather than CreateProcessW (the UNICODE/wide version) as we want the
    39     daemon, vworad, to receive its command line arguments as ANSI strings not wide strings."
    39     daemon, vworad, to receive its command line arguments as ANSI strings not wide strings."
    40 
    40 
    41     <C: BOOL CreateProcessA(
    41     <C: BOOL CreateProcessA(
    42             LPCTSR imageName,
    42 	    LPCTSR imageName,
    43             LPCTSTR commandLine,
    43 	    LPCTSTR commandLine,
    44             struct SECURITY_ATTRIBUTES *pSecurity,
    44 	    struct SECURITY_ATTRIBUTES *pSecurity,
    45             struct SECURITY_ATTRIBUTES *tSecurity,
    45 	    struct SECURITY_ATTRIBUTES *tSecurity,
    46             BOOL inheritHandles,
    46 	    BOOL inheritHandles,
    47             DWORD creationFlags,
    47 	    DWORD creationFlags,
    48             LPVOID environment,
    48 	    LPVOID environment,
    49             LPTSTR currentDirectoryName,
    49 	    LPTSTR currentDirectoryName,
    50             struct STARTUPINFO *startupInfo,
    50 	    struct STARTUPINFO *startupInfo,
    51             struct PROCESS_INFORMATION *processInfo)>
    51 	    struct PROCESS_INFORMATION *processInfo)>
    52 
    52 
    53 "
    53 "
    54 self new
    54 self new
    55  CreateProcess: 'foo' commandLine: 'foo bla' pSecurity: nil tSecurity: nil inheritHandles: false
    55  CreateProcess: 'foo' commandLine: 'foo bla' pSecurity: nil tSecurity: nil inheritHandles: false
    56  creationFlags: 0 environment: nil currentDirectoryName: 'baz' startupInfo: nil processInfo: nil
    56  creationFlags: 0 environment: nil currentDirectoryName: 'baz' startupInfo: nil processInfo: nil
    57 "
    57 "
    58 !
    58 !
    59 
    59 
    60 TerminateProcess: hProcess exitCode: dwExitCode
    60 TerminateProcess: hProcess exitCode: dwExitCode
    61         "Kill the specified process."
    61 	"Kill the specified process."
    62 
    62 
    63         self primTerminateProcess: hProcess exitCode: 1234
    63 	self primTerminateProcess: hProcess exitCode: 1234
    64 !
    64 !
    65 
    65 
    66 closeHandle: aHandle
    66 closeHandle: aHandle
    67         "Close an OS Handle decrementing it's use count."
    67 	"Close an OS Handle decrementing it's use count."
    68 
    68 
    69         <C: int CloseHandle(HANDLE aHandle)>
    69 	<C: int CloseHandle(HANDLE aHandle)>
    70 !
    70 !
    71 
    71 
    72 primTerminateProcess: hProcess exitCode: dwExitCode
    72 primTerminateProcess: hProcess exitCode: dwExitCode
    73         "Kill the specified process."
    73 	"Kill the specified process."
    74 
    74 
    75         <C: BOOL TerminateProcess(HANDLE hProcess, DWORD dwExitCode)>
    75 	<C: BOOL TerminateProcess(HANDLE hProcess, DWORD dwExitCode)>
    76 !
    76 !
    77 
    77 
    78 setCurrentDirectory: pathName
    78 setCurrentDirectory: pathName
    79         "Set the current working directory."
    79 	"Set the current working directory."
    80 
    80 
    81         <C: BOOL _wincall SetCurrentDirectoryA(LPCTSTR pathName)>
    81 	<C: BOOL _wincall SetCurrentDirectoryA(LPCTSTR pathName)>
    82         ^self externalAccessFailedWith: _errorCode
    82 	^self externalAccessFailedWith: _errorCode
    83 ! !
    83 ! !
    84 
    84 
    85 !ExternalInterfaceTests methodsFor:'structs'!
    85 !ExternalInterfaceTests methodsFor:'structs'!
    86 
    86 
    87 PROCESS_INFORMATION
    87 PROCESS_INFORMATION
    88         "Describes a created process and its main thread."
    88 	"Describes a created process and its main thread."
    89 
    89 
    90         <C: struct PROCESS_INFORMATION {
    90 	<C: struct PROCESS_INFORMATION {
    91                         HANDLE hProcess;
    91 			HANDLE hProcess;
    92                         HANDLE hThread;
    92 			HANDLE hThread;
    93                         DWORD dwProcessId;
    93 			DWORD dwProcessId;
    94                         DWORD dwThreadId;
    94 			DWORD dwThreadId;
    95                 }>
    95 		}>
    96 !
    96 !
    97 
    97 
    98 SECURITY_ATTRIBUTES
    98 SECURITY_ATTRIBUTES
    99         "Describes security of associated process."
    99 	"Describes security of associated process."
   100 
   100 
   101         <C: struct SECURITY_ATTRIBUTES {
   101 	<C: struct SECURITY_ATTRIBUTES {
   102                         DWORD nLength;
   102 			DWORD nLength;
   103                         LPVOID lpSecurityDescriptor;
   103 			LPVOID lpSecurityDescriptor;
   104                         BOOL bInheritHandle;
   104 			BOOL bInheritHandle;
   105                 }>
   105 		}>
   106 !
   106 !
   107 
   107 
   108 STARTUPINFO
   108 STARTUPINFO
   109         "Describes how we want the process to be started."
   109 	"Describes how we want the process to be started."
   110 
   110 
   111         <C: struct STARTUPINFO {
   111 	<C: struct STARTUPINFO {
   112                         DWORD   cb;
   112 			DWORD   cb;
   113                         LPSTR           lpReserved;
   113 			LPSTR           lpReserved;
   114                         LPSTR           lpDesktop;
   114 			LPSTR           lpDesktop;
   115                         LPSTR           lpTitle;
   115 			LPSTR           lpTitle;
   116                         DWORD           dwX;
   116 			DWORD           dwX;
   117                         DWORD           dwY;
   117 			DWORD           dwY;
   118                         DWORD           dwXSize;
   118 			DWORD           dwXSize;
   119                         DWORD           dwYSize;
   119 			DWORD           dwYSize;
   120                         DWORD           dwXCountChars;
   120 			DWORD           dwXCountChars;
   121                         DWORD           dwYCountChars;
   121 			DWORD           dwYCountChars;
   122                         DWORD           dwFillAttribute;
   122 			DWORD           dwFillAttribute;
   123                         DWORD           dwFlags;
   123 			DWORD           dwFlags;
   124                         WORD            wShowWindow;
   124 			WORD            wShowWindow;
   125                         WORD            cbReserved2;
   125 			WORD            cbReserved2;
   126                         LPBYTE          lpReserved2;
   126 			LPBYTE          lpReserved2;
   127                         HANDLE  hStdInput;
   127 			HANDLE  hStdInput;
   128                         HANDLE  hStdOutput;
   128 			HANDLE  hStdOutput;
   129                         HANDLE  hStdError;
   129 			HANDLE  hStdError;
   130                 }>
   130 		}>
   131 ! !
   131 ! !
   132 
   132 
   133 !ExternalInterfaceTests methodsFor:'tests'!
   133 !ExternalInterfaceTests methodsFor:'tests'!
   134 
   134 
   135 test_call_01
   135 test_call_01
   136     |fn|
   136     |fn|
   137 
   137 
   138     OperatingSystem isMSWINDOWSlike ifFalse:[
   138     OperatingSystem isMSWINDOWSlike ifFalse:[
   139         "This test makes sense only on windows"
   139 	"This test makes sense only on windows"
   140         ^ self.
   140 	^ self.
   141     ].
   141     ].
   142 
   142 
   143     fn := ExternalLibraryFunction
   143     fn := ExternalLibraryFunction
   144             name:'Beep' 
   144 	    name:'Beep'
   145             module:'kernel32.dll' 
   145 	    module:'kernel32.dll'
   146             returnType:(CType bool)
   146 	    returnType:(CType bool)
   147             argumentTypes:(Array with:(CType unsignedLong) with:(CType unsignedLong)).
   147 	    argumentTypes:(Array with:(CType unsignedLong) with:(CType unsignedLong)).
   148 
   148 
   149     fn beCallTypeAPI.
   149     fn beCallTypeAPI.
   150     fn invokeWith:440 with:1.
   150     fn invokeWith:440 with:1.
   151 
   151 
   152     "
   152     "
   175 
   175 
   176 DWORD
   176 DWORD
   177     <C: typedef unsigned long DWORD>
   177     <C: typedef unsigned long DWORD>
   178 
   178 
   179     "
   179     "
   180        self new DWORD 
   180        self new DWORD
   181     "
   181     "
   182 !
   182 !
   183 
   183 
   184 HANDLE
   184 HANDLE
   185     <C: typedef void * HANDLE>
   185     <C: typedef void * HANDLE>
   245     "
   245     "
   246 !
   246 !
   247 
   247 
   248 SIZE
   248 SIZE
   249     <C: typedef struct {
   249     <C: typedef struct {
   250             long cx;
   250 	    long cx;
   251             long cy;
   251 	    long cy;
   252     } SIZE>
   252     } SIZE>
   253 
   253 
   254     "
   254     "
   255      self new SIZE
   255      self new SIZE
   256     "
   256     "
   264     "
   264     "
   265 !
   265 !
   266 
   266 
   267 fooType
   267 fooType
   268    <C: struct foo {
   268    <C: struct foo {
   269         long l1;
   269 	long l1;
   270         float f1;
   270 	float f1;
   271    }>
   271    }>
   272 
   272 
   273     "
   273     "
   274      self new fooType
   274      self new fooType
   275     "
   275     "
   285 
   285 
   286 var2
   286 var2
   287     <C: #define var1 "hello">
   287     <C: #define var1 "hello">
   288 
   288 
   289     "
   289     "
   290      self new var2  
   290      self new var2
   291     "
   291     "
   292 !
   292 !
   293 
   293 
   294 var3
   294 var3
   295     <C: #define var1 1.2345>
   295     <C: #define var1 1.2345>
   296 
   296 
   297     "
   297     "
   298      self new var3  
   298      self new var3
   299     "
   299     "
   300 ! !
   300 ! !
   301 
   301 
   302 !ExternalInterfaceTests class methodsFor:'documentation'!
   302 !ExternalInterfaceTests class methodsFor:'documentation'!
   303 
   303