austinfcui | d28d5f8 | 2022-04-28 16:20:39 -0500 | [diff] [blame] | 1 | #include <cli.hpp> |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | using namespace attn; |
| 6 | |
| 7 | TEST(TestCli, TestCliOptAll) |
| 8 | { |
austinfcui | d28d5f8 | 2022-04-28 16:20:39 -0500 | [diff] [blame] | 9 | // Test --all on options |
| 10 | Config* config = new Config(); |
| 11 | char* argv[2]; |
| 12 | int i = 0; |
| 13 | 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); |
| 27 | i = 0; |
| 28 | 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 | |
| 41 | TEST(TestCli, TestCliNonAll) |
| 42 | { |
| 43 | // Test options with on switch. |
| 44 | Config* config = new Config(); |
| 45 | char* argv[11]; |
| 46 | int i = 0; |
| 47 | 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); |
| 72 | i = 0; |
| 73 | 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 | } |