1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "tarantool/util.h"
#include "errcode.h"
#include <tarantool/tnt.h>
#include <tarantool/tnt_net.h>
#include <tarantool/tnt_io.h>
/** Client handler. Reused between tests. */
struct tnt_stream *t;
#define header() printf("\t*** %s ***\n", __func__)
#define footer() printf("\t*** %s: done ***\n ", __func__)
/** Test the ping command. */
void test_ping()
{
header();
const char message[]= { 0x00, 0xff, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0
};
tnt_io_send_raw(TNT_SNET_CAST(t), (char*)message, sizeof(message), 1);
t->wrcnt++;
struct tnt_iter i;
tnt_iter_reply(&i, t);
tnt_next(&i);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
printf("return_code: %"PRIu32"\n", r->code); /* =0 */
tnt_iter_free(&i);
footer();
}
/** Test the ping command. */
void test_replace()
{
header();
const char message[]= {
0xd, 0x0, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
0x4, 0x1, 0x0, 0x0, 0x0 };
tnt_io_send_raw(TNT_SNET_CAST(t), (char*)message, sizeof(message), 1);
t->wrcnt++;
struct tnt_iter i;
tnt_iter_reply(&i, t);
tnt_next(&i);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
printf("return_code: %"PRIu32"\n", r->code); /* =0 */
tnt_iter_free(&i);
footer();
}
/** A test case for Bug#702397
* https://bugs.launchpad.net/tarantool/+bug/702397 "If SELECT
* request specifies tuple count 0, no error"
*/
void test_bug702397()
{
header();
const char message[]= {
0x11, 0x0, 0x0, 0x0, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0 };
tnt_io_send_raw(TNT_SNET_CAST(t), (char*)message, sizeof(message), 1);
t->wrcnt++;
struct tnt_iter i;
tnt_iter_reply(&i, t);
tnt_next(&i);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
printf("return_code: %s, %s\n",
tnt_errcode_str(TNT_REPLY_ERR(r)), r->error);
tnt_iter_free(&i);
footer();
}
/** A test case for Bug#702399
* https://bugs.launchpad.net/tarantool/+bug/702399
* ERR_CODE_ILLEGAL_PARAMS is returned when there is no such key
*/
void test_bug702399()
{
header();
const char message[]= {
0x11, 0x0, 0x0, 0x0, 0x1d, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0xff, 0xff, 0xff, 0xff,
0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0,
0x4, 0x1, 0x0, 0x0, 0x0 };
tnt_io_send_raw(TNT_SNET_CAST(t), (char*)message, sizeof(message), 1);
t->wrcnt++;
struct tnt_iter i;
tnt_iter_reply(&i, t);
tnt_next(&i);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
printf("return_code: %s, %s\n",
tnt_errcode_str(TNT_REPLY_ERR(r)), r->error);
tnt_iter_free(&i);
footer();
}
/** A test case for Bug#1009992
* https://bugs.launchpad.net/tarantool/+bug/1009992
* ER_ILLEGAL_PARAMS is returned on bad operation id
*/
void test_bug1009992()
{
header();
struct tnt_header h = {
.type = 12345678, /* bad operation */
.len = 0,
.reqid = 0
};
tnt_io_send_raw(TNT_SNET_CAST(t), (char*)&h, sizeof(h), 1);
t->wrcnt++;
struct tnt_iter i;
tnt_iter_reply(&i, t);
tnt_next(&i);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
printf("return_code: %s, %s\n",
tnt_errcode_str(TNT_REPLY_ERR(r)), r->error);
tnt_iter_free(&i);
footer();
}
int main()
{
t = tnt_net(NULL);
if (t == NULL)
return 1;
tnt_set(t, TNT_OPT_HOSTNAME, "localhost");
tnt_set(t, TNT_OPT_PORT, 33013);
if (tnt_init(t) == -1)
return 1;
if (tnt_connect(t) == -1)
return 1;
test_ping();
test_replace();
test_bug702397();
test_bug702399();
test_bug1009992();
tnt_stream_free(t);
return 0;
}
|