commit
85b8125a2a
@ -39,6 +39,8 @@ add_executable(test_freerdp
|
||||
test_list.h
|
||||
test_stream.c
|
||||
test_stream.h
|
||||
test_utils.c
|
||||
test_utils.h
|
||||
test_transport.c
|
||||
test_transport.h
|
||||
test_freerdp.c
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "test_libgdi.h"
|
||||
#include "test_list.h"
|
||||
#include "test_stream.h"
|
||||
#include "test_utils.h"
|
||||
#include "test_transport.h"
|
||||
#include "test_freerdp.h"
|
||||
|
||||
@ -116,6 +117,7 @@ int main(int argc, char* argv[])
|
||||
add_libgdi_suite();
|
||||
add_list_suite();
|
||||
add_stream_suite();
|
||||
add_utils_suite();
|
||||
add_transport_suite();
|
||||
}
|
||||
else
|
||||
@ -138,6 +140,10 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
add_stream_suite();
|
||||
}
|
||||
else if (strcmp("utils", argv[*pindex]) == 0)
|
||||
{
|
||||
add_utils_suite();
|
||||
}
|
||||
else if (strcmp("transport", argv[*pindex]) == 0)
|
||||
{
|
||||
add_transport_suite();
|
||||
|
55
cunit/test_utils.c
Normal file
55
cunit/test_utils.c
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Utils Unit Tests
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
|
||||
#include "test_utils.h"
|
||||
|
||||
int init_utils_suite(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clean_utils_suite(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int add_utils_suite(void)
|
||||
{
|
||||
add_test_suite(utils);
|
||||
|
||||
add_test_function(semaphore);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_semaphore(void)
|
||||
{
|
||||
freerdp_sem sem;
|
||||
|
||||
sem = freerdp_sem_new(1);
|
||||
freerdp_sem_wait(sem);
|
||||
freerdp_sem_signal(sem);
|
||||
freerdp_sem_free(sem);
|
||||
}
|
26
cunit/test_utils.h
Normal file
26
cunit/test_utils.h
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Utils Unit Tests
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "test_freerdp.h"
|
||||
|
||||
int init_list_suite(void);
|
||||
int clean_list_suite(void);
|
||||
int add_list_suite(void);
|
||||
|
||||
void test_semaphore(void);
|
@ -20,8 +20,11 @@
|
||||
#ifndef __SEMAPHORE_UTILS_H
|
||||
#define __SEMAPHORE_UTILS_H
|
||||
|
||||
void freerdp_sem_create(void * sem_struct, int iv);
|
||||
void freerdp_sem_signal(void * sem_struct);
|
||||
void freerdp_sem_wait(void * sem_struct);
|
||||
typedef void* freerdp_sem;
|
||||
|
||||
freerdp_sem freerdp_sem_new(int iv);
|
||||
void freerdp_sem_free(freerdp_sem sem);
|
||||
void freerdp_sem_signal(freerdp_sem sem);
|
||||
void freerdp_sem_wait(freerdp_sem sem);
|
||||
|
||||
#endif /* __SEMAPHORE_UTILS_H */
|
||||
|
@ -17,41 +17,80 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#if defined __APPLE__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
#define freerdp_sem_t semaphore_t
|
||||
|
||||
#elif defined _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#define freerdp_sem_t HANDLE
|
||||
|
||||
#else
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#define freerdp_sem_t sem_t
|
||||
|
||||
#endif
|
||||
|
||||
void freerdp_sem_create(void * sem_struct, int iv)
|
||||
freerdp_sem freerdp_sem_new(int iv)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
semaphore_create(mach_task_self(), (semaphore_t *)sem_struct, SYNC_POLICY_FIFO, iv);
|
||||
freerdp_sem_t* sem;
|
||||
|
||||
sem = (freerdp_sem_t*)xmalloc(sizeof(freerdp_sem_t));
|
||||
|
||||
#if defined __APPLE__
|
||||
semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, iv);
|
||||
#elif defined _WIN32
|
||||
*sem = CreateSemaphore(NULL, 0, iv, NULL);
|
||||
#else
|
||||
int pshared = 0;
|
||||
sem_init((sem_t *)sem_struct, pshared, iv);
|
||||
sem_init(sem, 0, iv);
|
||||
#endif
|
||||
|
||||
return sem;
|
||||
}
|
||||
|
||||
void freerdp_sem_free(freerdp_sem sem)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_destroy(mach_task_self(), *((freerdp_sem_t*)sem));
|
||||
#elif defined _WIN32
|
||||
CloseHandle(*((freerdp_sem_t*)sem));
|
||||
#else
|
||||
sem_destroy((freerdp_sem_t*)sem);
|
||||
#endif
|
||||
|
||||
xfree(sem);
|
||||
}
|
||||
|
||||
void freerdp_sem_signal(freerdp_sem sem)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_signal(*((freerdp_sem_t*)sem));
|
||||
#elif defined _WIN32
|
||||
ReleaseSemaphore(*((freerdp_sem_t*)sem), 1, NULL);
|
||||
#else
|
||||
sem_post((freerdp_sem_t*)sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
void freerdp_sem_signal(void * sem_struct)
|
||||
void freerdp_sem_wait(freerdp_sem sem)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
semaphore_signal(*((semaphore_t *)sem_struct));
|
||||
#if defined __APPLE__
|
||||
semaphore_wait(*((freerdp_sem_t*)sem));
|
||||
#elif defined _WIN32
|
||||
WaitForSingleObject(*((freerdp_sem_t*)sem), INFINITE);
|
||||
#else
|
||||
sem_post((sem_t *)sem_struct);
|
||||
#endif
|
||||
}
|
||||
|
||||
void freerdp_sem_wait(void * sem_struct)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
semaphore_wait(*((semaphore_t *)sem_struct));
|
||||
#else
|
||||
sem_wait((sem_t *)sem_struct);
|
||||
sem_wait((freerdp_sem_t*)sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user