~clint-fewbar/ubuntu/precise/gearmand/drop-unneeded-patches

« back to all changes in this revision

Viewing changes to tests/tokyocabinet_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2009-09-28 21:43:31 UTC
  • mto: (1.2.3 upstream) (6.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20090928214331-9bku0d3v1b1ypgp4
ImportĀ upstreamĀ versionĀ 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Gearman server and library
2
 
 * Copyright (C) 2008 Brian Aker, Eric Day
3
 
 * All rights reserved.
4
 
 *
5
 
 * Use and distribution licensed under the BSD license.  See
6
 
 * the COPYING file in the parent directory for full text.
7
 
 */
8
 
 
9
 
#include <config.h>
10
 
#include <libtest/test.hpp>
11
 
 
12
 
using namespace libtest;
13
 
 
14
 
#include <assert.h>
15
 
#include <stdio.h>
16
 
#include <stdlib.h>
17
 
#include <string.h>
18
 
#include <unistd.h>
19
 
 
20
 
#include <libgearman/gearman.h>
21
 
 
22
 
#include <tests/basic.h>
23
 
#include <tests/context.h>
24
 
 
25
 
#include <tests/ports.h>
26
 
 
27
 
#ifndef __INTEL_COMPILER
28
 
#pragma GCC diagnostic ignored "-Wold-style-cast"
29
 
#endif
30
 
 
31
 
static test_return_t gearmand_basic_option_test(void *)
32
 
{
33
 
  const char *args[]= { "--check-args",
34
 
    "--queue=libtokyocabinet",
35
 
    "--libtokyocabinet-file=var/tmp/gearman_basic.tcb",
36
 
    "--libtokyocabinet-optimize", 
37
 
    0 };
38
 
 
39
 
  unlink("var/tmp/gearman.tcb");
40
 
  test_compare(EXIT_SUCCESS, exec_cmdline(gearmand_binary(), args, true));
41
 
 
42
 
  return TEST_SUCCESS;
43
 
}
44
 
 
45
 
static test_return_t collection_init(void *object)
46
 
{
47
 
  const char *argv[]= { "test_gearmand",
48
 
    "--libtokyocabinet-file=var/tmp/gearman.tcb",
49
 
    "--queue-type=libtokyocabinet",
50
 
    0 };
51
 
 
52
 
  unlink("var/tmp/gearman.tcb");
53
 
 
54
 
  Context *test= (Context *)object;
55
 
  assert(test);
56
 
 
57
 
  test_truth(test->initialize(3, argv));
58
 
 
59
 
  return TEST_SUCCESS;
60
 
}
61
 
 
62
 
static test_return_t collection_cleanup(void *object)
63
 
{
64
 
  Context *test= (Context *)object;
65
 
  test->reset();
66
 
  unlink("var/tmp/gearman.tcb");
67
 
 
68
 
  return TEST_SUCCESS;
69
 
}
70
 
 
71
 
 
72
 
static void *world_create(server_startup_st& servers, test_return_t& error)
73
 
{
74
 
  if (HAVE_LIBTOKYOCABINET == 0)
75
 
  {
76
 
    error= TEST_SKIPPED;
77
 
    return NULL;
78
 
  }
79
 
 
80
 
  Context *test= new Context(TOKYOCABINET_TEST_PORT, servers);
81
 
  if (not test)
82
 
  {
83
 
    error= TEST_MEMORY_ALLOCATION_FAILURE;
84
 
    return NULL;
85
 
  }
86
 
  unlink("var/tmp/gearman.tcb");
87
 
 
88
 
  return test;
89
 
}
90
 
 
91
 
static bool world_destroy(void *object)
92
 
{
93
 
  Context *test= (Context *)object;
94
 
 
95
 
  unlink("var/tmp/gearman.tcb");
96
 
  delete test;
97
 
 
98
 
  return TEST_SUCCESS;
99
 
}
100
 
 
101
 
test_st gearmand_basic_option_tests[] ={
102
 
  {"--libtokyocabinet-file=var/tmp/gearman_basic.tcb --libtokyocabinet-optimize", 0, gearmand_basic_option_test },
103
 
  {0, 0, 0}
104
 
};
105
 
 
106
 
 
107
 
test_st tests[] ={
108
 
  {"gearman_client_echo()", 0, client_echo_test },
109
 
  {"gearman_client_echo() fail", 0, client_echo_fail_test },
110
 
  {"gearman_worker_echo()", 0, worker_echo_test },
111
 
  {"clean", 0, queue_clean },
112
 
  {"add", 0, queue_add },
113
 
  {"worker", 0, queue_worker },
114
 
  {0, 0, 0}
115
 
};
116
 
 
117
 
collection_st collection[] ={
118
 
  {"gearmand options", 0, 0, gearmand_basic_option_tests},
119
 
  {"tokyocabinet queue", collection_init, collection_cleanup, tests},
120
 
  {0, 0, 0, 0}
121
 
};
122
 
 
123
 
void get_world(Framework *world)
124
 
{
125
 
  world->collections= collection;
126
 
  world->_create= world_create;
127
 
  world->_destroy= world_destroy;
128
 
}