File: testFilter.cpp

package info (click to toggle)
log4shib 1.0.9-3~bpo7%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports-sloppy
  • size: 4,244 kB
  • sloc: cpp: 4,767; sh: 4,210; ansic: 818; makefile: 268
file content (60 lines) | stat: -rw-r--r-- 1,969 bytes parent folder | download | duplicates (7)
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
#include <log4shib/Filter.hh>
#include <iostream>

class TestFilter : public log4shib::Filter {
    public:
    TestFilter() {};
    virtual ~TestFilter() {};

    protected:
    virtual log4shib::Filter::Decision _decide(const log4shib::LoggingEvent& event) {
	log4shib::Filter::Decision decision = log4shib::Filter::NEUTRAL;

	if (event.categoryName == "deny")
	    decision = log4shib::Filter::DENY;
	
	if (event.categoryName == "accept")
	    decision = log4shib::Filter::ACCEPT;

	return decision;
    };
};


class TestFilter2 : public log4shib::Filter {
    public:
    TestFilter2() {};
    virtual ~TestFilter2() {};

    protected:
    virtual log4shib::Filter::Decision _decide(const log4shib::LoggingEvent& event) {
	log4shib::Filter::Decision decision = log4shib::Filter::NEUTRAL;

	if (event.ndc == "test")
	    decision = log4shib::Filter::DENY;
	
	return decision;
    };
};

int main(int argc, char** argv) {
    TestFilter filter;

    bool resultsOK = true;
    
    std::cout << "decision 1 (should be 1): " << filter.decide(log4shib::LoggingEvent("accept", "bla", "ndc", log4shib::Priority::INFO)) << std::endl;

    std::cout << "decision 2 (should be -1): " << filter.decide(log4shib::LoggingEvent("deny", "bla", "ndc", log4shib::Priority::INFO)) << std::endl;

    std::cout << "decision 3 (should be 0): " << filter.decide(log4shib::LoggingEvent("neither", "bla", "ndc", log4shib::Priority::INFO)) << std::endl;

    std::cout << "decision 4 (should be 0): " << filter.decide(log4shib::LoggingEvent("neither", "bla", "test", log4shib::Priority::INFO)) << std::endl;

    filter.setChainedFilter(new TestFilter2());
    
    std::cout << "decision 5 (should be 0): " << filter.decide(log4shib::LoggingEvent("neither", "bla", "ndc", log4shib::Priority::INFO)) << std::endl;

    std::cout << "decision 6 (should be -1): " << filter.decide(log4shib::LoggingEvent("neither", "bla", "test", log4shib::Priority::INFO)) << std::endl;

    return 0;
}