1 /* Gearman server and library
2  * Copyright (C) 2011 Data Differential, http://datadifferential.com/
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 "gear_config.h"
10 #include <libtest/test.hpp>
11 
12 using namespace libtest;
13 
14 #include <cassert>
15 #include <cstdio>
16 #include <cstdlib>
17 #include <cstring>
18 #include <unistd.h>
19 
20 #include <libgearman/gearman.h>
21 
22 #include <tests/basic.h>
23 #include <tests/context.h>
24 
25 #ifndef __INTEL_COMPILER
26 #pragma GCC diagnostic ignored "-Wold-style-cast"
27 #endif
28 
collection_init(void * object)29 static test_return_t collection_init(void *object)
30 {
31   Context *test= (Context *)object;
32   test_true(test);
33 
34   test_truth(test->initialize(NULL));
35 
36   return TEST_SUCCESS;
37 }
38 
collection_cleanup(void * object)39 static test_return_t collection_cleanup(void *object)
40 {
41   Context *test= (Context *)object;
42   test->reset();
43 
44   return TEST_SUCCESS;
45 }
46 
47 
world_create(server_startup_st & servers,test_return_t &)48 static void *world_create(server_startup_st& servers, test_return_t&)
49 {
50   return new Context(default_port(), servers);
51 }
52 
world_destroy(void * object)53 static bool world_destroy(void *object)
54 {
55   Context *test= (Context *)object;
56 
57   delete test;
58 
59   return TEST_SUCCESS;
60 }
61 
62 test_st tests[] ={
63   {"gearman_client_echo()", 0, client_echo_test },
64   {"gearman_client_echo() fail", 0, client_echo_fail_test },
65   {"gearman_worker_echo()", 0, worker_echo_test },
66   {"clean", 0, queue_clean },
67   {"add", 0, queue_add },
68   {"worker", 0, queue_worker },
69   {0, 0, 0}
70 };
71 
72 collection_st collection[] ={
73   {"ephemeral queue", collection_init, collection_cleanup, tests},
74   {0, 0, 0, 0}
75 };
76 
get_world(libtest::Framework * world)77 void get_world(libtest::Framework *world)
78 {
79   world->collections(collection);
80   world->create(world_create);
81   world->destroy(world_destroy);
82 }
83