summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-08-18 05:04:09 +0000
committerStefan Schmidt <s.schmidt@samsung.com>2020-08-19 15:59:55 +0200
commit047b59d9345076fa927b7af747b4b90da31637eb (patch)
treebb4e7bc5cca26ae01930e20752264e9f7d3be24e
parentf6672c91a8fb65e04dc5bb6bbb37fb6d72b11715 (diff)
eet test: use eina_file_mkstemp, fix include for vc++
Reviewed-by: João Paulo Taylor Ienczak Zanette <joao.tiz@expertisesolutions.com.br> Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org> Differential Revision: https://phab.enlightenment.org/D12108
-rw-r--r--src/tests/eet/eet_test_cache.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/tests/eet/eet_test_cache.c b/src/tests/eet/eet_test_cache.c
index 6dee39142c..36acb414db 100644
--- a/src/tests/eet/eet_test_cache.c
+++ b/src/tests/eet/eet_test_cache.c
@@ -3,7 +3,11 @@
3#endif 3#endif
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6#include <unistd.h> 6#ifdef _WIN32
7# include <io.h> /* close(), unlink() */
8#else
9# include <unistd.h> /* close(), unlink() */
10#endif
7 11
8#include <Eina.h> 12#include <Eina.h>
9#include <Eet.h> 13#include <Eet.h>
@@ -46,33 +50,33 @@ _open_close_worker(void *path, Eina_Thread tid EINA_UNUSED)
46 50
47EFL_START_TEST(eet_test_cache_concurrency) 51EFL_START_TEST(eet_test_cache_concurrency)
48{ 52{
49 char *file;
50 const char *buffer = "test data"; 53 const char *buffer = "test data";
51 Eet_File *ef; 54 Eet_File *ef;
52 void *thread_ret; 55 void *thread_ret;
53 unsigned int n; 56 unsigned int n;
54 Eina_Thread thread; 57 Eina_Thread thread;
58 Eina_Tmpstr *tmpfile = NULL;
55 Eina_Bool r; 59 Eina_Bool r;
56 int tmpfd; 60 int tmpfd;
57 61
58 file = strdup("/tmp/eet_suite_testXXXXXX");
59
60 eina_threads_init(); 62 eina_threads_init();
61 63
62 eina_lock_new(&open_worker_mutex); 64 eina_lock_new(&open_worker_mutex);
63 eina_condition_new(&open_worker_cond, &open_worker_mutex); 65 eina_condition_new(&open_worker_cond, &open_worker_mutex);
64 66
65 /* create a file to test with */ 67 /* create a file to test with */
66 fail_if(-1 == (tmpfd = mkstemp(file))); 68 /* tmpfile will be created in temporary directory (with eina_environment_tmp) */
69 tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpfile);
70 fail_if(-1 == tmpfd);
67 fail_if(!!close(tmpfd)); 71 fail_if(!!close(tmpfd));
68 ef = eet_open(file, EET_FILE_MODE_WRITE); 72 ef = eet_open(tmpfile, EET_FILE_MODE_WRITE);
69 fail_if(!ef); 73 fail_if(!ef);
70 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); 74 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
71 75
72 eina_lock_take(&open_worker_mutex); 76 eina_lock_take(&open_worker_mutex);
73 /* start a thread that repeatedly opens and closes a file */ 77 /* start a thread that repeatedly opens and closes a file */
74 open_worker_stop = 0; 78 open_worker_stop = 0;
75 r = eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, _open_close_worker, file); 79 r = eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, _open_close_worker, tmpfile);
76 fail_unless(r); 80 fail_unless(r);
77 81
78 eina_condition_wait(&open_worker_cond); 82 eina_condition_wait(&open_worker_cond);
@@ -91,9 +95,10 @@ EFL_START_TEST(eet_test_cache_concurrency)
91 95
92 eet_close(ef); 96 eet_close(ef);
93 97
94 fail_if(unlink(file) != 0); 98 fail_if(unlink(tmpfile) != 0);
95 99
96 eina_threads_shutdown(); 100 eina_threads_shutdown();
101 eina_tmpstr_del(tmpfile);
97} 102}
98EFL_END_TEST 103EFL_END_TEST
99 104