File: xid_test.cpp

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (90 lines) | stat: -rw-r--r-- 2,427 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (C) 2020 Codership Oy <info@codership.com>
 *
 * This file is part of wsrep-lib.
 *
 * Wsrep-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Wsrep-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "wsrep/xid.hpp"
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(xid_test_is_null)
{
    wsrep::xid null_xid;
    BOOST_REQUIRE(null_xid.is_null());
    wsrep::xid test_xid(1,0,0,nullptr);
    BOOST_REQUIRE(!test_xid.is_null());
}

BOOST_AUTO_TEST_CASE(xid_test_equal)
{
    wsrep::xid a(1,1,1,"ab");
    wsrep::xid b(1,1,1,"ab");
    BOOST_REQUIRE(a == b);
}

BOOST_AUTO_TEST_CASE(xid_test_null_equal)
{
    wsrep::xid a;
    wsrep::xid b;
    BOOST_REQUIRE(a == b);
    BOOST_REQUIRE(a.is_null());
}

BOOST_AUTO_TEST_CASE(xid_test_not_equal)
{
    wsrep::xid a(1,1,0,"a");
    wsrep::xid b(1,0,1,"a");
    wsrep::xid c(-1,1,0,"a");
    wsrep::xid d(1,1,0,"b");
    BOOST_REQUIRE(!(a == b));
    BOOST_REQUIRE(!(a == c));
    BOOST_REQUIRE(!(a == d));
}

BOOST_AUTO_TEST_CASE(xid_clear)
{
    wsrep::xid null_xid;
    wsrep::xid to_clear(1, 1, 0, "a");
    to_clear.clear();
    BOOST_REQUIRE(to_clear.is_null());
    BOOST_REQUIRE(null_xid == to_clear);
}

BOOST_AUTO_TEST_CASE(xid_to_string)
{
    wsrep::xid null_xid;
    std::stringstream null_xid_str;
    null_xid_str << null_xid;
    BOOST_REQUIRE(null_xid_str.str() == "");

    wsrep::xid test_xid(1,4,0,"test");
    std::string xid_str(to_string(test_xid));
    BOOST_REQUIRE(xid_str == "test");
}

static bool exception_check(const wsrep::runtime_error&)
{
    return true;
}

BOOST_AUTO_TEST_CASE(xid_too_big)
{
    std::string s(65,'a');
    BOOST_REQUIRE_EXCEPTION(wsrep::xid a(1, 65, 0, s.c_str()),
                            wsrep::runtime_error, exception_check);
    BOOST_REQUIRE_EXCEPTION(wsrep::xid b(1, 0, 65, s.c_str()),
                            wsrep::runtime_error, exception_check);
}