forked from artemsen/swayimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_test.cpp
69 lines (59 loc) · 2.14 KB
/
action_test.cpp
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
// SPDX-License-Identifier: MIT
// Copyright (C) 2024 Artem Senichev <[email protected]>
extern "C" {
#include "action.h"
}
#include <gtest/gtest.h>
class Action : public ::testing::Test {
protected:
void TearDown() override { action_free(&actions); }
struct action_seq actions = { nullptr, 0 };
};
TEST_F(Action, Create)
{
ASSERT_TRUE(action_create("info", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(1));
ASSERT_NE(actions.sequence, nullptr);
ASSERT_EQ(actions.sequence[0].type, action_info);
ASSERT_EQ(actions.sequence[0].params, nullptr);
}
TEST_F(Action, Fail)
{
ASSERT_FALSE(action_create("", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(0));
ASSERT_EQ(actions.sequence, nullptr);
ASSERT_FALSE(action_create("invalid", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(0));
ASSERT_EQ(actions.sequence, nullptr);
ASSERT_FALSE(action_create("info123 exec", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(0));
ASSERT_EQ(actions.sequence, nullptr);
}
TEST_F(Action, Params)
{
ASSERT_TRUE(action_create("exec \t param 123 ", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(1));
ASSERT_NE(actions.sequence, nullptr);
ASSERT_EQ(actions.sequence[0].type, action_exec);
ASSERT_STREQ(actions.sequence[0].params, "param 123");
}
TEST_F(Action, Sequence)
{
ASSERT_TRUE(action_create("exec cmd;\nreload;\t exit;status ok", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(4));
ASSERT_NE(actions.sequence, nullptr);
ASSERT_EQ(actions.sequence[0].type, action_exec);
ASSERT_STREQ(actions.sequence[0].params, "cmd");
ASSERT_EQ(actions.sequence[1].type, action_reload);
ASSERT_EQ(actions.sequence[1].params, nullptr);
ASSERT_EQ(actions.sequence[2].type, action_exit);
ASSERT_EQ(actions.sequence[2].params, nullptr);
ASSERT_EQ(actions.sequence[3].type, action_status);
ASSERT_STREQ(actions.sequence[3].params, "ok");
}
TEST_F(Action, FailSequence)
{
ASSERT_FALSE(action_create("exec cmd;\nreload;invalid", &actions));
ASSERT_EQ(actions.num, static_cast<size_t>(0));
ASSERT_EQ(actions.sequence, nullptr);
}