Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Commit

Permalink
Fixing mutex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Aug 15, 2016
1 parent fd07c42 commit c89b8b7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 36 deletions.
1 change: 1 addition & 0 deletions Build/NewManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ $NestedModules = @(
".\Interop.ps1",
".\ListDlls.ps1",
'.\ListUsers.ps1',
".\Mutex.ps1",
".\MoveFile.ps1",
".\MemoryMappedFile.ps1",
".\NamedPipes.ps1",
Expand Down
1 change: 0 additions & 1 deletion Hooks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ function Register-PoshHook
$CompilerParameters.ReferencedAssemblies.Add("System.dll") | Out-Null
$CompilerParameters.ReferencedAssemblies.Add("System.Core.dll") | Out-Null
$CompilerParameters.ReferencedAssemblies.Add("System.Runtime.Remoting.dll") | Out-Null
$CompilerParameters.ReferencedAssemblies.Add("EasyHook.dll") | Out-Null
$CompilerParameters.OutputAssembly = $HookPath

Add-Type -Path (Join-Path $PSScriptRoot "HookInject.cs") -CompilerParameters $CompilerParameters | Out-Null
Expand Down
18 changes: 3 additions & 15 deletions Mutex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ function Enter-Mutex
{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true, Mandatory, ParmeterSetName='Mutex')]
[System.Threading.Mutex]$Mutex,
[Parameter(ValueFromPipeline=$true, Mandatory, ParmeterSetName='Name')]
[System.Threading.Mutex]$Name
[Parameter(ValueFromPipeline=$true, Mandatory)]
[System.Threading.Mutex]$Mutex
)

Process {
if ($PSCmdlet.ParameterSetName -eq 'Mutex')
{
$Mutex.WaitOne()
}
elseif ($PSCmdlet.ParameterSetName -eq 'Name')
{

}



$Mutex.WaitOne()
}
}

Expand Down
Binary file modified PoshInternals.psd1
Binary file not shown.
2 changes: 1 addition & 1 deletion Tests/Handle.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Describe "Get-Handle" {
Describe "Get-Handle" {
. (Join-Path $PSScriptRoot 'InitializeTest.ps1')

Context "File is locked" {
Expand Down
26 changes: 9 additions & 17 deletions Tests/Hooks.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
Describe "HooksTest" {
. (Join-Path $PSScriptRoot 'InitializeTest.ps1')

try
{
Register-PoshHook
}
catch
{
Write-Warning $_
return
}

Register-PoshHook

Context "LocalHookTest" {
Set-Hook -Dll "Kernel32.dll" -ReturnType "bool" -EntryPoint "Beep" -Verbose -ScriptBlock {
Context "Local hooked beep set to return false" {
Set-Hook -Dll "Kernel32.dll" -ReturnType "bool" -EntryPoint "Beep" -ScriptBlock {
param([int]$Freq, [int]$Duration)
Write-Host "Frequency was ($Freq) and duration was ($Duration)"
return $true
throw "Exception"
}

[Console]::Beep(1000, 1000)

It "should return false" {
[Console]::Beep(1000, 1000) | Should be $false
}

Get-Hook | Remove-Hook
}

Context "RemoteHookTest" {
$Posh = Start-Process PowerShell -ArgumentList " '& [Console]::Beep()'" -PassThru
$Posh = Start-Process PowerShell -ArgumentList " -noexit '& [Console]::Beep()'" -PassThru

Set-Hook -ProcessId $Posh.ProcessId -Dll "Kernel32.dll" -ReturnType "bool" -EntryPoint "Beep" -ScriptBlock {
param([int]$Freq, [int]$Duration)
Expand Down
2 changes: 0 additions & 2 deletions Tests/Mutex.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Describe "Mutex" {
try {
Enter-Mutex $Mutex

Write-Host 'Ok'

Exit-Mutex $Mutex
}
finally {
Expand Down

0 comments on commit c89b8b7

Please sign in to comment.