blob: 35a0ed2486118f01cab59e5eb28d4591d2cc0979 [file] [log] [blame]
austinfcuid28d5f82022-04-28 16:20:39 -05001#include <cli.hpp>
2
3#include "gtest/gtest.h"
4
5using namespace attn;
6
7TEST(TestCli, TestCliOptAll)
8{
austinfcuid28d5f82022-04-28 16:20:39 -05009 // Test --all on options
10 Config* config = new Config();
11 char* argv[2];
Patrick Williams27dd6362023-05-10 07:51:20 -050012 int i = 0;
austinfcuid28d5f82022-04-28 16:20:39 -050013 argv[i++] = (char*)"--all";
14 argv[i++] = (char*)"on";
15 parseConfig(argv, argv + i, config);
16 EXPECT_EQ(true, config->getFlag(AttentionFlag::enVital));
17 EXPECT_EQ(true, config->getFlag(AttentionFlag::enCheckstop));
18 EXPECT_EQ(true, config->getFlag(AttentionFlag::enTerminate));
19 EXPECT_EQ(true, config->getFlag(AttentionFlag::enBreakpoints));
20 // The dfltTi flag is cleared by default and is not updated in the function.
21 EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
22 EXPECT_EQ(true, config->getFlag(AttentionFlag::enClrAttnIntr));
23
24 // Test --all off options
25 // Set the dfltTi flag to default value.
26 config->clearFlag(dfltTi);
Patrick Williams27dd6362023-05-10 07:51:20 -050027 i = 0;
austinfcuid28d5f82022-04-28 16:20:39 -050028 argv[i++] = (char*)"--all";
29 argv[i++] = (char*)"off";
30 parseConfig(argv, argv + i, config);
31 EXPECT_EQ(false, config->getFlag(AttentionFlag::enVital));
32 EXPECT_EQ(false, config->getFlag(AttentionFlag::enCheckstop));
33 EXPECT_EQ(false, config->getFlag(AttentionFlag::enTerminate));
34 EXPECT_EQ(false, config->getFlag(AttentionFlag::enBreakpoints));
35 // The same, the dfltTi flag is not updated in the function.
36 EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
37 EXPECT_EQ(false, config->getFlag(AttentionFlag::enClrAttnIntr));
38 delete config;
39}
40
41TEST(TestCli, TestCliNonAll)
42{
43 // Test options with on switch.
44 Config* config = new Config();
45 char* argv[11];
Patrick Williams27dd6362023-05-10 07:51:20 -050046 int i = 0;
austinfcuid28d5f82022-04-28 16:20:39 -050047 argv[i++] = (char*)"--vital";
48 argv[i++] = (char*)"on";
49 argv[i++] = (char*)"--checkstop";
50 argv[i++] = (char*)"on";
51 argv[i++] = (char*)"--terminate";
52 argv[i++] = (char*)"on";
53 argv[i++] = (char*)"--breakpoints";
54 argv[i++] = (char*)"on";
55 argv[i++] = (char*)"--clrattnintr";
56 argv[i++] = (char*)"on";
57 // The --defaultti option does not have on/off switch.
58 // If this option is specified, it is enabled.
59 argv[i++] = (char*)"--defaultti";
60
61 parseConfig(argv, argv + i, config);
62 EXPECT_EQ(true, config->getFlag(AttentionFlag::enVital));
63 EXPECT_EQ(true, config->getFlag(AttentionFlag::enCheckstop));
64 EXPECT_EQ(true, config->getFlag(AttentionFlag::enTerminate));
65 EXPECT_EQ(true, config->getFlag(AttentionFlag::enBreakpoints));
66 EXPECT_EQ(true, config->getFlag(AttentionFlag::enClrAttnIntr));
67 EXPECT_EQ(true, config->getFlag(AttentionFlag::dfltTi));
68
69 // Test options with off switch.
70 // Set the dfltTi flag to default value.
71 config->clearFlag(dfltTi);
Patrick Williams27dd6362023-05-10 07:51:20 -050072 i = 0;
austinfcuid28d5f82022-04-28 16:20:39 -050073 argv[i++] = (char*)"--vital";
74 argv[i++] = (char*)"off";
75 argv[i++] = (char*)"--checkstop";
76 argv[i++] = (char*)"off";
77 argv[i++] = (char*)"--terminate";
78 argv[i++] = (char*)"off";
79 argv[i++] = (char*)"--breakpoints";
80 argv[i++] = (char*)"off";
81 argv[i++] = (char*)"--clrattnintr";
82 argv[i++] = (char*)"off";
83
84 parseConfig(argv, argv + i, config);
85 EXPECT_EQ(false, config->getFlag(AttentionFlag::enVital));
86 EXPECT_EQ(false, config->getFlag(AttentionFlag::enCheckstop));
87 EXPECT_EQ(false, config->getFlag(AttentionFlag::enTerminate));
88 EXPECT_EQ(false, config->getFlag(AttentionFlag::enBreakpoints));
89 EXPECT_EQ(false, config->getFlag(AttentionFlag::enClrAttnIntr));
90 // If the --defaultti option is not specified, it is disabled by default.
91 EXPECT_EQ(false, config->getFlag(AttentionFlag::dfltTi));
92 delete config;
93}