File: command-line-args-test.h

package info (click to toggle)
easyloggingpp 9.97.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,840 kB
  • sloc: cpp: 11,415; python: 2,336; sh: 337; makefile: 29
file content (55 lines) | stat: -rw-r--r-- 2,021 bytes parent folder | download | duplicates (4)
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
#ifndef COMMAND_LINE_ARGS_TEST_H
#define COMMAND_LINE_ARGS_TEST_H

#include "test.h"

TEST(CommandLineArgsTest, SetArgs) {
    const char* c[10];
    c[0] = "myprog";
    c[1] = "-arg1";
    c[2] = "--arg2WithValue=1";
    c[3] = "--arg3WithValue=something=some_other_thing";
    c[4] = "-arg1"; // Shouldn't be added
    c[5] = "--arg3WithValue=this_should_be_ignored_since_key_already_exist";
    c[6] = "--arg4WithValue=this_should_Added";
    c[7] = "\0";
    CommandLineArgs cmd(7, c);
    EXPECT_EQ(4, cmd.size());
    EXPECT_FALSE(cmd.hasParamWithValue("-arg1"));
    EXPECT_FALSE(cmd.hasParam("--arg2WithValue"));
    EXPECT_FALSE(cmd.hasParam("--arg3WithValue"));
    EXPECT_TRUE(cmd.hasParamWithValue("--arg2WithValue"));
    EXPECT_TRUE(cmd.hasParamWithValue("--arg3WithValue"));
    EXPECT_TRUE(cmd.hasParam("-arg1"));
    EXPECT_STRCASEEQ(cmd.getParamValue("--arg2WithValue"), "1");
    EXPECT_STRCASEEQ(cmd.getParamValue("--arg3WithValue"), "something=some_other_thing");
    EXPECT_STRCASEEQ(cmd.getParamValue("--arg4WithValue"), "this_should_Added");
}

TEST(CommandLineArgsTest, DISABLED_LoggingFlagsArg) {
    const char* c[3];
    c[0] = "myprog";
    c[1] = "--logging-flags=5"; // NewLineForContainer & LogDetailedCrashReason (1 & 4)
    c[2] = "\0";

    unsigned short currFlags = ELPP->flags(); // For resetting after test
	
    EXPECT_FALSE(Loggers::hasFlag(LoggingFlag::NewLineForContainer));
    EXPECT_FALSE(Loggers::hasFlag(LoggingFlag::LogDetailedCrashReason));

    Helpers::setArgs(2, c);

    EXPECT_TRUE(Loggers::hasFlag(LoggingFlag::NewLineForContainer));
    EXPECT_TRUE(Loggers::hasFlag(LoggingFlag::LogDetailedCrashReason));

    // Reset to original state
    std::stringstream resetter;
    resetter << "--logging-flags=" << currFlags;
    c[1] = resetter.str().c_str();
    Helpers::setArgs(2, c);
    EXPECT_FALSE(Loggers::hasFlag(LoggingFlag::NewLineForContainer));
    EXPECT_FALSE(Loggers::hasFlag(LoggingFlag::LogDetailedCrashReason));

}

#endif // COMMAND_LINE_ARGS_TEST_H