Changeset 14288


Ignore:
Timestamp:
Jun 8, 2014, 7:09:41 PM (8 years ago)
Author:
jordan
Message:

separate out the sandbox code so that test sandboxes can be created without a tr_session

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/libtransmission-test.c

    r14241 r14288  
    123123#include "variant.h"
    124124
    125 tr_session * session = NULL;
    126 char * sandbox = NULL;
    127 char * downloadDir = NULL;
    128 char * blocklistDir = NULL;
     125/***
     126****
     127***/
    129128
    130129static char*
     
    147146
    148147  return tr_strdup (buf);
     148}
     149
     150char *
     151libtest_sandbox_create (void)
     152{
     153  const char * path = tr_getcwd ();
     154  char * sandbox = tr_buildPath (path, "sandbox-XXXXXX", NULL);
     155  tr_mkdtemp (sandbox);
     156  return sandbox;
    149157}
    150158
     
    180188}
    181189
     190void
     191libtest_sandbox_destroy (const char * sandbox)
     192{
     193  rm_rf (sandbox);
     194}
     195
     196/***
     197****
     198***/
     199
    182200#define MEM_K 1024
    183201#define MEM_B_STR   "B"
     
    218236    settings = &local_settings;
    219237
    220   path = tr_getcwd ();
    221   sandbox = tr_buildPath (path, "sandbox-XXXXXX", NULL);
    222   tr_mkdtemp (sandbox);
    223   tr_free (path);
     238  sandbox = libtest_sandbox_create ();
    224239
    225240  if (!formatters_inited)
     
    276291libttest_session_close (tr_session * session)
    277292{
    278   char * path;
    279 
    280   path = tr_strdup (tr_sessionGetConfigDir (session));
     293  char * sandbox;
     294
     295  sandbox = tr_strdup (tr_sessionGetConfigDir (session));
    281296  tr_sessionClose (session);
    282297  tr_logFreeQueue (tr_logGetQueue ());
    283298  session = NULL;
    284299
    285   rm_rf (path);
    286   tr_free (path);
     300  libtest_sandbox_destroy (sandbox);
     301  tr_free (sandbox);
    287302}
    288303
     
    416431    tr_wait_msec (10);
    417432}
     433
     434void
     435libtest_create_file_with_contents (const char * path, const char * str)
     436{
     437  FILE * fp;
     438  char * dir;
     439  const int tmperr = errno;
     440
     441  dir = tr_dirname (path);
     442  errno = 0;
     443  tr_mkdirp (dir, 0700);
     444  assert (errno == 0);
     445  tr_free (dir);
     446
     447  tr_remove (path);
     448  fp = fopen (path, "wb");
     449  fprintf (fp, "%s", str);
     450  fclose (fp);
     451
     452  sync ();
     453
     454  errno = tmperr;
     455}
     456
  • trunk/libtransmission/libtransmission-test.h

    r14241 r14288  
    8484void         libttest_blockingTorrentVerify (tr_torrent * tor);
    8585
     86void         libtest_create_file_with_contents (const char * path, const char * str);
     87
     88char*        libtest_sandbox_create (void);
     89void         libtest_sandbox_destroy (const char * sandbox);
     90
     91
     92
    8693
    8794
  • trunk/libtransmission/rename-test.c

    r14241 r14288  
    9494
    9595static void
    96 create_file_with_contents (const char * path, const char * str)
    97 {
    98   FILE * fp;
    99   char * dir;
    100   const int tmperr = errno;
    101 
    102   dir = tr_dirname (path);
    103   errno = 0;
    104   tr_mkdirp (dir, 0700);
    105   assert (errno == 0);
    106   tr_free (dir);
    107 
    108   tr_remove (path);
    109   fp = fopen (path, "wb");
    110   fprintf (fp, "%s", str);
    111   fclose (fp);
    112 
    113   sync ();
    114 
    115   errno = tmperr;
    116 }
    117 
    118 static void
    11996create_single_file_torrent_contents (const char * top)
    12097{
    12198  char * path = tr_buildPath (top, "hello-world.txt", NULL);
    122   create_file_with_contents (path, "hello, world!\n");
     99  libtest_create_file_with_contents (path, "hello, world!\n");
    123100  tr_free (path);
    124101}
     
    265242
    266243  path = tr_buildPath (top, "Felidae", "Felinae", "Acinonyx", "Cheetah", "Chester", NULL);
    267   create_file_with_contents (path, "It ain't easy bein' cheesy.\n");
     244  libtest_create_file_with_contents (path, "It ain't easy bein' cheesy.\n");
    268245  tr_free (path);
    269246
    270247  path = tr_buildPath (top, "Felidae", "Pantherinae", "Panthera", "Tiger", "Tony", NULL);
    271   create_file_with_contents (path, "They’re Grrrrreat!\n");
     248  libtest_create_file_with_contents (path, "They’re Grrrrreat!\n");
    272249  tr_free (path);
    273250
    274251  path = tr_buildPath (top, "Felidae", "Felinae", "Felis", "catus", "Kyphi", NULL);
    275   create_file_with_contents (path, "Inquisitive\n");
     252  libtest_create_file_with_contents (path, "Inquisitive\n");
    276253  tr_free (path);
    277254
    278255  path = tr_buildPath (top, "Felidae", "Felinae", "Felis", "catus", "Saffron", NULL);
    279   create_file_with_contents (path, "Tough\n");
     256  libtest_create_file_with_contents (path, "Tough\n");
    280257  tr_free (path);
    281258
Note: See TracChangeset for help on using the changeset viewer.