示例#1
0
static int
do_test (void)
{
  /* The test-in-container framework sets these environment variables.
     The presence of GCONV_PATH invalidates this test.  */
  unsetenv ("GCONV_PATH");
  unsetenv ("LOCPATH");

  /* Create the gconv module cache.  iconvconfig is in /sbin, which is
     not on PATH.  */
  {
    char *iconvconfig = xasprintf ("%s/iconvconfig", support_sbindir_prefix);
    TEST_COMPARE (system (iconvconfig), 0);
  }

  /* Use built-in ASCII gconv module, without triggering cache
     initialization.  */
  FILE *fp1 = xfopen ("/dev/zero", "r");
  TEST_COMPARE (fwide (fp1, 1), 1);

  /* Use non-ASCII gconv module and trigger gconv cache
     initialization.  */
  FILE *fp2 = xfopen ("/dev/zero", "r,ccs=UTF-8");
  TEST_COMPARE (fwide (fp2, 0), 1);

  xfclose (fp1);
  xfclose (fp2);

  return 0;
}
示例#2
0
static void *
tf (void *arg)
{
  pthread_rwlock_t *r = arg;

  /* Timeout: 0.3 secs.  */
  struct timespec ts_start;
  xclock_gettime (CLOCK_REALTIME, &ts_start);
  const struct timespec ts_timeout = timespec_add (ts_start,
                                                   make_timespec (0, 300000000));

  TEST_COMPARE (pthread_rwlock_timedwrlock (r, &ts_timeout), ETIMEDOUT);
  puts ("child: timedwrlock failed with ETIMEDOUT");

  TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts_timeout);

  struct timespec ts_invalid;
  xclock_gettime (CLOCK_REALTIME, &ts_invalid);
  ts_invalid.tv_sec += 10;
  /* Note that the following operation makes ts invalid.  */
  ts_invalid.tv_nsec += 1000000000;

  TEST_COMPARE (pthread_rwlock_timedwrlock (r, &ts_invalid), EINVAL);

  puts ("child: timedwrlock failed with EINVAL");

  return NULL;
}
示例#3
0
static void
one_test (const char *message, int error_code, const wchar_t *expected)
{
  wchar_t *buffer = NULL;
  size_t length = 0;
  FILE *fp = open_wmemstream (&buffer, &length);
  TEST_VERIFY_EXIT (fp != NULL);
  FILE *old_stderr = stderr;
  stderr = fp;
  errno = error_code;
  switch (error_code)
    {
    case E2BIG:
      warn ("%s with padding " PADDING, message);
      break;
    case EAGAIN:
      warn ("%s", message);
      break;
    case -1:
      warnx ("%s", message);
      break;
    case -2:
      warnx ("%s with padding " PADDING, message);
      break;
    }
  stderr = old_stderr;
  TEST_VERIFY_EXIT (!ferror (fp));
  TEST_COMPARE (fclose (fp), 0);
  if (wcscmp (buffer, expected) != 0)
    FAIL_EXIT1 ("unexpected output: %ls", buffer);
  free (buffer);
}
void CQueueLinkedListTests::testIsEmpty()
{
	std::cout << "CSinglyLinkedListTests::testIsEmpty  \t\t";
	CQueueLinkedList queueLinkedList;
	std::string sOutput;
	APPEND_INT_TEST_OUTPUT(queueLinkedList.isEmpty(), sOutput);
	queueLinkedList.enqueue(1);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.isEmpty(), sOutput);
	queueLinkedList.enqueue(1);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.isEmpty(), sOutput);
	TEST_COMPARE(sOutput, "1 0 0 ");
}
示例#5
0
static int
do_test (void)
{
  sem_t s;
  struct timespec ts;
  struct timeval tv;

  TEST_COMPARE (sem_init (&s, 0, 1), 0);
  TEST_COMPARE (TEMP_FAILURE_RETRY (sem_wait (&s)), 0);
  TEST_COMPARE (gettimeofday (&tv, NULL), 0);

  TIMEVAL_TO_TIMESPEC (&tv, &ts);

  /* We wait for half a second.  */
  ts.tv_nsec += 500000000;
  if (ts.tv_nsec >= 1000000000)
    {
      ++ts.tv_sec;
      ts.tv_nsec -= 1000000000;
    }

  errno = 0;
  TEST_COMPARE (TEMP_FAILURE_RETRY (sem_timedwait (&s, &ts)), -1);
  TEST_COMPARE (errno, ETIMEDOUT);

  struct timespec ts2;
  TEST_COMPARE (clock_gettime (CLOCK_REALTIME, &ts2), 0);

  TEST_VERIFY (ts2.tv_sec > ts.tv_sec
               || (ts2.tv_sec == ts.tv_sec && ts2.tv_nsec > ts.tv_nsec));

  return 0;
}
示例#6
0
static int
do_test (void)
{
  TEST_VERIFY_EXIT (setlocale (LC_ALL, "de_DE.UTF-8") != NULL);
  /* Fill the stdio buffer and advance the read pointer.  */
  TEST_VERIFY_EXIT (fgetwc (stdin) != WEOF);
  /* This calls _IO_wfile_sync, it should not crash.  */
  TEST_VERIFY_EXIT (setvbuf (stdin, NULL, _IONBF, 0) == 0);
  /* Verify that the external file offset has been synchronized.  */
  TEST_COMPARE (xlseek (0, 0, SEEK_CUR), 1);

  return 0;
}
示例#7
0
static void
run_query (const char *query, const char *address)
{
  char *quoted_query = support_quote_string (query);
  char *context = xasprintf ("gethostbyname (\"%s\")", quoted_query);
  char *expected = xasprintf ("name: %s\n"
                              "address: %s\n", query, address);
  check_hostent (context, gethostbyname (query), expected);
  free (context);

  context = xasprintf ("gethostbyname_r \"%s\"", quoted_query);
  struct hostent storage;
  char buf[4096];
  struct hostent *e = NULL;
  TEST_COMPARE (gethostbyname_r (query, &storage, buf, sizeof (buf),
                                 &e, &h_errno), 0);
  check_hostent (context, e, expected);
  free (context);

  context = xasprintf ("gethostbyname2 (\"%s\", AF_INET)", quoted_query);
  check_hostent (context, gethostbyname2 (query, AF_INET), expected);
  free (context);

  context = xasprintf ("gethostbyname2_r \"%s\" AF_INET", quoted_query);
  e = NULL;
  TEST_COMPARE (gethostbyname2_r (query, AF_INET, &storage, buf, sizeof (buf),
                                  &e, &h_errno), 0);
  check_hostent (context, e, expected);
  free (context);
  free (expected);

  free (quoted_query);

  /* The gethostbyname tests are always valid for getaddrinfo, but not
     vice versa.  */
  run_query_addrinfo (query, address);
}
示例#8
0
static int
do_test (void)
{
  /* Check handling of the empty blob, both with and without trailing
     NUL byte.  */
  char *p = support_quote_blob ("", 0);
  TEST_COMPARE (strlen (p), 0);
  free (p);
  p = support_quote_blob ("X", 0);
  TEST_COMPARE (strlen (p), 0);
  free (p);

  /* Check escaping of backslash-escaped characters, and lack of
     escaping for other shell meta-characters.  */
  p = support_quote_blob ("$()*?`@[]{}~\'\"X", 14);
  TEST_COMPARE (strcmp (p, "$()*?`@[]{}~\\'\\\""), 0);
  free (p);

  /* Check lack of escaping for letters and digits.  */
#define LETTERS_AND_DIGTS                       \
  "abcdefghijklmnopqrstuvwxyz"                  \
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                  \
  "0123456789"
  p = support_quote_blob (LETTERS_AND_DIGTS "@", 2 * 26 + 10);
  TEST_COMPARE (strcmp (p, LETTERS_AND_DIGTS), 0);
  free (p);

  /* Check escaping of control characters and other non-printable
     characters.  */
  p = support_quote_blob ("\r\n\t\a\b\f\v\1\177\200\377\0@", 14);
  TEST_COMPARE (strcmp (p, "\\r\\n\\t\\a\\b\\f\\v\\001"
                        "\\177\\200\\377\\000@\\000"), 0);
  free (p);

  return 0;
}
示例#9
0
int
do_test (void)
{
  /* The easiest way to set up the conditions under which you can
     notice whether the end-of-file indicator is sticky, is with a
     pseudo-tty.  This is also the case which applications are most
     likely to care about.  And it avoids any question of whether and
     how it is legitimate to access the same physical file with two
     independent FILE objects.  */
  int outer_fd, inner_fd;
  FILE *fp;

  support_openpty (&outer_fd, &inner_fd, 0, 0, 0);
  fp = fdopen (inner_fd, "r+");
  if (!fp)
    {
      perror ("fdopen");
      return 1;
    }

  XWRITE (outer_fd, "abc\n\004", "first line + EOF");
  TEST_COMPARE (fgetwc (fp), L'a');
  TEST_COMPARE (fgetwc (fp), L'b');
  TEST_COMPARE (fgetwc (fp), L'c');
  TEST_COMPARE (fgetwc (fp), L'\n');
  TEST_COMPARE (fgetwc (fp), WEOF);

  TEST_VERIFY_EXIT (feof (fp));
  TEST_VERIFY_EXIT (!ferror (fp));

  XWRITE (outer_fd, "d\n", "second line");

  /* At this point, there is a new full line of input waiting in the
     kernelside input buffer, but we should still observe EOF from
     stdio, because the end-of-file indicator has not been cleared.  */
  TEST_COMPARE (fgetwc (fp), WEOF);

  /* Clearing EOF should reveal the next line of input.  */
  clearerr (fp);
  TEST_COMPARE (fgetwc (fp), L'd');
  TEST_COMPARE (fgetwc (fp), L'\n');

  fclose (fp);
  close (outer_fd);
  return 0;
}
void CQueueLinkedListTests::testEnqueue()
{
	std::cout << "CQueueLinkedListTests::testEnqueue  \t\t";
	CQueueLinkedList queueLinkedList;
	queueLinkedList.enqueue(1);
	queueLinkedList.enqueue(2);
	queueLinkedList.enqueue(3);
	queueLinkedList.enqueue(4);
	queueLinkedList.enqueue(5);
	queueLinkedList.enqueue(6);
	std::stringstream ss;
	queueLinkedList.printList_itr(ss);

	TEST_COMPARE(ss.str(), "1 2 3 4 5 6 \n");
}
void TestUpdaterOptions::testOldFormatArgs()
{
    const int argc = 6;
    char* argv[argc];
    argv[0] = strdup("updater");

    std::string currentDir("CurrentDir=");
    const char* appDir = 0;

    // CurrentDir is the path to the directory containing the main
    // Mendeley Desktop binary, on Linux and Mac this differs from
    // the root of the install directory
#if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
    appDir = "/tmp/path-to-app/lib/mendeleydesktop/libexec/";
    FileUtils::mkpath(appDir);
#elif defined(PLATFORM_MAC)
    appDir = "/tmp/path-to-app/Contents/MacOS/";
    FileUtils::mkpath(appDir);
#elif defined(PLATFORM_WINDOWS)
    appDir = "C:/path/to/app/";
#endif
    currentDir += appDir;

    argv[1] = strdup(currentDir.c_str());
    argv[2] = strdup("TempDir=/tmp/updater");
    argv[3] = strdup("UpdateScriptFileName=/tmp/updater/file_list.xml");
    argv[4] = strdup("AppFileName=/path/to/app/theapp");
    argv[5] = strdup("PID=123456");

    UpdaterOptions options;
    options.parse(argc,argv);

    TEST_COMPARE(options.mode,UpdateInstaller::Setup);
#if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD)
    TEST_COMPARE(options.installDir,"/tmp/path-to-app");
#elif defined(PLATFORM_MAC)
    // /tmp is a symlink to /private/tmp on Mac
    TEST_COMPARE(options.installDir,"/private/tmp/path-to-app");
#else
    TEST_COMPARE(options.installDir,"C:/path/to/app/");
#endif
    TEST_COMPARE(options.packageDir,"/tmp/updater");
    TEST_COMPARE(options.scriptPath,"/tmp/updater/file_list.xml");
    TEST_COMPARE(options.waitPid,123456);

    for (int i=0; i < argc; i++)
    {
        free(argv[i]);
    }
}
示例#12
0
static int
do_test (void)
{
  char *tempfile;
  int fd;

  /* Create a temporary file and open it in read-only mode.  */
  TEST_VERIFY_EXIT (create_temp_file ("tst-bz11319", &tempfile));
  fd = xopen (tempfile, O_RDONLY, 0660);

  /* Try and write to the temporary file to intentionally fail, then
     check that dprintf (or __dprintf_chk) return EOF.  */
  TEST_COMPARE (dprintf (fd, "%d", 0), EOF);

  xclose (fd);
  free (tempfile);

  return 0;
}
void CQueueLinkedListTests::testSize()
{
	std::cout << "CQueueLinkedListTests::testSize  \t\t";
	CQueueLinkedList queueLinkedList;
	std::string sOutput;
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	queueLinkedList.enqueue(6);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	queueLinkedList.enqueue(5);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	queueLinkedList.enqueue(4);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	queueLinkedList.enqueue(3);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	queueLinkedList.enqueue(2);
	queueLinkedList.enqueue(1);
	APPEND_INT_TEST_OUTPUT(queueLinkedList.size(), sOutput);
	TEST_COMPARE(sOutput, "0 1 2 3 4 6 "); //This is the ASCII output
}
示例#14
0
static void
wide (const char *path)
{
  FILE *old_stdin = stdin;
  stdin = xfopen (path, "r");

  TEST_COMPARE (getwchar (), L'a');
  TEST_COMPARE (getwchar_unlocked (), L'b');
  wchar_t ch = 1;
  TEST_COMPARE (wscanf (L"%lc", &ch), 1);
  TEST_COMPARE (ch, L'c');
  TEST_COMPARE (call_vwscanf (L"%lc", &ch), 1);
  TEST_COMPARE (ch, L'd');

  fclose (stdin);
  stdin = old_stdin;
}
示例#15
0
static void
narrow (const char *path)
{
  FILE *old_stdin = stdin;
  stdin = xfopen (path, "r");

  TEST_COMPARE (getchar (), 'a');
  TEST_COMPARE (getchar_unlocked (), 'b');
  char ch = 1;
  TEST_COMPARE (scanf ("%c", &ch), 1);
  TEST_COMPARE (ch, 'c');
  TEST_COMPARE (call_vscanf ("%c", &ch), 1);
  TEST_COMPARE (ch, 'd');
  char buf[8];
  memset (buf, 'X', sizeof (buf));

  /* Legacy interface.  */
  extern char *gets (char *);
  TEST_VERIFY (gets (buf) == buf);
  TEST_COMPARE_BLOB (buf, sizeof (buf), "ef\0XXXXX", sizeof (buf));

  fclose (stdin);
  stdin = old_stdin;
}
示例#16
0
static int
do_test (void)
{
  struct in_addr addr = { };

  TEST_COMPARE (__inet_aton_exact ("192.0.2.1", &addr), 1);
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000201);

  TEST_COMPARE (__inet_aton_exact ("192.000.002.010", &addr), 1);
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000208);
  TEST_COMPARE (__inet_aton_exact ("0xC0000234", &addr), 1);
  TEST_COMPARE (ntohl (addr.s_addr), 0xC0000234);

  /* Trailing content is not accepted.  */
  TEST_COMPARE (__inet_aton_exact ("192.0.2.2X", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.3 Y", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.4\nZ", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.5\tT", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.6 Y", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.7\n", &addr), 0);
  TEST_COMPARE (__inet_aton_exact ("192.0.2.8\t", &addr), 0);

  return 0;
}