-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_applet.cpp
More file actions
51 lines (39 loc) · 1.89 KB
/
Copy pathtest_applet.cpp
File metadata and controls
51 lines (39 loc) · 1.89 KB
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
#include <cfbox/applet.hpp>
#include <gtest/gtest.h>
using namespace cfbox::applet;
// ── fake applet functions ─────────────────────────────────────
static int fake_echo([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { return 0; }
static int fake_cat([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { return 1; }
// ── test registry ─────────────────────────────────────────────
constexpr auto TEST_REGISTRY = std::to_array<AppEntry>({
{"echo", fake_echo, "display a line of text"},
{"cat", fake_cat, "concatenate files"},
});
// ── AppEntry fields ───────────────────────────────────────────
TEST(AppletTest, EntryFields) {
const auto& entry = TEST_REGISTRY[0];
EXPECT_EQ(entry.app_name, "echo");
EXPECT_EQ(entry.help, "display a line of text");
EXPECT_EQ(entry.app_func, fake_echo);
}
// ── find_applet ───────────────────────────────────────────────
TEST(AppletTest, FindExisting) {
const auto* found = find_applet("echo", TEST_REGISTRY);
ASSERT_NE(found, nullptr);
EXPECT_EQ(found->app_name, "echo");
EXPECT_EQ(found->app_func, fake_echo);
}
TEST(AppletTest, FindLast) {
const auto* found = find_applet("cat", TEST_REGISTRY);
ASSERT_NE(found, nullptr);
EXPECT_EQ(found->app_name, "cat");
EXPECT_EQ(found->app_func, fake_cat);
}
TEST(AppletTest, FindMissing) {
const auto* found = find_applet("nonexistent", TEST_REGISTRY);
EXPECT_EQ(found, nullptr);
}
TEST(AppletTest, EmptyName) {
const auto* found = find_applet("", TEST_REGISTRY);
EXPECT_EQ(found, nullptr);
}