File: action_test.cpp

package info (click to toggle)
swayimg 4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,764 kB
  • sloc: ansic: 13,338; cpp: 2,470; makefile: 9
file content (71 lines) | stat: -rw-r--r-- 1,591 bytes parent folder | download
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
// SPDX-License-Identifier: MIT
// Copyright (C) 2024 Artem Senichev <artemsen@gmail.com>

extern "C" {
#include "action.h"
}

#include <gtest/gtest.h>

class Action : public ::testing::Test {
protected:
    void TearDown() override { action_free(actions); }
    struct action* actions = nullptr;
};

TEST_F(Action, Create)
{
    actions = action_create("info");
    ASSERT_TRUE(actions);
    EXPECT_FALSE(actions->next);
    EXPECT_STREQ(actions->params, "");
    EXPECT_EQ(actions->type, action_info);
}

TEST_F(Action, Fail)
{
    EXPECT_FALSE(action_create(""));
    EXPECT_FALSE(action_create("invalid"));
    EXPECT_FALSE(action_create("info123 exec"));
}

TEST_F(Action, Params)
{
    actions = action_create("exec \t  param 123 ");
    ASSERT_TRUE(actions);
    EXPECT_FALSE(actions->next);
    EXPECT_EQ(actions->type, action_exec);
    EXPECT_STREQ(actions->params, "param 123");
}

TEST_F(Action, Sequence)
{
    actions = action_create("exec cmd;\nreload ;\t exit;status ok");

    struct action* it = actions;
    ASSERT_TRUE(it);
    EXPECT_EQ(it->type, action_exec);
    EXPECT_STREQ(it->params, "cmd");

    it = it->next;
    ASSERT_TRUE(it);
    EXPECT_EQ(it->type, action_reload);
    EXPECT_STREQ(it->params, "");

    it = it->next;
    ASSERT_TRUE(it);
    EXPECT_EQ(it->type, action_exit);
    EXPECT_STREQ(it->params, "");

    it = it->next;
    ASSERT_TRUE(it);
    EXPECT_EQ(it->type, action_status);
    EXPECT_STREQ(it->params, "ok");

    EXPECT_FALSE(it->next);
}

TEST_F(Action, FailSequence)
{
    ASSERT_FALSE(action_create("exec cmd;\nreload;invalid"));
}