Debian Codegraph @

test/unit/test_command.c

raw
1 #include <sqlite3.h>
2
3 #include "../../src/command.h"
4
5 #include "../lib/runner.h"
6
7 TEST_MODULE(command);
8
9 /******************************************************************************
10 *
11 * Open.
12 *
13 ******************************************************************************/
14
15 TEST_SUITE(open);
16
17 TEST_CASE(open, encode, NULL)
18 {
19 struct command_open c;
20 struct raft_buffer buf;
21 int rc;
22 (void)data;
23 (void)params;
24 c.filename = "test.db";
25 rc = command__encode(COMMAND_OPEN, &c, &buf);
26 munit_assert_int(rc, ==, 0);
27 munit_assert_int(buf.len, ==, 16);
28 raft_free(buf.base);
29 return MUNIT_OK;
30 }
31
32 TEST_CASE(open, decode, NULL)
33 {
34 struct command_open c1;
35 void *c2;
36 int type;
37 struct raft_buffer buf;
38 int rc;
39 (void)data;
40 (void)params;
41 c1.filename = "db";
42 rc = command__encode(COMMAND_OPEN, &c1, &buf);
43 munit_assert_int(rc, ==, 0);
44 rc = command__decode(&buf, &type, &c2);
45 munit_assert_int(rc, ==, 0);
46 munit_assert_int(type, ==, COMMAND_OPEN);
47 munit_assert_string_equal(((struct command_open *)c2)->filename, "db");
48 raft_free(c2);
49 raft_free(buf.base);
50 return MUNIT_OK;
51 }