1. Added test

2. Fixes
This commit is contained in:
gabi
2014-01-25 15:52:10 +02:00
parent 3e88d785c0
commit df56bb775a
13 changed files with 326 additions and 151 deletions

8
test/stdafx.cpp Normal file
View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

16
test/stdafx.h Normal file
View File

@@ -0,0 +1,16 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include <thread>
#include <iostream>
#include <chrono>
#include "utils.h"
#include "../include/c11log/logger.h"
#include "../include/c11log/sinks/async_sink.h"
#include "../include/c11log/sinks/stdout_sinks.h"
#include "../include/c11log/sinks/file_sinks.h"

24
test/test.cpp Normal file
View File

@@ -0,0 +1,24 @@
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void fn();
int main(int argc, char* argv[])
{
c11log::logger logger("test");
auto sink = std::make_shared<c11log::sinks::stdout_sink>();
auto async = std::make_shared<c11log::sinks::async_sink>(100);
async->add_sink(sink);
logger.add_sink(async);
logger.info() << "Hello logger!";
utils::run(std::chrono::seconds(10), fn);
return 0;
}
static void fn()
{}

47
test/utils.h Normal file
View File

@@ -0,0 +1,47 @@
#pragma once
#include <functional>
#include <chrono>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <locale>
namespace utils
{
template<typename T>
std::string format(const T& value)
{
static std::locale loc("");
std::stringstream ss;
ss.imbue(loc);
ss << value;
return ss.str();
}
inline void run(const std::chrono::milliseconds &duration, const std::function<void() >& fn)
{
using namespace std::chrono;
typedef steady_clock the_clock;
size_t counter = 0;
seconds print_interval(1);
auto start_time = the_clock::now();
auto lastPrintTime = start_time;
while (true)
{
fn();
++counter;
auto now = the_clock::now();
if (now - start_time >= duration)
break;
auto p = now - lastPrintTime;
if (now - lastPrintTime >= print_interval)
{
std::cout << format(counter) << " per sec" << std::endl;
counter = 0;
lastPrintTime = the_clock::now();
}
}
}
}