This file is indexed.

/usr/include/wibble/log.test.h is in libwibble-dev 1.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* -*- C++ -*- (c) 2007 Petr Rockai <me@mornfall.net>
               (c) 2007 Enrico Zini <enrico@enricozini.org> */

#include <wibble/test.h>
#include <wibble/log/stream.h>
#include <wibble/log/null.h>
#include <wibble/log/file.h>
#include <wibble/log/ostream.h>
#include <vector>
#include <iostream>
#include <fstream>

/**
 * TODO: find a way to test the syslog sender, if at all possible
 */

namespace {

using namespace std;
using namespace wibble;
using namespace wibble::log;

struct TestLog {

    // Test sender for log::Streambuf
    struct Sender1 : public log::Sender
    {
        // Here go the log messages
        std::vector< std::pair<Level, std::string> > log;
        
        virtual ~Sender1() {}
        
        // Interface for the streambuf to send messages
        virtual void send(Level level, const std::string& msg)
        {
            log.push_back(make_pair(level, msg));
        }
        
        // Dump all the logged messages to cerr
        void dump()
        {
            for (size_t i = 0; i < log.size(); ++i)
                std::cerr << log[i].first << " -> " << log[i].second << " <-" << std::endl;
        }
    };

    Test streambuf() {
        // Instantiate a Streambuf and write something in it

        Sender1 s;
        {
            log::Streambuf ls(&s);
            ostream o(&ls);
            
            // Send a normal log message
            o << "test" << endl;
            assert_eq(s.log.size(), 1u);
            assert_eq(s.log[0].first, log::INFO);
            assert_eq(s.log[0].second, "test");

            // Send a log message with a different priority
            //o << log::lev(log::WARN) << "test" << endl;
            o << log::WARN << "test" << endl;
            assert_eq(s.log.size(), 2u);
            assert_eq(s.log[1].first, log::WARN);
            assert_eq(s.log[1].second, "test");

            // Ensure that log messages are only sent after a newline
            o << "should eventually appear";
            assert_eq(s.log.size(), 2u);
        }
        // Or at streambuf destruction
        assert_eq(s.log.size(), 3u);
        assert_eq(s.log[2].first, log::INFO);
        assert_eq(s.log[2].second, "should eventually appear");

        //s.dump();
    }

    // Test the NullSender
    Test nullSender() {
        // Null does nothing, so we cannot test the results.

        log::NullSender ns;
        ns.send(log::INFO, "test");
        
        log::Streambuf null(&ns);
        ostream o(&null);
        
        // Send a normal log message
        o << "test" << endl;
        
        // Send a log message with a different priority
        //o << log::lev(log::WARN) << "test" << endl;
        o << log::WARN << "test" << endl;
        
        // Ensure that log messages are only sent after a newline
        o << "should eventually appear";
    }

// Test the FileSender
    Test fileSender() {
#ifdef POSIX // there's no /dev/null on win32
        // We send to /dev/null, so we cannot test the results.

        log::FileSender ns("/dev/null");
        ns.send(log::INFO, "test");
        
        log::Streambuf file(&ns);
        ostream o(&file);
        
        // Send a normal log message
        o << "test" << endl;
        
        // Send a log message with a different priority
        //o << log::lev(log::WARN) << "test" << endl;
        o << log::WARN << "test" << endl;
        
        // Ensure that log messages are only sent after a newline
        o << "should eventually appear";
#endif
    }

// Test the OstreamSender
    Test ostreamSender() {
        // We send to /dev/null, so we cannot test the results.

#ifdef POSIX // there's no /dev/null on win32
        std::ofstream null("/dev/null", std::ios::out);
        assert(!null.fail());

        log::OstreamSender sender(null);
        sender.send(log::INFO, "test");
        
        log::Streambuf log(&sender);
        ostream o(&log);
        
        // Send a normal log message
        o << "test" << endl;
        
        // Send a log message with a different priority
        //o << log::lev(log::WARN) << "test" << endl;
        o << log::WARN << "test" << endl;
        
        // Ensure that log messages are only sent after a newline
        o << "should eventually appear";
#endif
    }
    
};

}

// vim:set ts=4 sw=4: